Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use time display option instead of date_time #28

Merged
merged 5 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sensor:
- platform: template
value_template: >
{% set before = (as_timestamp(states("sensor.fajr_mawaqit")) - 20 * 60) | timestamp_custom("%H:%M", True) %}
{% set time = states("sensor.date_time").split(" ")[1] %}
{% set time = states("sensor.time") %}
{{ time == before }}
action:
# turn on the light of the bedroom
Expand All @@ -62,7 +62,7 @@ sensor:
platform: template
value_template: >
{% set isha_time = as_timestamp(states("sensor.isha_mawaqit")) | timestamp_custom("%H:%M", True) %}
{% set time = states("sensor.date_time").split(" ")[1] %}
{% set time = states("sensor.time") %}
{{ time == isha_time }}
action:
- service: mqtt.publish
Expand Down
25 changes: 12 additions & 13 deletions configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ sensor:
- platform: time_date
display_options:
- 'time'
- 'date_time'

template:
- sensor:
Expand All @@ -30,8 +29,8 @@ automation:
trigger:
platform: template
value_template: >
{% set a1 = states("sensor.date_time").split(" ")[1].split(":")[0] %}
{% set b1 = states("sensor.date_time").split(":")[1] %}
{% set a1 = states("sensor.time").split(":")[0] %}
{% set b1 = states("sensor.time").split(":")[1] %}
{% set a = states("sensor.maghrib_adhan").split(" ")[1].split(":")[0] %}
{% set b = states("sensor.maghrib_adhan").split(":")[1] %}
{{ b | int == b1 | int and a | int == a1 | int }}
Expand All @@ -48,8 +47,8 @@ automation:
trigger:
platform: template
value_template: >
{% set a1 = states("sensor.date_time").split(" ")[1].split(":")[0] %}
{% set b1 = states("sensor.date_time").split(":")[1] %}
{% set a1 = states("sensor.time").split(":")[0] %}
{% set b1 = states("sensor.time").split(":")[1] %}
{% set a = states("sensor.asr_adhan").split(" ")[1].split(":")[0] %}
{% set b = states("sensor.asr_adhan").split(":")[1] %}
{{ b | int == b1 | int and a | int == a1 | int }}
Expand All @@ -66,8 +65,8 @@ automation:
trigger:
platform: template
value_template: >
{% set a1 = states("sensor.date_time").split(" ")[1].split(":")[0] %}
{% set b1 = states("sensor.date_time").split(":")[1] %}
{% set a1 = states("sensor.time").split(":")[0] %}
{% set b1 = states("sensor.time").split(":")[1] %}
{% set a = states("sensor.dhuhr_adhan").split(" ")[1].split(":")[0] %}
{% set b = states("sensor.dhuhr_adhan").split(":")[1] %}
{{ b | int == b1 | int and a | int == a1 | int }}
Expand All @@ -84,8 +83,8 @@ automation:
trigger:
platform: template
value_template: >
{% set a1 = states("sensor.date_time").split(" ")[1].split(":")[0] %}
{% set b1 = states("sensor.date_time").split(":")[1] %}
{% set a1 = states("sensor.time").split(":")[0] %}
{% set b1 = states("sensor.time").split(":")[1] %}
{% set a = states("sensor.isha_adhan").split(" ")[1].split(":")[0] %}
{% set b = states("sensor.isha_adhan").split(":")[1] %}
{{ b | int == b1 | int and a | int == a1 | int }}
Expand All @@ -102,8 +101,8 @@ automation:
trigger:
platform: template
value_template: >
{% set a1 = states("sensor.date_time").split(" ")[1].split(":")[0] %}
{% set b1 = states("sensor.date_time").split(":")[1] %}
{% set a1 = states("sensor.time").split(":")[0] %}
{% set b1 = states("sensor.time").split(":")[1] %}
{% set a = states("sensor.fajr_adhan").split(" ")[1].split(":")[0] %}
{% set b = states("sensor.fajr_adhan").split(":")[1] %}
{{ b | int == b1 | int and a | int == a1 | int }}
Expand All @@ -126,7 +125,7 @@ automation:
{% set before3 = (as_timestamp(states('sensor.dhuhr_adhan')) - 10 * 60) | timestamp_custom("%H:%M") %}
{% set before4 = (as_timestamp(states('sensor.fajr_adhan')) - 60 * 60) | timestamp_custom("%H:%M") %}
{% set before5 = (as_timestamp(states('sensor.fajr_adhan')) - 10 * 60) | timestamp_custom("%H:%M") %}
{% set b1 = states("sensor.date_time").split(" ")[1] | timestamp_custom("%H:%M") %}
{% set b1 = states("sensor.time") | timestamp_custom("%H:%M") %}
{{ b1 == before1 or b1 == before2 or b1 == before3 or b1 == before4 or b1 == before5 }}
action: # the action below is given as an example and is to adapt based on on your homeassistant installation
- service: mqtt.publish
Expand All @@ -147,7 +146,7 @@ automation:
{% set before3 = (as_timestamp(states('sensor.dhuhr_adhan')) - 1 * 60) | timestamp_custom("%H:%M") %}
{% set before4 = (as_timestamp(states('sensor.fajr_adhan')) - 1 * 60) | timestamp_custom("%H:%M") %}
{% set before5 = (as_timestamp(states('sensor.fajr_adhan')) - 1 * 60) | timestamp_custom("%H:%M") %}
{% set b1 = states("sensor.date_time").split(" ")[1] | timestamp_custom("%H:%M") %}
{% set b1 = states("sensor.time") | timestamp_custom("%H:%M") %}
{{ b1 == before1 or b1 == before2 or b1 == before3 or b1 == before4 or b1 == before5 }}
action: # the action below is given as an example and is to adapt based on on your homeassistant installation
service: mqtt.publish
Expand Down