Islamic Prayer Times Notifications (On mobile device and Media Player like Alexa)

Hi, can you please share code that works with Alexa that’s play mp3 which I have link, I don’t need anymobile notifications… I have tried soo many codes which have failed. @raub21
Thanks

Sure. Just make sure you install Alexa in Home Assistant and that is working fine. Second, add the Islamic prayer time integration from the settings<devices and service<add integration. After that, configure the islamic prayer and integration to the calculation method you prefer.
Now, you can go the automation page and paste the following code:

alias: Adthan call through Alexa echo
description: ""
trigger:
  - platform: time
    at: sensor.dhuhr_prayer
    id: dhuhr
  - platform: time
    at: sensor.asr_prayer
    id: Asr
  - platform: time
    id: Maghrib
    at: sensor.maghrib_prayer
  - platform: time
    id: Isha
    at: sensor.isha_prayer
  - platform: time
    id: fajr
    at: sensor.fajr_prayer
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: dhuhr
        sequence:
          - service: notify.family
            data:
              message: حان الآن موعد صلاة الظهر
              title: 🕌 Prayer Time 🕌
          - service: notify.alexa_media
            data:
              message: <audio src='https://yourhomeassistanturl/local/audio/duhradthan.mp3'/>
              target:
                - media_player.kitchen_s_echo_show
                - media_player.master_show
              data:
                type: tts
      - conditions:
          - condition: trigger
            id: Asr
        sequence:
          - service: notify.family
            data:
              message: حان الآن موعد صلاة العصر
              title: 🕌 Prayer Time 🕌
          - service: media_player.volume_set
            data:
              volume_level: 0.7
            target:
              entity_id:
                - media_player.kitchen_show
                - media_player.master_show
          - service: notify.alexa_media
            data:
              message: <audio src='https://yourhomeassistanturl/local/audio/asradthan1.mp3'/>
              target:
                - media_player.kitchen_show
                - media_player.master_show
              data:
                type: tts
      - conditions:
          - condition: trigger
            id: Maghrib
        sequence:
          - service: notify.family
            data:
              message: حان الآن موعد صلاة المغرب
              title: 🕌 Prayer Time 🕌
          - service: notify.alexa_media
            data:
              message: <audio src='https://yourhomeassistanturl/local/audio/maghribadthan.mp3'/>
              target:
                - media_player.kitchen_show
                - media_player.living_room_show
                - media_player.master_show
              data:
                type: tts
      - conditions:
          - condition: trigger
            id: Isha
        sequence:
          - service: notify.family
            data:
              message: حان الآن موعد صلاة العشاء
              title: 🕌 Prayer Time 🕌
          - service: notify.alexa_media
            data:
              message: <audio src='https://yourhomeassistanturl/local/audio/ishaadthan.mp3'/>
              target:
                - media_player.kitchen_show
                - media_player.living_room_show
                - media_player.master_show
              data:
                type: tts
      - conditions:
          - condition: trigger
            id: fajr
        sequence:
          - service: notify.family
            data:
              message: حان الآن موعد صلاة الفجر
              title: 🕌 Prayer Time 🕌
          - service: notify.alexa_media
            data:
              message: <audio src='https://yourhomeassistanturl/local/audio/subhadthan.mp3'/>
              target:
                - media_player.living_room_show
                - media_player.master_show
                - media_player.kids_dot
              data:
                type: tts
mode: single

As added note, I host the adthan mp3 files on HA. So the url https://yourhomeassistanturl has to have the right path for the mp3 files. For instance: Let say the url of your home assistant is: https://nameless900.ga . The adthan file can be stored for example in a directory audio with the following link: https://nameless900.ga/local/audio/adthan.mp3
I hope that was clear and let me know if you need further assistance.

Did you fix the issue? if not, where are you located?

no the times are still off of my local mosque. I am located in vancouver canada

sorry hit wrong thing and double posted

