*Very simple* Use Islamic Prayer Times integration to cast Athan when the time for prayer goes in

Automation to Play MP3 at Maghrib Prayer Time

This automation plays an MP3 file when the Maghrib prayer time occurs. It’s a useful setup for those who want to be reminded of prayer times with a specific audio file. I found alot of brothers trying to help doing this but they were so complex, this one is way more simple.
Just take it, change the prayer name etc and set it up for the prayers you want.

Took me a looong time to figure this one out and I took some help from Chatgpt but Alhamdullilah, solved it.

The only thing is, the Asr time is 2 hours later and Isha is WAAY late, its probably differences of school . If someone can help me how to fix that, I would be helpful. I have chosen all the proper setting in the “Islamic Prayer Times” integration but it still wont be corrected.

This is my first share so sorry for any formatting mistakes

Automation Configuration

Here is the YAML configuration for the automation:

alias: Play MP3 at Maghrib Prayer Time
description: Plays an MP3 file when Maghrib prayer time occurs
trigger:
  - platform: template
    value_template: >
      {{ now().strftime('%H:%M') ==
      (as_timestamp(states('sensor.islamic_prayer_times_maghrib_prayer')) |
      timestamp_custom('%H:%M', true)) }}
condition: []
action:
  - service: logbook.log
    data:
      name: Maghrib Prayer Triggered
      message: >-
        Maghrib prayer time matched current time: {{ now().strftime('%H:%M') }} ==
        {{ as_timestamp(states('sensor.islamic_prayer_times_maghrib_prayer')) |
        timestamp_custom('%H:%M', true) }}
  - service: media_player.volume_set
    target:
      entity_id: media_player.living_room
    data:
      volume_level: "0.7"
  - service: media_player.play_media
    target:
      entity_id: media_player.living_room
    data:
      media_content_id: media-source://media_source/local/athan.mp3
      media_content_type: audio/mpeg
mode: single

Explanation

  • Trigger:
    • The automation triggers when the current time matches the Maghrib prayer time. This comparison is done by converting both times to the same format (%H:%M).
  • Actions:
    • Logbook Log: Logs an entry in the logbook indicating the Maghrib prayer time was matched.
    • Set Volume: Sets the volume of the specified media player (media_player.living_room) to 70%.
    • Play Media: Plays the MP3 file (athan.mp3) on the specified media player.

This setup ensures that at the precise time of Maghrib prayer, the specified MP3 file will play, providing an audible reminder for the prayer time.

Tips

  1. Adjust Entity IDs: Make sure to replace media_player.living_room with the correct entity ID of your media player.
  2. File Location: Ensure that the MP3 file (athan.mp3) is correctly placed in the media folder of your Home Assistant configuration.

Feel free to ask questions or share your feedback!

No idea where you looked, or why ChatGPT was needed, but there are simpler versions that have been posted in this community forum for several years.

The simplest uses a Time Trigger that triggers when the current time is equal to the time of the Maghrib sensor. I left out posting to the Logbook because that’s an entirely optional step (and the goal here is to keep it “very simple”).

alias: Maghrib example
trigger:
  - platform: time
    at: sensor.islamic_prayer_times_maghrib_prayer
condition: []
action:
  - service: media_player.volume_set
    target:
      entity_id: media_player.living_room
    data:
      volume_level: "0.7"
  - service: media_player.play_media
    target:
      entity_id: media_player.living_room
    data:
      media_content_id: media-source://media_source/local/athan.mp3
      media_content_type: audio/mpeg
mode: single

  • For anyone wishing to use this example, be advised that the name of sensor.islamic_prayer_times_maghrib_prayer might be different on your system. When you installed the Islamic Prayer Times integration, the default name used in all its sensors is islamic_prayer_times. If you changed the default name, all the sensors will use whatever name you chose.

  • In addition, the example refers to an audio file named athan.mp3. It’s unlikely to exist on your system unless you put it there. You’ll have to change it to the name of whatever audio file you have installed. It can also refer to an external audio source (i.e. in the cloud).

  • Lastly, you will need to change media_player.living_room to whatever media_player you have in your system.

All this to say that even an allegedly “very simple” version involves a certain degree of complexity.

Jzk.

Like I said, I am very new to this stuff. I searched and searched but wasnt able to find, I might be using wrong terms. The ones I found was this one with red node and such. Thanks.

Do you have any idea on how to change the times to match my times more correct, For example, Asr is around 17.30 but it goes in at like 18.40.

I dont know if its the madhab but Ive tried all options but it still wont get to my one wich is actually Diyanet measurement and Hanafi.

The integration’s “Configure” section allows you to change various parameters that control its operation. If you tried adjusting those parameters and nothing worked like you wanted, then the integration doesn’t support it.

For more information, you can search the community forum for related posts by using the phrase islamic prayer.