Azaan/Adhan/Azan on your Alexa devices

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 :blush:
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:
    Capture1

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:

2 Likes

You only need one automation to handle all five times plus you can use a simple Time Trigger instead of a Template Trigger.

I posted an example in a related thread. The trigger is simply this:

- alias: Call to prayer example
  trigger:
  - platform: time
    at: 
    - sensor.fajr_prayer
    - sensor.dhuhr_prayer
    - sensor.asr_prayer
    - sensor.maghrib_prayer
    - sensor.isha_prayer
  action:
  ... etc ...

This is great - the Template Trigger is a pain to deal with. I will test this for sure, simplifies a bunch of things - the only limitation, for me, is that I follow the Hanafi Asr method - due to which I increase the asr time by about an hour. Is there a way to do it with this?

Yes. In the other thread I provided an example of how to offset all the prayer times by a few minutes.

If you only want to offset one prayer time (asr) then it’s easy to modify the example. Just add 3600 seconds (1 hour) to asr time.

- alias: 'Example 1'
  trigger:
  - platform: template
    value_template: >
      {% set f = as_timestamp(states('sensor.fajr_prayer')) %}
      {% set d = as_timestamp(states('sensor.dhuhr_prayer')) %}
      {% set a = as_timestamp(states('sensor.asr_prayer')) + 3600 %}
      {% set i = as_timestamp(states('sensor.isha_prayer')) %}
      {% set m = as_timestamp(states('sensor.maghrib_prayer')) %}
      {{ now().timestamp() | int in [f, d, a, i, m] }}
  action:
  ... etc ...

Thanks, yeah this will definitely make my configuration.yaml more clean :slight_smile:

Salam alikom, is this working for you?
What’s your updated yaml config?
I would love to get This working.

Hello All,
im looking for the easiest way to add offset to athan as follow:

This is the automation Trigger:

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

And this is my configuration:

sensor:
  - platform: time_date
    display_options:
      - "time"
      - "date"
      - "date_time"
      - "date_time_iso"
      - "time_date"
      - "time_utc"
      - "beat"

Thanks in advance!

Hello,

i found the fix, i had the wrong islamic sensor defined, here is the corrected one …

trigger:
  - platform: time
    at: sensor.islamic_prayer_times_fajr_prayer
  - platform: time
    at: sensor.islamic_prayer_times_dhuhr_prayer
  - platform: time
    at: sensor.islamic_prayer_times_asr_prayer
  - platform: time
    at: sensor.islamic_prayer_times_maghrib_prayer
  - platform: time
    at: sensor.islamic_prayer_times_isha_prayer

for a average this this is almost impossible to do. please try my athan solution which is fully automated turn-key solution: Smart Azan Automation For Alexa