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

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

What media player speaker you use?? Sonos or what?

what is it you need help with?

google home mini; but its not the speakers, i’ve tested it with the tutorial that msahar posted and it works fine.The issue is only when i add the delay and the local files you told me to… it doesn’t work.

Jazakallah Brother, i just found the guide from msahar
I will try to follow that guide and if needed i will get back to you.
btw can you suggest the best place to buy PI board or starter kit ?? Thanks

https://secure.sayal.com/STORE2/locations.php
or amazon.ca
I personally prefer amazon

What you can do is to call a script that call the mp3 files or try to make 2 automatines, one that trigger the other, or you can combine 2 mp3 file in 1 files and this way play only the combined mp3 file, I didn’t try they, but I could test later with my Google home.

im 100% convinced that its not the speaker issue. Its either the code or the audio file, im starting to doubt that the mp3 file is not readible by the app (media_player) which is called by hass.io

Try convert to .wav

ok so its not the audio file as well, I’m stumped now.

# 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.wav
        #media_content_id: https://www.islamcan.com/audio/adhan/azan2.mp3
        media_content_type: 'music'
    - delay: '00:03:06' # 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.wav
        #media_content_id: https://www.islamcan.com/audio/adhan/azan2.mp3
        media_content_type: 'music'

Try 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_player.play_media 
      data_template:                 
        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'
    - service: media_player.play_media 
      data_template:                 
        entity_id: media_player.hall_speaker           
        media_content_id: http://hassio.local:8123/local/adhan_duaa.mp3
        media_content_type: 'audio/mp3' 

just make sure you have access to your mp3 files through the URL.

so it triggers the speaker but nothing plays; i feel that the way this is coded is a problem?

I’ve updated it so that it reaches those files, triggers the speaker (i hear bleep) but that’s it.

# TEST BLOCK
- alias: TEST BLOCK 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_player.play_media 
      data_template:                 
        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:03:50'
    - service: media_player.play_media 
      data_template:                 
        entity_id: media_player.hall_speaker           
        media_content_id: http://khurram.org/aud/dua-e-adhan.mp3
        media_content_type: 'audio/mp3'

UPDATE:

I think i have found the culprit but not sure what the solution is:
this address when played on on the browser, works: http://hassio.local:8123/local/adhan_fajr_makkah.mp3

but when i put that address in the code it doesn’t:
http://hassio.local:8123/local/adhan_fajr_makkah.mp3
or
http://localhost:8123/local/adhan_fajr_makkah.mp3

I’ve put the audio on the internal server on a local ip address and it works fine
weird! but i guess we can let this one go cause it could just be my internal network playing games.

    - service: media_player.play_media 
      data_template:                 
        entity_id: media_player.hall_speaker           
        media_content_id: http://hassio.local:8123/local/adhan_fajr_makkah.mp3
        media_content_type: 'audio/mp3'  

I tried to run this portion in service console and worked fine for me , i used google chrom cast.
I also created this automation and from service trigger it and worked fine, try instead of using hassio.local, use the ip address of your pi, like http://192.168.7.10:8123/local/adan.mp3

Hey Hassan, Thanks for your assistance so far. I’ve come across another interesting issue, im not sure if this is a limitation or not, but I can only play 2 files per trigger…
so lets say im playing adhan and then the dua after it… it wont go past that.

They should work try the url in a browser and see if you have access and it runs, if so it should work, make sure you have the delays well measured.

I am not from Toronto but can help you remotely by accessing your computer through Teamviewer.

Hi @rizwan You can get a raspberrypi3 from BuyaPi.ca

These work for me with a goole home mini:

# Play Adhan
  - alias: Play Adhan
    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_speaker
          media_content_id: http://10.10.10.12:8123/local/adhan-main.mp3
          media_content_type: music
      - delay: '00:00:10'
      - service: input_boolean.turn_off
        entity_id: input_boolean.adhan
      - service: notify.ios_all
        data:
          message: 'It is {{ states.sensor.salah_actual.state }} time, please perform wudhu.'
      
# Play Adhan Fajr
  - alias: Play Adhan Fajr
    trigger:
    - entity_id: input_boolean.adhan_fajr
      from: 'off'
      platform: state
      to: 'on'
    condition: []
    action:
      - service: media_player.play_media
        data:
          entity_id: media_player.living_room_speaker
          media_content_id: http://10.10.10.12:8123/local/adhan-fajr.mp3
          media_content_type: music
      - delay: '00:00:10'
      - service: input_boolean.turn_off
        entity_id: input_boolean.adhan_fajr
      - service: notify.ios_all
        data:
          message: 'It is {{ states.sensor.salah_actual.state }} time, please perform wudhu.'
1 Like