Shows 03:36am which match Fajr prayer time…
That suggests the automation successfully triggered at the correct time. However, if the media_player failed to play anything then either there’s a flaw in the automation’s action
or the media_player was not available at the time it was needed.
We will know more after you make the modification I suggested previously. The automation’s trace will reveal more information.
You can also check Configuration > Logs and see if it contains any error messages posted at 03:36 AM
.
I added in automation in line 2
id: adhan_announcement
Nothing in Logs for 3:36am
I will monitor again today at Dhuhr scheduled for 1:03pm
This is the only warning I am getting in logs each time I do Restart HAAS
Logger: homeassistant.components.islamic_prayer_times
Source: helpers/config_validation.py:739
Integration: Islamic Prayer Times (documentation, issues)
First occurred: 11:45:39 (1 occurrences)
Last logged: 11:45:39
The 'islamic_prayer_times' option near /config/configuration.yaml:1 is deprecated, please remove it from your configuration
You should do what the message recommends and remove that option. However, it is a separate issue and not related to this automation’s behavior.
The trace that the automation will produce at 1:03 PM will hopefully reveal more information about the automation operation.
So 1:03 was the Dhuhr prayer and here is the error I got from logs… still nothing played from speakers
Logger: homeassistant.components.automation.adhan
Source: helpers/script.py:736
Integration: Automation (documentation, issues)
First occurred: 13:04:00 (2 occurrences)
Last logged: 13:04:00
Adhan: Error executing script. Unexpected error for repeat at pos 2: 'repeat'
While executing automation automation.adhan
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 368, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/trace.py", line 256, in async_wrapper
await func(*args)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_repeat_step
del self._variables["repeat"]
KeyError: 'repeat'
I believe I have identified the cause of the error message.
The following version corrects the error. It is not only slightly shorter than the previous version, it also avoids producing an error message if you manually execute it.
If you manually execute this version, it will always default to using the first (fajr) trigger. Anyway, you normally shouldn’t manually trigger the automation but at least it now does allow you to test it by simulating Fajr prayer time.
alias: Adhan
id: adhan_announcement
trigger:
- platform: template
value_template: "{{ now().timestamp()|int == as_timestamp(states('sensor.fajr_prayer')) + 1260 }}"
- platform: template
value_template: "{{ now().timestamp()|int == as_timestamp(states('sensor.dhuhr_prayer')) + 240 }}"
- platform: template
value_template: "{{ now().timestamp()|int == as_timestamp(states('sensor.asr_prayer')) + 180 }}"
- platform: template
value_template: "{{ now().timestamp()|int == as_timestamp(states('sensor.maghrib_prayer')) + 360 }}"
- platform: template
value_template: "{{ now().timestamp()|int == as_timestamp(states('sensor.isha_prayer')) - 1860 }}"
action:
- variables:
players: >
{{[
[ {'player': 'basement_speaker', 'volume': 0.2}, {'player': 'family_room_display', 'volume': 0.3} ],
[ {'player': 'basement_speaker', 'volume': 0.3}, {'player': 'family_room_display', 'volume': 0.4}, {'player': 'alperxiv_shield_tv', 'volume': 0.4} ],
[ {'player': 'alperxiv_shield_tv', 'volume': 0.4} ],
[ {'player': 'alperxiv_shield_tv', 'volume': 0.2}, {'player': 'kitchen_speaker', 'volume': 0.3}, {'player': 'family_room_display', 'volume': 0.2} ],
[ {'player': 'basement_speaker', 'volume': 0.2}, {'player': 'alperxiv_shield_tv', 'volume': 0.2}, {'player': 'kitchen_speaker', 'volume': 0.2}, {'player': 'family_room_display', 'volume': 0.2}, {'player': 'hallway_speaker', 'volume': 0.4} ]
][trigger.id | default(0) | int]}}
- repeat:
count: "{{ players | count }}"
sequence:
- variables:
player: 'media_player.{{ players[repeat.index-1].player }}'
volume: '{{ players[repeat.index-1].volume }}'
- service: media_extractor.play_media
data:
entity_id: "{{ player }}"
media_content_id: https://www.youtube.com/watch?v=4s9Y_BSoIYc
media_content_type: audio/youtube
- service: media_player.volume_set
data:
entity_id: "{{ player }}"
volume_level: "{{ volume }}"
Perfect, like you said manual trigger works now and by default fajr is triggered. I will let you know with Air prayer at 17:12 if automation will work.
On variables section last prayer is ,
missing at the end of line? like the first 4 variables at the end of the line I see ],
Glad to hear manually executing the automation no longer results in an error.
That’s an excellent observation but when defining items in a list, the last item doesn’t need a comma.
Example:
[ 'apples', 'oranges', 'bananas' ]
Here’s more information about python’s lists:
Thank you all for helping out with this automation may you’ll be blessed whenever this automation is used.
It would be highly appreciated if someone could help with creating a scrape or web sensor for local masjids.I am using the following website MasjidBoard Live
Thanks
Hi @123 me again :). I found that with the automation/configuration above there is delay between speakers. Is there anyway to fix that? I see that each speaker is delayed ±1sec. Would be good if all speakers are synchronized
If you are using speakers that support Chromecast, you can use Google Home to combine them into a single grouped speaker. The grouped speaker will be discovered by Home Assistant. Playing to this grouped speaker should eliminate any small delays you are currently hearing between individual speakers.
Sonos speakers also support grouping.
Yes that’s what I did however by grouping speakers I didn’t find a way to set specific volume for each speaker. I think when you group speakers it use same volume level for all. I have 5 google mini speakers…
You will have to decide what’s more important to you, no delays or individual volume control.
The calculation of prayers time is not accurate for my location. I am following Diyanet/Turkey times. Can i just store monthly the 5prayers/day to somewhere and just update every month. Now i have to change the offsets duration daily…
@123 someone helped me toi trigger prayer times from a website which creates times.txt and update every 4hours
/config/times.txt
{“time”:[“05:16”,“06:53”,“11:45”,“14:03”,“16:27”,“17:47”],“date”:“20.11.2021”}
this is my configuration file
default_config:
#start ici
media_extractor:Track the sun
sun:
template:
- sensor:
- name: “today_time_fajr_prayer”
state: ‘{{ (states.sensor.times.state|from_json).time[0] }}’
- name: “today_time_dhuhr_prayer”
state: ‘{{ (states.sensor.times.state|from_json).time[2] }}’
- name: “today_time_asr_prayer”
state: ‘{{ (states.sensor.times.state|from_json).time[3] }}’
- name: “today_time_maghrib_prayer”
state: ‘{{ (states.sensor.times.state|from_json).time[4] }}’
- name: “today_time_isha_prayer”
state: ‘{{ (states.sensor.times.state|from_json).time[5] }}’sensor:
- platform: file
file_path: /config/times.txt
name: Times- platform: time_date
display_options:
- ‘time’
- ‘date’
- ‘date_time’
- ‘date_time_iso’
- ‘time_date’
- ‘time_utc’
- ‘beat’
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
I have problem with my automation. It will not play YouTube link based on prayer hours…
alias: Adhan
id: adhan_announcement
trigger:
- platform: template
value_template: “{{ now().timestamp()|int == as_timestamp(states(‘sensor.today_time_fajr_prayer’)) }}”- platform: template
value_template: “{{ now().timestamp()|int == as_timestamp(states(‘sensor.today_time_dhuhr_prayer’)) }}”- platform: template
value_template: “{{ now().timestamp()|int == as_timestamp(states(‘sensor.today_time_asr_prayer’)) }}”- platform: template
value_template: “{{ now().timestamp()|int == as_timestamp(states(‘sensor.today_time_maghrib_prayer’)) }}”- platform: template
value_template: “{{ now().timestamp()|int == as_timestamp(states(‘sensor.today_time_isha_prayer’)) }}”
action:- variables:
players: >
{{[
[ {‘player’: ‘basement_speaker’, ‘volume’: 0.5} ],
[ {‘player’: ‘all_speakers’, ‘volume’: 0.5} ],
[ {‘player’: ‘all_speakers’, ‘volume’: 0.5} ],
[ {‘player’: ‘all_speakers’, ‘volume’: 0.6} ],
[ {‘player’: ‘all_speakers’, ‘volume’: 0.6} ]
][trigger.id | default(0) | int]}}- repeat:
count: “{{ players | count }}”
sequence:
- variables:
player: ‘media_player.{{ players[repeat.index-1].player }}’
volume: ‘{{ players[repeat.index-1].volume }}’- service: media_extractor.play_media
data:
entity_id: “{{ player }}”
media_content_id: https://www.youtube.com/watch?v=imF7mu1Mdmk
media_content_type: audio/youtube- service: media_player.volume_set
data:
entity_id: “{{ player }}”
volume_level: “{{ volume }}”
can you help me?
Ideally you should be asking whoever helped you because they proposed it. However, I think I know why it fails to trigger.
Each Template Sensor (like sensor.today_time_fajr_prayer
) only contains the time and not time and date. However, the automation’s Template Trigger is comparing today’s timestamp (which represents today’s time and date) with just the sensor’s time. The two timestamps can never match.
Here’s what I suggest you try. Replace all five Template Triggers with this:
- platform: template
value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_fajr_prayer')) }}"
- platform: template
value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_dhuhr_prayer')) }}"
- platform: template
value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_asr_prayer')) }}"
- platform: template
value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_maghrib_prayer')) }}"
- platform: template
value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_isha_prayer')) }}"
Thanks again that fixed the automation.
Hi @123 can you help me improving this automation? I am looking to have separate YouTube link for each prayer time.
alias: Adhan
id: adhan_announcement
trigger:
- platform: template
value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_fajr_prayer')) }}"
- platform: template
value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_dhuhr_prayer')) }}"
- platform: template
value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_asr_prayer')) }}"
- platform: template
value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_maghrib_prayer')) }}"
- platform: template
value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_isha_prayer')) }}"
action:
- variables:
players: >
{{[
[ {'player': 'basement_speaker', 'volume': 0.5} ],
[ {'player': 'all_speakers', 'volume': 0.5} ],
[ {'player': 'all_speakers', 'volume': 0.5} ],
[ {'player': 'all_speakers', 'volume': 0.6} ],
[ {'player': 'all_speakers', 'volume': 0.6} ]
][trigger.id | default(0) | int]}}
- repeat:
count: "{{ players | count }}"
sequence:
- variables:
player: 'media_player.{{ players[repeat.index-1].player }}'
volume: '{{ players[repeat.index-1].volume }}'
- service: media_extractor.play_media
data:
entity_id: "{{ player }}"
media_content_id: https://www.youtube.com/watch?v=imF7mu1Mdmk
media_content_type: audio/youtube
- service: media_player.volume_set
data:
entity_id: "{{ player }}"
volume_level: "{{ volume }}"