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

You need to use media extractor to play the youtube version of the Athan.
first add media extractor anywhere in your configuration.yaml file like this:
media_extractor:

Next use media extractor to play the audio of that youtube video, here’s my automation.

- id: '1554439831482'
  alias: Athan_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:
  - data:
      message: Allah Yet2abal <3
      title: Time To Pray Fajr
    service: notify.tg
  - data:
      entity_id: ' media_player.living_room_speaker'
      volume_level: '0.90'
    service: media_player.volume_set
  - data:
      entity_id: media_player.living_room_speaker
      media_content_id: https://www.youtube.com/watch?v=ADLO-Hm_nCQ
      media_content_type: audio/youtube
    service: media_extractor.play_media

you can ignore the first action which is just a notification i send to our phones using telegram.

I hope this hleps.

Just for any passers by. Make sure you have the right timezone in your configuration file. I’m in London and i had utc set as my time zone so this wasnt working as expected.

1 Like

Hello Aadighal, I’ve been struggling since few days to get the automation , I can manually trigger it and the Adhan plays. Possible to share your config and automation files? any help would be appreciated.

S.A Bilal, sure thing, here’s what I currently have.

Config:

sensor:
  - platform: time_date
    display_options:      
      - 'time'
      - 'date'
      - 'date_time'
      - 'time_date'
      - 'time_utc'
      - 'beat'
- platform: islamic_prayer_times
    calculation_method: isna
    sensors:
      - fajr
      - sunrise
      - dhuhr
      - asr
      - maghrib
      - isha
      - midnight

Automation:
Fajr Prayer

- id: '1554439831482'
  alias: Athan_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:
  - data:
      entity_id: ' media_player.living_room_speaker'
      volume_level: '0.90'
    service: media_player.volume_set
  - data:
      entity_id: media_player.living_room_speaker
      media_content_id: https://www.youtube.com/watch?v=ADLO-Hm_nCQ
      media_content_type: audio/youtube
    service: media_extractor.play_media

Athan for the rest of prayers:

- id: '1554438581518'
  alias: Athan_4
  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_isha"),
      "%Y-%m-%dT%H:%M:%S")) }}'
  condition: []
  action:
  - data:
      message: Allah Yet2abal <3
      title: Time for Prayer
    service: notify.tg
  - data:
      entity_id: ' media_player.living_room_speaker'
      volume_level: '0.50'
    service: media_player.volume_set
  - data:
      entity_id: media_player.living_room_speaker
      media_content_id: https://www.youtube.com/watch?v=ADLO-Hm_nCQ
      media_content_type: audio/youtube
    service: media_extractor.play_media

Unfortunately you can’t enter a value template in the Automation editor GUI, to go around that you could create an automation and use a template trigger but leave the value template empty and fill out the rest. Then go to your automation.yaml file and add the value template there. Here’s a picture of the my automation in the Automation editor.

Thank you. I appreciate your offer. Please give us a detailed tutorial. May Allah reward all of you for making our homes filled with the voice of Azaan.

1 Like

I have written a detailed guide. Check it out. GUIDE. The video link is also available in this guide too.

Salam,

I am not able to workout this automation on the bose hs 500.
Can you please help?

Hi, Salam, where do I place this?

Salams, how do I get 12hr format instead of 24?

Al salam Alikum
this will make it Hr 12 am/pm

- platform: template
    sensors:
      salah_fajir:
        friendly_name: pray_fajir:
        value_template: "{{ as_timestamp(states('sensor.islamic_prayer_time_fajr')) | timestamp_custom('%-I:%M %P') }}"

you can create it as sensor for each Salah to display, try it in you template editor and it will display the time to pray,

1 Like

I have a question not exactly related to adhan automation but has a similar automation

Does any one know if its possible to use the media player component to play Quran for the kids at a set time and repeat for 2 hours.

As my daughter is learning a new surah, I want to be able to play surah on repeat for 2 hours then stop

I have followed the similar automation as adhan but I only know how to assign 1 mp3 file (like the adhan). I want it to repeat playing for a set time

1 Like

How can i play multiple files:
so basically after adhan i would like to play couple du’ah

Hi, you can add them to folder and then play all the mp3 files either *.mp3 or you can use Delay: (time for file to end playing) then play the next file and so on, this way you will have a playing order.
This is an example to play random files

    - service: shell_command.bienvenida
      data_template:
        tocar: "/zara/music/saludos/saludos{{ '{0:d}'.format(range(1, 15)|random) }}.mp3"

