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
).
- The automation triggers when the current time matches the Maghrib prayer time. This comparison is done by converting both times to the same format (
- 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
- Adjust Entity IDs: Make sure to replace
media_player.living_room
with the correct entity ID of your media player. - File Location: Ensure that the MP3 file (
athan.mp3
) is correctly placed in themedia
folder of your Home Assistant configuration.
Feel free to ask questions or share your feedback!