Home Assistant Automation: Azan Reminder & Soundbar Control
Overview
This automation ensures that a reminder plays 5 minutes before the Dhuhr, Asr, Maghrib, and Isha Athan (Azan) using a media player (e.g., a soundbar). Additionally, it turns off a connected switch (e.g., a TV) to avoid interruptions.
For Fajr, the configuration is not yet added, but feel free to contribute!
Requirements
- Mawaqit Integration: Follow this guide (Thanks, Moha Tah!) to integrate Mawaqit into Home Assistant.
- A compatible media player in Home Assistant (e.g., a DLNA soundbar).
- An entity switch (optional) to turn off devices like a TV before the Azan.
YAML Code
yaml
CopyEdit
alias: 4 Azan Working - Soundbar
description: "Reminder 5 minutes before Azan & turn off TV"
trigger:
- platform: template
value_template: >-
{{ (as_timestamp(states('sensor.dhuhr_adhan')) - 300) | timestamp_custom('%H:%M:%S') == now().strftime('%H:%M:%S') }}
- platform: template
value_template: >-
{{ (as_timestamp(states('sensor.asr_adhan')) - 300) | timestamp_custom('%H:%M:%S') == now().strftime('%H:%M:%S') }}
- platform: template
value_template: >-
{{ (as_timestamp(states('sensor.maghrib_adhan')) - 300) | timestamp_custom('%H:%M:%S') == now().strftime('%H:%M:%S') }}
- platform: template
value_template: >-
{{ (as_timestamp(states('sensor.isha_adhan')) - 300) | timestamp_custom('%H:%M:%S') == now().strftime('%H:%M:%S') }}
# Main Azan triggers
- platform: time
at: sensor.dhuhr_adhan
- platform: time
at: sensor.asr_adhan
- platform: time
at: sensor.maghrib_adhan
- platform: time
at: sensor.isha_adhan
condition: []
action:
- choose:
# 5-minute pre-Azan alert
- conditions:
- condition: template
value_template: >-
{{ (as_timestamp(states('sensor.dhuhr_adhan')) - 300) | int == now().timestamp() | int or
(as_timestamp(states('sensor.asr_adhan')) - 300) | int == now().timestamp() | int or
(as_timestamp(states('sensor.maghrib_adhan')) - 300) | int == now().timestamp() | int or
(as_timestamp(states('sensor.isha_adhan')) - 300) | int == now().timestamp() | int }}
sequence:
- service: switch.turn_off
target:
entity_id: switch.nabeel_steckdose_l1
- service: media_player.play_media
target:
entity_id: media_player.soundbar_dnla
data:
media_content_id: media-source://media_source/local/azan/beep_with_silence.mp3
media_content_type: audio/mpeg
# Main Azan (5 min later)
- conditions: []
sequence:
- service: media_player.play_media
target:
entity_id: media_player.soundbar_dnla
data:
media_content_id: media-source://media_source/local/azan/Azan.mp3
media_content_type: audio/mpeg
mode: single
How It Works
5 minutes before Azan:
- Plays a short notification sound.
- Turns off the TV (or any switch you define).
At Azan time:
- Plays the full Athan (Azan) audio on the soundbar.
To-Do (Fajr Azan Support)
- You need to add the Fajr Azan sensor:
yaml
CopyEdit
- platform: template
value_template: >-
{{ (as_timestamp(states('sensor.fajr_adhan')) - 300) | timestamp_custom('%H:%M:%S') == now().strftime('%H:%M:%S') }}
- platform: time
at: sensor.fajr_adhan
- Include Fajr in the condition checks inside
action
.
Why This Is Useful
Great for big sound systems that take time to start.
Works even if your TV or other devices are on.
Ensures you never miss the Azan with a reminder.
Hope this helps! Let me know if you need any improvements.