Automate Islamic Adhan (also called Azan or Azzan) or other prayer calls - Updated 3_24_2023 for Node-RED

try changing sensor name from sensor.mughrib_prayer_time to sensor.maghrib_prayer_time.

2 Likes

as @chintito4ever suggested, use sensor.magrib_prayer as indicated in the Islamic Prayer Times entities

Salaam Brothers,

I have the automation working perfectly minus one small thing. The Islamic Prayer Time integration doesn’t have a calculation for the UK, the closest is MWL but it isn’t correct. Is there a way I can correct this without having to change anything constantly.

Thanks

Salaam Brother,

I also want to set up azan automation working my amazon echo, I have currently install Islamic prayer times and alexa media.

can you kindly share your config & auto script.

Salam @sshaikh - I’ve just added this integration to my HA and hoping it will resolve all the issues i’ve had with setting offsets on all the prayer times as mentioned in the thread.

If this works - You will be remembered in the coming month of Ramadan I’A

Please add to HACS when you have time and create a blueprint also. This will make life easier for those who are not as tech savy.

Original Detailed Instructions as I ran out of character limit when updating the post for Node-RED.

Detailed Instructions: I am fairly new to Home Assistant and YAML, please excuse my messy code. There is likely easier and more compressed way to write the automation scripts, modified suggestions would be appreciated. I am just happy I got it to work :wink:

You should not add Islamic Prayer Times integration using config file, please use the standard Home Assistant Integration page to do this under “Devices and Services”.

configuration.yaml

homeassistant:
  name: Home
  latitude: !secret lat
  longitude: !secret long
sensor:
     - platform: time_date
        display_options:
        - 'time'
        - 'date'
        - 'date_time'
        - 'time_date'
        - 'time_utc'
        - 'beat'
    - platform: islamic_prayer_times
      calculation_method: makkah
      sensors:
        - fajr
        - sunrise
        - dhuhr
        - asr
        - maghrib
        - isha
        - midnight
#Google Home
cast:
  media_player:
    - host: 10.0.0.36
    - host: 10.0.0.53
    - host: 10.0.0.51
    - host: 10.0.0.50
#Input Boolean - used to synchronize between multiple speakers
input_boolean:  
  adhan:
    name: Adhan
    initial: off 
#Play media from URL - this is another way to play the Adhan from Youtube
media_extractor:

For the below automation, please note that I have a lot of speakers and media devices which are mostly controlled via Harmony Hubs and via Bose SoundTouch component. Please see my comments embedded in the automation script.

automations.yaml

# Automation for Dhuhr, Asr, Maghrib, and Isha Adhan
- id: '1517693010922'
  alias: Adhan
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_dhuhr"), "%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.islamic_prayer_time_asr"), "%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.islamic_prayer_time_maghrib"), "%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.islamic_prayer_time_isha"), "%Y-%m-%dT%H:%M:%S")) }}'
  condition: []
  action:
  #Basement Media Pause/Mute
  - service: remote.send_command
    data:
      entity_id: remote.basement_remote 
      command:
        - Pause
      device: 17712304
  - service: remote.send_command
    data:
      entity_id: remote.basement_remote 
      command:
        - Pause
      device: 52012635
  - service: media_player.volume_mute
    data:
      entity_id: media_player.home_theater_speaker
      is_volume_muted: true
  - service: media_player.volume_set
    data:
      entity_id: media_player.gym_speaker
      volume_level: 0.0
 #Living Room Media Pause/Mute
  - service: remote.send_command
    data:
      entity_id: remote.living_room_remote 
      command:
        - Pause
      device: 47973307
  - service: remote.send_command
    data:
      entity_id: remote.living_room_remote 
      command:
        - Pause
      device: 48904860
  - service: remote.send_command
    data:
      entity_id: remote.living_room_remote 
      command:
        - Mute
      device: 47973310
  - service: media_player.volume_set
    data:
      entity_id: media_player.kitchen_speaker
      volume_level: 0.0
  - service: media_player.volume_set
    data:
      entity_id: media_player.living_room_speaker
      volume_level: 0.0
  #Bedroom Media Pause/Mute
  - service: remote.send_command
    data:
      entity_id: remote.bedroom_remote 
      command:
        - Pause
      device: 49622856
  - service: remote.send_command
    data:
      entity_id: remote.bedroom_remote 
      command:
        - Pause
      device: 52828759
  - service: remote.send_command
    data:
      entity_id: remote.bedroom_remote 
      command:
        - Mute
      device: 49622863