Salam aalikom brother. I think the prayers time will be slightly off or over since every mosque has different times for iqamah. Here is my setup of the islamic prayer integration.
image
And here are the prayers times for the mosque I go to:
image

Here are my prayers times from Home assistant:
image

The only thing I may suggest is to check the Home zone in Home assistant is set to your house location in Vancover or close to it. You can check it that in maps in home assistant. Post back if you need further details.

walaikum salam, I have set my location in HA to where I am located as i was trying to make some person cards as well with location status such as home, work and out.
I have gone through all of the different options for choosing a prayer time location and for me they almost always have 1221, 222, and 441 for dhur, asr, and maghrib.
I found some that were close but yours just seem much closer to the appropriate time. Such as asr is always 35min early for me, dhur always 10min early, maghrib not too bad its only 6 min early.
I think ill choose jafari it seems the least “off”
my mosque times are 607, 1231, 257, 447, and 617.
Jafari lists 619, 1221, 222, 504 and 610.

where do i go from here? scripts? blueprints? never done any of this yet only installed some basic integrations for light switch and bulbs lol. Started tinkering with a custom person card but doesnt work yet. Thank you for your help so far

Yes there will be differences in time according to different calculations. For instance, Asr in my mosque start at 4:15pm since I think they chose to follow the ISNA method of calculation. In Home assistant, I chose the Makkah method of calculation and Asr is 3:31pm for me.
I am new as well to home assistant. I migrated from Smarthings that I started using back in 2016. I like Home assistant better since there are plenty of room to tweak things. I am using zwave, zigbee and wifi devices in my setup. As far, as to scripts and blueprints, it all depends what you want to accomplish. There are many tutorials in this community and in youtube. Just be patient and learn a little bit every day.

ya i figure if its close enough then at least its that rmeinder that its almost time or time. I was using homebridge but like the customization of HA better. So far i only have a few light bulbs, thermostats and light switches all on wifi. No clue what zwave or zigbee is lol will have to look that up as ive seen many people mention zigbee. ive tinkered with getting a tablet set up with a “control panel” for when leaving can quickly see everything we need to.

With this little side of the project i want to try and get the azhan to play on my home pods, google mini, and alexa so its heard in all the rooms. did you try the script posted above and have it working?

For sure, I ve found that HA is way better and more complex as well. Make sure you install Hacs,file editor, samba share and google backup.
The last code posted above is mine and that is working perfect for me with Alexa. Adthan is played at the same time in some chosen amazon devices. I installed and setup Alexa in HA which was a little long process since I did not do it through the HA cloud ( nabu casa). Google Home devices seem easy to configure and play all different medias. There are some tutorials on this community forums how to configure adthan on google devices. The same goes for the Apple devices. On a side note, I would recommend if you can afford it to get sonos.

thanks ill take a look at your code and give it a shot. i havent set up the alex and google home mini yet as i was debating trying to setup remote access without subscription for cloud access havent had time yet. Ill look into sonos but right now funds are a little tight so im using what i got lol. Ill take a look for some of the tutorials and see if i can make it work… might just have it come out the apple homepods if it seems too difficult to run off the 3 different types… thinking id maybe need 3 different scripts set up for it maybe… thanks for the advice ill give it a go this weekend

