This guide is written for people who want to have Azaan/Adhan/Azan played on their Alexa devices through HA automation 5 times a day. A shout out to porankazi as I used his code for Google Mini from here, also a shout out to Mark @ Mark Watt Tech
Disclaimer: By no means I am an expert in YAML or HA OS - just a person who wants to hear Azaan 5 times a day in my home.
Requirements:
- Installed and working Home Assistant (I am using HA OS on a Pi4 with a LAN)
- At least one Alexa device (Echo device, Sonos Alexa, etc.)
-
Alexa Media Player installed through HACS
- Either have Nabu Casa subscription or working remote access (I am using Nabu Casa subscription)
- Have access to update configuration.yaml and automation.yaml (I am using File Editor to do this)
Getting Your Adhan files ready:
- Download your adhan/azaan in mp3 format
- Use Jovo Converter (Audio File Converter for Alexa Skills | Jovo) to convert your MP3 file into an Alexa Readable format
- Be sure that your mp3 file is less then 240 secs or 4 minutes long
- Place the converted mp3 file into the folder /config/www/mp3
o I used Samba share to get access to RPI and copied the file there
Now to the fun stuff
Getting Home Assistant Ready:
- In Home Assistant go to Configuration > Integrations
- Add Integration
- Search for ‘Islamic Prayer Times’
- Install Integration
- Might need to restart your instance after the installation
- You would see the following integration in your Integrations tab:
Time to set up configurations and automation:
- Open configuration.yaml and insert the following code:
homeassistant:
latitude: !your Latitude
longitude: !your Longitude
unit_system: metric
time_zone: America/Toronto
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor:
- platform: time_date
display_options:
- ‘time’
- 'date'
- 'date_time'
- 'time_date'
- 'time_utc'
- 'beat'
Now to your automations.yaml – I will be showing how to do one prayer and I am assuming you can do this for the rest:
- id: Prayer_Isha
alias: Prayer_Isha
description: ''
trigger:
- platform: template
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == (as_timestamp(strptime(states("sensor.isha_prayer"), "%H:%M, %Y-%m-%d"))) }}'
condition: []
action:
- service: notify.alexa_media
data:
message: <audio src='https://xxxxx.ui.nabu.casa/local/mp3/azan_normal.mp3'/> #replace xxxx with your nabu casa link
target:
- media_player.xxxx_s_sonos_one
- media_player.echo_living_room
data:
type: tts
mode: single
For other namaz - I swtiched sensor.isha_prayer to sensor.dhuhr, sensor.asr, and sensor.maghrib
For Fajr - I switched sensor.isha_prayer to sensor.fajr_prayer and saved fajr adhan in the folder and pointed the code to play that adhan.
Hope this helps - JazakAllah Khair
Resources used:
- Samba Share: 5 Home Assistant Add-ons For Beginners - YouTube
- How to use Custom MP3s on Alexa: ALEXA CUSTOM MP3's (Using Home Assistant) - YouTube