or you can do it this way:

    - service: shell_command.bienvenida
      data_template:
        tocar: "/zara/music/saludos/saludos1.mp3"
    - delay: '00:01:55' # this is the time it takes to finish playing the saludos1.mp3 file.
    - service: shell_command.bienvenida
      data_template:
        tocar: "/zara/music/saludos/saludos2.mp3"

Shell command:

bienvenida: /usr/bin/mpg123 -a hw:0,0 -q "{{tocar}}"

The “hw:0,0” is the audio hardware if you are using the raspberry and have speakers attached to the raspberry.

# Seperate Automation for Fajr Adhan
- action:
  - alias: ''
    data:
      entity_id: media_player.hall_speaker
      media_content_id: http://hassio.local:8123/local/adhan_fajr_makkah.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.hall_speaker
      volume_level: '0.7'
    service: media_player.volume_set
  alias: Fajr Adhan
  condition: []
  id: '1517693010922'
  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")) +960 }}'

where would I put the delay and run the other file in this?

# Seperate Automation for Fajr Adhan
- alias: Fajr Adhan
  id: '1517693010922'
  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")) +960 }}'
  action:
    - service: media_player.volume_set
      data:
        entity_id: media_player.hall_speaker
        volume_level: '0.7'
    - service: media_extractor.play_media
      data:
        entity_id: media_player.hall_speaker
        media_content_id: http://hassio.local:8123/local/adhan_fajr_makkah.mp3
        media_content_type: audio/mp3
    - delay: '00:02:05' # time it takes to finish playing your adhan_fajr_makkah.mp3
    - service: media_extractor.play_media
      data:
        entity_id: media_player.hall_speaker
        media_content_id: http://hassio.local:8123/local/adhan_duaa.mp3
        media_content_type: audio/mp3        

i have just rearrange your automation and added delay and “another adhan_duaa.mp3” file as another mp3 file to play.
hope it works.
mjust make sure that the time on the delay its grater than the time your adhan fajir takes by lets say 3 seconds.

Im going to create a test block : is there a way to get time like it does already and then to trigger a specific time to run that test block?

currently:
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")) +960 }}'

what im thinking, not sure if this is correct:
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == 18:30:00, "%H:%M:%S"))}}'

So i created a test block: which doesn’t give me error but doesn’t do much: im assuming the issue is the way i have entered a specific time under value_template…

- alias: TEST BLOCK
  id: '1517693010922'
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp("18:15:00", "%H:%M:%S") }}' #so the current time from time_date is 18:10
  action:
    - service: media_player.volume_set
      data:
        entity_id: media_player.office_speaker
        volume_level: '0.7'
    - service: media_extractor.play_media
      data:
        entity_id: media_player.office_speaker
        media_content_id: http://hassio.local:8123/local/adhan_fajr_makkah.mp3
        media_content_type: audio/mp3
    - delay: '00:03:50' # time it takes to finish playing your adhan_fajr_makkah.mp3
    - service: media_extractor.play_media
      data:
        entity_id: media_player.office_speaker
        media_content_id: http://hassio.local:8123/local/dua-e-adhan.mp3
        media_content_type: audio/mp3

Try to trigger the automation from the service panel

Ok, so I used the trigger. It ran, but there’s no sound. I can play the file directly on the web…

# TEST BLOCK for Fajr Adhan
- alias: TEST BLOCK Fujr Adhan
  id: '1517693010922'
  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")) +1140 }}'
  action:
    - service: media_player.volume_set
      data:
        entity_id: media_player.office_speaker
        volume_level: '0.7'
    - service: media_extractor.play_media
      data:
        entity_id: media_player.office_speaker
        media_content_id: http://hassio.local:8123/local/adhan_fajr_makkah.mp3
        media_content_type: audio/mp3
    - delay: '00:03:50' # time it takes to finish playing your adhan_fajr_makkah.mp3
    - service: media_extractor.play_media
      data:
        entity_id: media_player.office_speaker
        media_content_id: http://hassio.local:8123/local/dua-e-adhan.mp3
        media_content_type: audio/mp3

audio files:

  1. http://khurram.org/aud/adhan_fajr_makkah.mp3
  2. http://khurram.org/aud/dua-e-adhan.mp3

Asalam u Alaikum All,

is anyone here from Toronto area, I am not very technical and i am looking for some in-person help to set this automatic azaan for my home

Thanks & Regards