You can check the following video from youtube even you don’t understand the language (which what I did). He is using apple music to play adthan in alexa but the process is the same for homepods (when he is choosing the media player, you will choose your homepods. The code I posted above is inspired from the person on the video. I tweaked a little for my needs. Just make sure your homepods are integrated in the HA.
Click here to see the video.

1 Like

so finally trying to set this up i followed the video but it wouldnt let me save giving me an error so ive started going visual to yaml and trying to match yours. my media is confusing me. I have an athan downloaded from apple music but cant figure out how to link it. so was going to put an mp3 in my media folder. however i have samba installed and ive accessed the media folder before to add a photos folder. now i want to add an audio folder and it wont open my HA on windows just wants to open the webpage. getting verty confused here with this set up

alias: Athan Call
description: ""
trigger:
  - platform: time
    id: dhuhr
    at: sensor.dhuhr_prayer
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: dhuhr
        sequence:
          - service: media_player.media_pause
            data: {}
            target:
              entity_id:
                - media_player.living_room_2
                - media_player.living_room_3
          - service: media_player.play_media
            data:
              message: <audio src='https://homeassistant.local:xxxx/local/ZuhrAthan.mp3'/>
            target:
              entity_id:
                - media_player.living_room_2
                - media_player.living_room_3
mode: single


so i set this up and ran the test and it doesnt work… not sure what i did wrong

1- Which media player devices are you trying to play adthan on? Alexa devices or apple homepods? Also, make sure they are connected to HA?
2- Check the following screenshot and follow it

Also, to be able to play the adthan from your own home assistant server, you will need to have it configured to connect to it remotely from outside. The easy way is through Nabucasa.
If you are still facing challenges, I will be happy to assist you if you prefer doing it one on one.

so i just tested dhuhr with my working call service from the developer tools but i think i messed up my trigger

alias: Athan Call
description: ""
trigger:
  - platform: time
    id: dhuhr
    at: sensor.dhuhr_prayer
condition: []
action:
  - service: media_player.play_media
    data:
      media_content_id: http://homeassistant.local:####/local/ZuhrAzan.mp3
      media_content_type: music
      annouce: true
    target:
      entity_id:
        - media_player.living_room_2
mode: single

edit: so i retried and got this:

alias: Athan Call
description: ""
trigger:
  - platform: time
    id: asr
    at: sensor.asr_prayer
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: asr
        sequence:
          - service: media_player.play_media
            target:
              entity_id: media_player.living_room_2
            data:
              media_content_id: media-source://media_source/local/ZuhrAzan.mp3
              media_content_type: audio/mpeg
            metadata:
              title: ZuhrAzan.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
mode: single

the only problem i forsee is for instance asr time is still about 30min off which is frustrating… debating if i should set the time and then change it manually every day or 2… havent decided yet

If you got it to work and just need to offset the time for Asr prayer, you can add delay command in the actions.

alias: Athan Call
description: ""
trigger:
  - platform: time
    id: asr
    at: sensor.asr_prayer
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: asr
        sequence:
          - delay:
              hours: 0
              minutes: 30
              seconds: 0
              milliseconds: 0
          - service: media_player.play_media
            target:
              entity_id: media_player.living_room_2
            data:
              media_content_id: media-source://media_source/local/ZuhrAzan.mp3
              media_content_type: audio/mpeg
            metadata:
              title: ZuhrAzan.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
mode: single

You can do this way above or follow what this person mentioned here

oh that seems simple thank you… at least from a quick glance how you did it verse the other post lol. I wrote down my mosque times and HA times yesterday and going to do that for the week and see if its the same time everytime then itll make it alot easier.

side question if you can delay the time is there a way to play it earlier? some of them go off 5-10min late but if the times are the same offset every day then i thought maybe i could have them play early as well if possible

To play it earlier, I am going to quote @123 from this post.

Here is his code:

trigger:
  - platform: template
    value_template: >
      {{ now().timestamp() | int(0) + 600 in expand('sensor.fajr_prayer', 'sensor.dhuhr_prayer', 
        'sensor.asr_prayer', 'sensor.isha_prayer', 'sensor.maghrib_prayer')
        | map(attribute='state') | map('as_timestamp') | list }}

ok thanks ill start with the delay and see how that works out and then move to the earlier. YAML really confuses me lol just need more practice i guess

So…… I didn’t even try a offset yet I just decided to
Make a second automation for Maghrib and make sure that one worked as well. The first time asr went off it worked now today it starts maybe 10-15 sec then stops and maghrib did the same so back to the drawing board not sure what went wrong

You mean the audio file for adthan started on time but it did not go through the whole time length? what device:Alexa or homepods?