Assalm u alikum, I hope someone can help me. I am trying to setup the automation script so that it mutes my Samsung soundbar before playing the Adhan on the google home mini (for Duhur, Asr, Magrib and Isha).
I am very new to all this.
# Automation for 5 times Azan
# Automation for Zuhur, Asr, Magrib, and Isha
- action:
service: media_player.volume_mute
- data:
entity_id: media_player.home_theater_speaker
is_volume_muted: true
- alias: 'Azan'
data:
entity_id: media_player.living_room_speaker
media_content_id: https://www.islamcan.com/audio/adhan/azan1.mp3
media_content_type: audio/mp3
service: media_extractor.play_media
- data:
entity_id: media_player.living_room_speaker
volume_level: '0.6'
service: media_player.volume_set
#Turning on the input boolean to trigger the Google Homes to start playing the Adhan
- service: input_boolean.turn_on
entity_id: input_boolean.Adhan
#The delay is based on how long the actual Adhan audio is, for this Adhan, it is just around 2 minutes and 14 seconds
- delay: '00:02:14'
alias: Adhan
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")) }}'
- 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")) +2400 }}'
- 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")) }}'
- platform: template
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.isha_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'
- service: media_player.volume_mute
data:
entity_id: media_player.home_theater_speaker
is_volume_muted: false
#Seperate Automation for Fajr
- action:
- alias: 'Azan'
data:
entity_id: media_player.living_room_speaker
media_content_id: https://download.tvquran.com/download/TvQuran.com__Athan/TvQuran.com__01.athan.mp3
media_content_type: audio/mp3
service: media_extractor.play_media
- data:
entity_id: media_player.living_room_speaker
volume_level: '0.4'
service: media_player.volume_set
alias: Fajr_Adhan
trigger:
- platform: template
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.fajr_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'
### Restart HA to force update Islamic Time Sensors at 1AM ###
- alias: Restart HA
trigger:
platform: time
at: "01:00:00"
action:
- service: homeassistant.restart
I am getting the following parse error.
YAMLException: end of the stream or a document separator is expected at line 4, column 1:
service: media_player.volume_mute
^
Automations does not work, as per the states in developer tool, the did not trigger, snip is attached. One Observation is that the name of YAML file for automation in HA is named as automations.yaml
Dashboard widget looks like this, although the timings of Adhan are not as per my timezone. Please advise how can I show the Adhan timings as per my timezone?
Salam @msahar , really appreciate your effort in setting adhan automation. I have been following the thread and found myself bit lost after an integration of Islamic Prayer Time was introduced in Home Assistant.
Is it possible to have specific instructions to configure and automate with Islamic Prayer Time. You probably have already done that but wanted to segregate it from current topic.
One Error I was able to find was the naming of entity (entity_id: media_player.**dining_room_speakerr**) was wrong for Fajr prayers resulting not in playing this. I will wait for Dhuhur prayers to see if it works and update the thread.
Update:
Alhamdulillah, I was able to play Asr Adhan … There was change in sensor naming convention in automation that caused the issue, I have corrected it as it was advised in the comments. Following is the correct automations.yaml file
The information presented in the first post of this thread is almost 3 years old. Some of it is outdated and there are now simpler, easier ways to do the same things.
Could you please help me out configuring the configuration.yaml? I’m using the version you posted above. I now get this error:
2021-12-06 01:05:20 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'unknown' when rendering template '{{ states('sensor.fajr_prayer') | as_timestamp | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2022.1
That means the value of sensor.fajr_prayer is unknown. Did you install the Islamic Prayer Times integration? Do you see five sensors in Configuration > Entities related to the Prayer Times integration?
Guys, the times which is gives to me is not really correct, some of 10 minutes after or before. How can i setup some + or - to let me see the correct times on lovelace?
type: glance
entities:
- entity: sensor.fajr_prayer
format: time
- entity: sensor.dhuhr_prayer
format: time
- entity: sensor.asr_prayer
format: time
- entity: sensor.maghrib_prayer
format: time
- entity: sensor.isha_prayer
format: time
Same problem did you just find the problem? See my question up maybe a workaround if that is possible to let see the lovelace the time with some +10 min -10 min as example.
Can someone post an updated version of this, I cannot get this working correctly. the original post is outdated as of today and does not function correctly.
Currently, I am getting the following error in the logs, It does execute when I run the automation manually but does not execute on its own or on the correct time.
Because you don’t have everything in a single place, plus it’s not user-friendly because you don’t mention what goes in which file. If I had to guess these things from your post, I am sure others who are new would also have to guess the same, therefore I mentioned the complete information in 1 single post instead of going back and forth to different posts.
I’ve managed to make this work using scrape. Go to the diyanet website and change the location based on your current location. My example below is set to Rotterdam, The Netherlands: Diyanet İşleri Başkanlığı | Rotterdam İçin Namaz Vakti
You should change the URL in below and copy paste this in your configuration.yaml