#Set Desired Volume for Google Home
  - service: media_player.volume_set
    data:
      entity_id: media_player.basement_google 
      volume_level: 0.6
  - service: media_player.volume_set
    data:
      entity_id: media_player.living_room_google
      volume_level: 0.7
  - service: media_player.volume_set
    data:
      entity_id: media_player.green_room_google
      volume_level: 0.6
  - service: media_player.volume_set
    data:
      entity_id: media_player.bedroom_google
      volume_level: 0.5
#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 daly 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'
#Basement Media Resume/Un-Mute after Adhan is completed
  - service: remote.send_command
    data:
      entity_id: remote.basement_remote 
      command:
        - Play
      device: 17712304
  - service: remote.send_command
    data:
      entity_id: remote.basement_remote 
      command:
        - Play
      device: 52012635
  - service: media_player.volume_mute
    data:
      entity_id: media_player.home_theater_speaker
      is_volume_muted: false
  - service: media_player.volume_set
    data:
      entity_id: media_player.gym_speaker
      volume_level: 0.55
#Living Room Media Resume/Un-Mute after Adhan is completed
  - service: remote.send_command
    data:
      entity_id: remote.living_room_remote 
      command:
        - Play
      device: 47973307
  - service: remote.send_command
    data:
      entity_id: remote.living_room_remote 
      command:
        - Play
      device: 48904860
  - service: remote.send_command
    data:
      entity_id: remote.living_room_remote 
      command:
        - Mute
      device: 47973310
  - service: media_player.volume_set
    data:
      entity_id: media_player.kitchen_speaker
      volume_level: 0.6
  - service: media_player.volume_set
    data:
      entity_id: media_player.living_room_speaker
      volume_level: 0.7
#Bedroom Media Resume/Un-Mute after Adhan is completed
  - service: remote.send_command
    data:
      entity_id: remote.bedroom_remote 
      command:
        - Play
      device: 49622856
  - service: remote.send_command
    data:
      entity_id: remote.bedroom_remote 
      command:
        - Play
      device: 52828759
  - service: remote.send_command
    data:
      entity_id: remote.bedroom_remote 
      command:
        - VolumeUp
      device: 49622863

#Seperate automation for the Fajr prayer (~5 AM)
- id: '151769301092'
  alias: Adhan Fajr
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_fajr"), "%Y-%m-%dT%H:%M:%S")) }}'
  condition: []
  action:
  #Set the volume of Google Home Speaker to very low, too early for loud audio :)
  - service: media_player.volume_set
    data:
      entity_id: media_player.basement_google 
      volume_level: 0.3
  - service: media_player.volume_set
    data:
      entity_id: media_player.living_room_google
      volume_level: 0.3
  - service: media_player.volume_set
    data:
      entity_id: media_player.green_room_google
      volume_level: 0.3
  - service: media_player.volume_set
    data:
      entity_id: media_player.bedroom_google
      volume_level: 0.1
  #Turn on the input boolean to trigger playing the Adhan on Google Home Speaker
  - service: input_boolean.turn_on
    entity_id: input_boolean.adhan
#The daly 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'
#After the delay, set the volume back to higher level for Google Home devices
  - service: media_player.volume_set
    data:
      entity_id: media_player.basement_google 
      volume_level: 0.6
  - service: media_player.volume_set
    data:
      entity_id: media_player.living_room_google
      volume_level: 0.7
  - service: media_player.volume_set
    data:
      entity_id: media_player.green_room_google
      volume_level: 0.6
  - service: media_player.volume_set
    data:
      entity_id: media_player.bedroom_google
      volume_level: 0.6
  - service: media_extractor.play_media

