I have other method, however it is depending on an android app and mqtt, if this is interesting to you let me know I will share it.
Salaam, can someone send me their automation in a single file, instead of separated by adhan?
Thanks
Salam, i got it works thanks.
I have question, how to set alarm ringing about 30 minutes before adzan please
# Automation for remaining four Azaan to pause all media_player 5 min before
- alias: Azaan pause all media_player
trigger:
- platform: template
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.dhuhr_prayer"), "%Y-%m-%dT%H:%M:%S"))
- 300 }}'
- platform: template
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.asr_prayer"), "%Y-%m-%dT%H:%M:%S")) -
300 }}'
- platform: template
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.maghrib_prayer"), "%Y-%m-%dT%H:%M:%S")
) - 300 }}'
action:
- service: notify.fire_speak_notify
data_template:
message: 'Active media players paused'
data:
title: Alarm
- service: script.pause_roku_media_device_for_namaaz
- service: script.pause_echo_dot_media_device_for_namaaz
- service: script.pause_chromecast_media_device_for_namaaz
- service: script.pause_nest_mini_media_device_for_namaaz
- service: script.pause_samsung_bluray_media_device_for_namaaz
- service: script.pause_firetv4k_media_device_for_namaaz
you could change the 5 min - 300 sec to 30 min (1800 sec) and call appropriate alarm serviceā¦ i use it to pause any media players if playingā¦
thank you JZKā¦
let say i want to switch on my sonoff ( water machine ) 30 minutes before adzan
how to configure it please
QQ: Does the prayer time auto fix with DST?
Salam Khorem. apparently it does not. I am looking to solve this issue.
mine did correctly after a day. First day of the change it was messed up but then next day it syncād up fine with the updated time. Not sure but you can try restarting HASS
AsalamAlakum,
i am very new to home assistant and yaml files. what i am trying to do is play the last 3 Surahs of the Quran before Fajr. i am getting this error when it tries to run.
2020-11-07 03:59:34 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{{ as_timestamp(states("sensor.ptf_fajr")) == as_timestamp(states("sensor.time")) -300 }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 421, in async_render
render_result = compiled.render(kwargs)
File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 518, in async_render_to_info
render_info._result = self.async_render(variables, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 423, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
2020-11-07 03:59:35 ERROR (Recorder) [homeassistant] Error doing job: Unclosed connection
any help would be greatly appreciated.
(also if there is a better way to post my config and other files please let me know)
Dan
this is my configuration.yaml
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Text to speech
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
media_extractor:
sensor:
- platform: time_date
display_options:
- "time"
- "date"
- "date_time"
- "date_time_utc"
- "date_time_iso"
- "time_date"
- "time_utc"
- "beat"
- platform: template
sensors:
salah_fajr:
friendly_name: "Fajr"
value_template: >
{%- set a = states("sensor.fajr_prayer").split("T")[1].split(":")[0] -%}
{%- set b = states("sensor.fajr_prayer").split("T")[1].split(":")[1] -%}
{{ a + ":" + b }}
ptf_fajr:
friendly_name: "Fajr Prayer"
value_template: >
{{ as_timestamp(states('sensor.fajr_prayer')) | timestamp_custom('%H:%M') }}
icon_template: mdi:calendar-clock
salah_dhuhr:
friendly_name: "Dhuhr"
value_template: >
{%- set a = states("sensor.dhuhr_prayer").split("T")[1].split(":")[0] -%}
{%- set b = states("sensor.dhuhr_prayer").split("T")[1].split(":")[1] -%}
{{ a + ":" + b }}
ptf_dhuhr:
friendly_name: "Dhuhr Prayer"
value_template: >
{{ as_timestamp(states('sensor.dhuhr_prayer')) | timestamp_custom('%H:%M') }}
icon_template: mdi:calendar-clock
salah_asr:
friendly_name: "Asr"
value_template: >
{%- set a = states("sensor.asr_prayer").split("T")[1].split(":")[0] -%}
{%- set b = states("sensor.asr_prayer").split("T")[1].split(":")[1] -%}
{{ a + ":" + b }}
ptf_asr:
friendly_name: "Asr Prayer"
value_template: >
{{ as_timestamp(states('sensor.asr_prayer')) | timestamp_custom('%H:%M') }}
icon_template: mdi:calendar-clock
salah_maghrib:
friendly_name: "Maghrib"
value_template: >
{%- set a = states("sensor.maghrib_prayer").split("T")[1].split(":")[0] -%}
{%- set b = states("sensor.maghrib_prayer").split("T")[1].split(":")[1] -%}
{{ a + ":" + b }}
ptf_maghrib:
friendly_name: "maghrib Prayer"
value_template: >
{{ as_timestamp(states('sensor.maghrib_prayer')) | timestamp_custom('%H:%M') }}
icon_template: mdi:calendar-clock
salah_isha:
friendly_name: "Isha"
value_template: >
{%- set a = states("sensor.isha_prayer").split("T")[1].split(":")[0] -%}
{%- set b = states("sensor.isha_prayer").split("T")[1].split(":")[1] -%}
{{ a + ":" + b }}
ptf_isha:
friendly_name: "Isha Prayer"
value_template: >
{{ as_timestamp(states('sensor.isha_prayer')) | timestamp_custom('%H:%M') }}
icon_template: mdi:calendar-clock
#Input Boolean - used to synchronize between multiple speakers
input_boolean:
adhan:
name: Adhan
initial: off
influxdb:
host: a0d7b954-influxdb
port: 8086
database: !secret influxdb_db
username: !secret influxdb_un
password: !secret influxdb_pw
max_retries: 3
default_measurement: state
and this is my automations.yaml file
- id: "1602013093065"
alias: Play Adhan
description: ""
trigger:
- platform: state
entity_id: input_boolean.adhan
from: "off"
to: "on"
condition: []
action:
- service: media_player.media_pause
data: {}
entity_id: media_player.home_group
- service: media_player.media_pause
data: {}
entity_id: media_player.masterbd
- service: media_player.volume_set
data:
volume_level: 0.55
entity_id: media_player.living_room_speaker
- service: media_player.volume_set
data:
volume_level: 0.55
entity_id: media_player.master_bedroom_speaker
- service: media_player.volume_set
data:
volume_level: 0.55
entity_id: media_player.office_speaker
- service: media_player.play_media
data:
media_content_id: http://10.0.0.4:8123/local/mba.mp3
media_content_type: music
entity_id: media_player.home_group
mode: single
- id: "1602895411112"
alias: Quran
description: ""
trigger:
- platform: state
entity_id: input_boolean.quarn
from: "off"
to: "on"
condition: []
action:
- service: media_player.volume_set
data:
volume_level: 0.75
entity_id: media_player.living_room_speaker
- service: media_player.play_media
data:
media_content_type: music
media_content_id: http://10.0.0.4:8123/local/quarn/{{range(1, 114)|random}}.mp3
entity_id: media_player.living_room_speaker
- delay: "5"
- service: input_boolean.turn_off
data: {}
entity_id: input_boolean.quarn
mode: single
- id: "1603220813524"
alias: Auto For Fajr
description: ""
trigger:
- platform: template
value_template: '{{ states("sensor.time_utc") == states("sensor.salah_fajr") }}'
condition: []
action:
- service: input_boolean.turn_on
data: {}
entity_id: input_boolean.adhan
- delay: "30"
- service: input_boolean.turn_off
data: {}
entity_id: input_boolean.adhan
- delay: "1140"
- service: input_boolean.turn_on
data: {}
entity_id: input_boolean.fajr_quran
mode: single
- id: "1603220882286"
alias: Auto Dhuhr Prayer
description: ""
trigger:
- platform: template
value_template:
'{{ states("sensor.time_utc") == states("sensor.salah_dhuhr")
}}'
condition: []
action:
- service: input_boolean.turn_on
data: {}
entity_id: input_boolean.adhan
- delay: "30"
- service: input_boolean.turn_off
data: {}
entity_id: input_boolean.adhan
- delay: "1140"
- service: input_boolean.turn_on
data: {}
entity_id: input_boolean.fajr_quran
mode: single
- id: "1603220941015"
alias: Auto Asr Prayer
description: ""
trigger:
- platform: template
value_template: '{{ states("sensor.time_utc") == states("sensor.salah_asr") }}'
condition: []
action:
- service: input_boolean.turn_on
data: {}
entity_id: input_boolean.adhan
- delay: "30"
- service: input_boolean.turn_off
data: {}
entity_id: input_boolean.adhan
- delay: "1140"
- service: input_boolean.turn_on
data: {}
entity_id: input_boolean.fajr_quran
mode: single
- id: "1603221001240"
alias: Auto Maghrib Prayer
description: ""
trigger:
- platform: template
value_template:
'{{ states("sensor.time_utc") == states("sensor.salah_maghrib")
}}'
condition: []
action:
- service: input_boolean.turn_on
data: {}
entity_id: input_boolean.adhan
- delay: "30"
- service: input_boolean.turn_off
data: {}
entity_id: input_boolean.adhan
- delay: "1140"
- service: input_boolean.turn_on
data: {}
entity_id: input_boolean.fajr_quran
mode: single
- id: "1603221063694"
alias: Auto Isha Prayer
description: ""
trigger:
- platform: template
value_template: '{{ states("sensor.time_utc") == states("sensor.salah_isha") }}'
condition: []
action:
- service: input_boolean.turn_on
data: {}
entity_id: input_boolean.adhan
- delay: "30"
- service: input_boolean.turn_off
data: {}
entity_id: input_boolean.adhan
- delay: "1140"
- service: input_boolean.turn_on
data: {}
entity_id: input_boolean.fajr_quran
mode: single
- id: "1603221439747"
alias: Play Sura 67 & 36
description: ""
trigger:
- platform: state
entity_id: input_boolean.play_yaseen_and_mulk
from: "off"
to: "on"
condition: []
action:
- service: media_player.play_media
data:
media_content_type: music
media_content_id: http://10.0.0.4:8123/local/quarn/67.mp3
entity_id: media_player.living_room_speaker
- delay: "381"
- service: media_player.play_media
data:
media_content_type: music
media_content_id: http://10.0.0.4:8123/local/quarn/36.mp3
entity_id: media_player.living_room_speaker
- service: input_boolean.turn_off
data: {}
entity_id: input_boolean.play_yaseen_and_mulk
mode: single
- id: "1603223315797"
alias: Fajr Quran
description: ""
trigger:
- platform: state
entity_id: input_boolean.fajr_quran
from: "off"
to: "on"
condition: []
action:
- service: media_player.play_media
data:
media_content_type: music
media_content_id: http://10.0.0.4:8123/local/quarn/112.mp3
entity_id: media_player.living_room_speaker
- delay: "23"
- service: media_player.play_media
data:
media_content_type: music
media_content_id: http://10.0.0.4:8123/local/quarn/113.mp3
entity_id: media_player.living_room_speaker
- delay: "33"
- service: media_player.play_media
data:
media_content_type: music
media_content_id: http://10.0.0.4:8123/local/quarn/114.mp3
entity_id: media_player.living_room_speaker
- service: input_boolean.turn_off
data: {}
entity_id: input_boolean.fajr_quran
mode: single
- id: "1604738624931"
alias: Quran Before Fajr
description: ""
trigger:
- platform: template
value_template: '{{ as_timestamp(states("sensor.ptf_fajr")) == as_timestamp(states("sensor.time")) -300 }}'
condition: []
action:
- service: input_boolean.turn_on
data:
entity_id: input_boolean.fajr_quran
mode: single
try to convert to integer before doing the subtraction in your template :
"{{ as_timestamp(states("sensor.ptf_fajr"))|int == as_timestamp(states("sensor.time"))| int -300 }}"`
ok i will try that thank you so much
Anyone else adhan automation break with 0.118?
So sorry this has taken so long to get back to this.
it did not work and there were no errors in the log about it.
To do 5min before :
{{ as_timestamp(now() - timedelta( hours = 0, minutes = 5 ))| float | timestamp_custom('%H:%M', true) }}
true at the end for local time.
So :
trigger:
- platform: template
value_template: '{{ states("sensor.ptf_fajr") == as_timestamp(now() - timedelta( hours = 0, minutes = 5 ))| float | timestamp_custom('%H:%M', true) }}'
as @123paultje said, float filter is not needed, here just to introduce
I will try this and let you know. IA it will work. May Allah(saw) Bless you for your help, may Allah(saw) give you deeds every time this goes off.
If it interests you, the template can be reduced to:
trigger:
- platform: template
value_template: >
{{ states('sensor.ptf_fajr') == (now().timestamp() - 300) | timestamp_custom('%H:%M') }}
Yes, I had read it, but I prefer a more human writingā¦
I didnāt realize the goal was to write a novel.
FWIW, why was hours=0
included in the timedelta()
function when all thatās needed is minutes=5
?
timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
Because we do not all have the same skill levels
I could indeed have put all the keys for the example.
It is a support. I take the part (even if it displeases) to put more keys than necessary to show others that it is not limited.
Thank you for the example with all
Moreover, if I want to write now, 2 hours and 27 minutes, I can do it quickly without any miscalculation
I see.
That probably also explains why the int
filter was included even though it isnāt needed.