#Below 4 automation simply plays the Adhan on 4 of my speakers at the same time
- id: '1013100'
  alias: Play Adhan Bedroom
  trigger:
  - entity_id: input_boolean.adhan
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  #Below commented section is an exmaple of how you can use mmedia_extractor component
  # - service: media_extractor.play_media
  #   data:
  #     entity_id: media_player.bedroom_google   # replace with your Google Home's id
  #     media_content_id: https://www.youtube.com/watch?v=ADLO-Hm_nCQ  # replace with your choice of Adhan
  #     media_content_type: audio
  - service: media_player.play_media
    data:
      entity_id: media_player.bedroom_google   # replace with your Google Home's id
      media_content_id: https://kazihome.duckdns.org:8123/local/Adhan1.mp3  # replace with your choice of Adhan
      media_content_type: music
  - delay: '00:00:10'
  - service: input_boolean.turn_off
    entity_id: input_boolean.adhan

- id: '1013101'
  alias: Play Adhan Greeen Room
  trigger:
  - entity_id: input_boolean.adhan
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - service: media_player.play_media
    data:
      entity_id: media_player.green_room_google   # replace with your Google Home's id
      media_content_id: https://kazihome.duckdns.org:8123/local/Adhan1.mp3  # replace with your choice of Adhan
      media_content_type: music
  - delay: '00:00:10'
  - service: input_boolean.turn_off
    entity_id: input_boolean.adhan

- id: '1013101'
  alias: Play Adhan Living Room
  trigger:
  - entity_id: input_boolean.adhan
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - service: media_player.play_media
    data:
      entity_id: media_player.living_room_google   # replace with your Google Home's id
      media_content_id: https://kazihome.duckdns.org:8123/local/Adhan1.mp3  # replace with your choice of Adhan
      media_content_type: music
  - delay: '00:00:10'
  - service: input_boolean.turn_off
    entity_id: input_boolean.adhan

- id: '1013101'
  alias: Play Adhan Basement
  trigger:
  - entity_id: input_boolean.adhan
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - service: media_player.play_media
    data:
      entity_id: media_player.basement_google   # replace with your Google Home's id
      media_content_id: https://kazihome.duckdns.org:8123/local/Adhan1.mp3  # replace with your choice of Adhan
      media_content_type: music
  - delay: '00:00:10'
  - service: input_boolean.turn_off
    entity_id: input_boolean.adhan

Hi after the latest HA update my adhan doesn’t work anymore. I had to write “Country: AU” in the config or else i will get an error in the system saying i they can’t read where is my location. After typing the country code, all the adhan time totally mess up and automation doesn’t even work. Can someone help?

config:

homeassistant:
  name: xxxxxxx
  latitude: xxxxxxx
  longitude: xxxxxxx
  elevation: xx
  unit_system: metric
  time_zone: Australia/Perth
  country: AU
  
default_config:
discovery:
media_extractor:

# Example configuration.yaml using a non-default calculation method
islamic_prayer_times:
    calculation_method: mwl
    
# Sensors
sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'time_date'
  - platform: template
    sensors:
      salah_fajr:
        friendly_name: "Salah 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 }}
      salah_dhuhr:
        friendly_name: "Salah 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 }}
      salah_asr:
        friendly_name: "Salah 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 }}
      salah_maghrib:
        friendly_name: "Salah 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 }}
      salah_isha:
        friendly_name: "Salah 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 }}
           
# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

automation

- action:
  - alias: Azan
    data:
      entity_id: media_player.verydisco
      media_content_id: https://www.islamcan.com/audio/adhan/azan2.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.verydisco
      volume_level: ‘0.9’
    service: media_player.volume_set
  alias: Adhan
  trigger:
  - platform: template
    value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M,
      %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_fajr"),
      "%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.islamic_prayer_time_dhuhr"),
      "%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.islamic_prayer_time_asr"),
      "%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.islamic_prayer_time_maghrib"),
      "%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.islamic_prayer_time_isha"),
      "%Y-%m-%dT%H:%M:%S")) }}'
  id: 8221b242fc0f4934939f66eedbe4c78b
- alias: Restart HA
  trigger:
    platform: time
    at: 01:00:00
  action:
  - service: homeassistant.restart
  id: d28222dc69014127ae1bb91e67353753
- id: '1680081209833'
  alias: Adhan
  description: ''
  trigger:
  - platform: template
    value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M,
      %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_fajr"),
      "%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.islamic_prayer_time_dhuhr"),
      "%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.islamic_prayer_time_asr"),
      "%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.islamic_prayer_time_maghrib"),
      "%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.islamic_prayer_time_isha"),
      "%Y-%m-%dT%H:%M:%S")) }}'
  condition: []
  action:
  - alias: Azan
    data:
      media_content_id: https://www.islamcan.com/audio/adhan/azan2.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
    target:
      entity_id: media_player.verydisco
      device_id:
      - 038e96310faedd96dc4dfdc854289aca
      - 2a99c55c7a524b68954b220e0f236a17
      - f28547ceff3a4eed950561de23cae35a
      - 2fbf7b1857049124ba8ad4c021a01608
      - db2898a1ccd54375aa1bc0825886ce84
      - fbbdc0625444442a840a468b3fef7453
  - data:
      volume_level: 0.47
    service: media_player.volume_set
    target:
      entity_id: media_player.verydisco
  mode: single

Hi, you should not use the config file to add the integration, but rather use the default Home Assistant “Add Integration” option and you can configure the calculation method there.

i did this already. The restarting HA automation is working just fine, just the adhan is the problem

Hi,
This is exactly what im looking for, thanks heaps for all the work youve done so far.

I am really new to all this and am a little bit confused with what you’ve documented on how to setup the automation using node-red. Is this part of that installation/configuration? or is this the “original” way you set it up before moving onto node-red?

I changed the timezone to the country and city im from. pointed the sensor for my google hub. All the other bits you’ve added are not really necessary in my case but also shouldn’t prevent it from continuing as far as i can tell.

I feel like i followed your instructions but I am not sure how to confirm whether this is actually working or not. … well not until the time for a prayer starts. I should probably be a bit more patient - sorry if its been discussed already.

Hi, the original method should still work, but I have moved everything over to Node Red. It’s just much easier to manage. You don’t have to wait until prayer time to test, you can go to the developer tools - - >States to update the prayer times to test the automation. I will plan to make a video recording and share link here of my setup for node red this weekend.

I would recommend watching this video to install Node Red and understand the basics.

Thanks for that. Updating the state for the prayer time helped diagnose a few things but I am still stuck. I have for the most part setup node red (using HA supervisor + node-red). So far I have managed to get the trigger to work on notifying me the Athan has not played on my mobile.
I am not familiar with how you setup the Prayer Call Status “input_boolean.prayer_call” though. That for me is currently showing as “not found”. If i understood right, the input_boolean.whatever can be created in the configuration.yaml. I’ve been reading up on it but im not sure exactly how to add it.

You can create input boolean under devices - - >helpers in settings. Or the existing configuration yaml option works too. Restart home assistant or reload the input boolean and ensure it shows up under developer tools states. If it does, make sure to turn it on.

So i have that, and the state shows as Prayer call status “off” but I am not sure exactly how to get it to identify the prayer time so it can be “on”. I set the time for the prayer and it continues to pass the message to my mobile HA app saying it didn’t play the adhan. I feel like there is a part missing or incomplete.
In my configurations.yaml:

input_boolean:
  prayer_call:
    name: Prayer Call
    initial: off

I did read about how you said you can add it in the helpers but that was not clear which option to chose e.g. Button or Group. there were a lot of options to chose from and it just wasn’t clear which one to use. Putting into the confiugrations.yaml seemed the easier choice for now.

omg… ok. Fasting brain here. It all clicked once I checked the helpers and seen it there. I have it in my dashboard now (for some reason it took me a while to get what that part was actually doing). Brilliant work. Thank you again. I think i might actually have this setup right now.

You’re welcome and glad it worked out.

1 Like

Hi again - not sure if i got this right but the volume doesn’t seem to have a set point for Fajr in your node red config. The “turn on Fajr Volume” turns on the speaker but doesnt set a value for the speaker which I assume would be another call service node? or am i looking at this wrong.
basically i just want to know where the volume is being set, and from what i have been reading from other forums, I can’t seem to make out where its being done in node-red.

is there meant to be another call service after the delay 2s? e.g. "Turn on Fajr Volume > delay 2s > Set Volume > Play athan?

Testing this out and adding the call service node data: { "volume_level": 0.5} seems to have done the trick but I am not sure If I added this when it was already there? Just wanted to make sure.

Thanks

I feel that Mawait is doing better than what you’re trying to do. Also, Mawaqit offers integration with HA

Hope this helps :slight_smile:

i have installed the latest Prayer time official integration. It works fine but i want to add lovelace card to see the next prayer time like this. How can i do that?

rpyaer

Do you mean how to create a card like in the picture you posted?