Adhan automation (أذان التلقائي) using Home Assistant and Google Home Mini

Thanks, i’ve added it. Everything works perfectly but i want the real time to show in the box rather than “hours ago”

azan

The solution is somewhere up in the comments.

@msahar Sahar - I am having issue getting the sensors working. I am using raspbian and configured hass a virtual service thats configured to restart upon reboot. I cant find the islamic_Prayer_times sensor entities either. I am unsure what I am doing wrong. I can run the azan manually by clickin execute on the automation page. Can I mail you directly? My email firozozman @ gmail.com.

Thank you so much for your help.
Massalama

Salaam, all.

First off, thanks @msahar for setting this up, excellent directions, JZK. A few notes I thought I would share from my setup experience, which are tweaks of post #1 which you need as a framework.

Automation File Allowing for Individual Azhan Settings and Suhoor Alarm

The below automation.yaml file allows for individual settings (ie, individual azhan for Fajr which is different, etc), and using the Entity Card (below), you can turn off each azhan as needed.

It also adds a “Suhoor” alarm to wake up everyone in time during Ramadan. :slight_smile:

Note, it uses local azhan mp3 files (great source here for many azhan options).

# Automation for 5 separate times Azan and Suhoor time alarm

# Separate alarm for Suhoor time wakeup
- action:
  - alias: ''
    data:
      entity_id: media_player.q_whole_home
      media_content_id: http://192.168.1.204:8123/local/adhan_qetami.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.q_whole_home
      volume_level: '0.3'
    service: media_player.volume_set
  alias: Suhoor
  condition: []
  id: '1517693034928'
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_fajr"), "%Y-%m-%dT%H:%M:%S")) - 1800 }}'

# Separate alarm for Fajr Azan
- action:
  - alias: ''
    data:
      entity_id: media_player.q_whole_home
      media_content_id: http://192.168.1.204:8123/local/adhan_Fajr_efasy.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.q_whole_home
      volume_level: '0.15'
    service: media_player.volume_set
  alias: Adhan Fajr
  condition: []
  id: '1517693034923'
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_fajr"), "%Y-%m-%dT%H:%M:%S")) }}'

# Zhuhr Alarm
- action:
  - alias: ''
    data:
      entity_id: media_player.q_whole_home
      media_content_id: http://192.168.1.204:8123/local/adhan_makkah_short.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.q_whole_home
      volume_level: '0.3'
    service: media_player.volume_set
  alias: Adhan Zhuhr
  condition: []
  id: '1517693010924'
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_dhuhr"), "%Y-%m-%dT%H:%M:%S")) }}'

# Asr Alarm
- action:
  - alias: ''
    data:
      entity_id: media_player.q_whole_home
      media_content_id: http://192.168.1.204:8123/local/adhan_makkah2.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.q_whole_home
      volume_level: '0.3'
    service: media_player.volume_set
  alias: Adhan Asr
  condition: []
  id: '1517693010925'
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_asr"), "%Y-%m-%dT%H:%M:%S")) }}'

# Maghrib Alarm
- action:
  - alias: ''
    data:
      entity_id: media_player.q_whole_home
      media_content_id: http://192.168.1.204:8123/local/adhan_makkah2.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.q_whole_home
      volume_level: '0.3'
    service: media_player.volume_set
  alias: Adhan Maghrib
  condition: []
  id: '1517693010926'
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_maghrib"), "%Y-%m-%dT%H:%M:%S")) }}'

# Isha Alarm
- action:
  - alias: ''
    data:
      entity_id: media_player.q_whole_home
      media_content_id: http://192.168.1.204:8123/local/adhan_makkah_short.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.q_whole_home
      volume_level: '0.3'
    service: media_player.volume_set
  alias: Adhan Isha
  condition: []
  id: '1517693010927'
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_isha"), "%Y-%m-%dT%H:%M:%S")) }}'

Entity Card

The following Entity Card for the overview screen works well to give on/off for each alarm, and formats the prayer times to show the actual times.

entities:
  - entity: automation.suhoor
  - entity: automation.adhan_fajr
  - entity: automation.adhan_zhuhr
  - entity: automation.adhan_asr
  - entity: automation.adhan_maghrib
  - entity: automation.adhan_isha
  - entity: sensor.islamic_prayer_time_fajr
    format: time
  - entity: sensor.islamic_prayer_time_sunrise
    format: time
  - entity: sensor.islamic_prayer_time_dhuhr
    format: time
  - entity: sensor.islamic_prayer_time_asr
    format: time
  - entity: sensor.islamic_prayer_time_maghrib
    format: time
  - entity: sensor.islamic_prayer_time_isha
    format: time
title: Prayer Alarms
type: entities

Virtualbox on Windows PC

Finally, I use a Windows PC as I have one running full time anyway. You can run Home Assistant using Virtualbox as follows.

  1. Make sure your PC is 64 bit, and virtualization is turned on in your BIOS
  2. Download Virtualbox from Oracle (free) and install
  3. Download the VMDK file instead when you follow post #1 above
  4. In Virtualbox, choose “New” and then specify “Linux 2,3, 4 64 bit”
  5. Then, you still have to change 2 settings, open settings and turn on “UEFI boot” under system and then also change the network type to “Bridged adapter” (the later allows your HASS to access the internet connection)
  6. Run!

Few Other Notes

To put everything in one place, as I know others have mentioned, but “configurator” doesn’t seem to be an add-on any more, instead use “file editor”.

Thanks again to @msahar for setting this all up, Ramadan Mubarak!

1 Like

Thanks for sharing your experience and taking time to help others.

thanks for sharing these tweaks! the athan link is a superb resource, and the entity card is a neat idea!

1 Like

Salam Sahar,

JazakAllah Khair for the solution. I’m completely new to Pi & HASSIO and i’ve just landed my hands on one just today for this purpose. I have a Googgle Nest Hub and i’d like to use it for the

  1. Azaan five times
  2. End of Suhur notification

Problems i face

  1. I’ve used OSX to flash my SD Card with HSSIO which doesn’t let me create the Wifi folder. So I can only connect with ethernet whch is not preferential

  2. After having installed the scripts (attached below). I can only see the Adhan and toggle for other times is missing.

Salam,

@msahar

I am trying to follow the installation guide and am unable to see the islamic prayer time states. I have restarted home assisstant, pi and reinstalled from scratch as well. Please help

Just as a follow up the automation also didn’t work and the Adhan didn’t play at Fajr.

Dear Msahar,

First of all thank you for your hard work and really its a great initiative

Everything was working fine till yesterday i got this message in the logs.

Log Details (ERROR)

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:112
Integration: Sensor (documentation, issues)
First occurred: 3:05:41 PM (1 occurrences)
Last logged: 3:05:41 PM

The islamic_prayer_times platform for the sensor integration does not support platform setup. Please remove it from your config.

Please find below my config file and automation file

Config file
`
homeassistant:
latitude: 23.424076
longitude: 53.847818000000004
elevation: 154
unit_system: metric
time_zone: Asia/Dubai

default_config:
discovery:
media_extractor:
sun:

sensor:

  • platform: yr
  • platform: time_date
    display_options:
    • ‘time’
    • ‘date’
    • ‘date_time’
    • ‘date_time_iso’
    • ‘time_date’
    • ‘time_utc’
    • ‘beat’
  • platform: islamic_prayer_times
    calculation_method: makkah
    sensors:
    • fajr
    • dhuhr
    • asr
    • maghrib
    • isha

Text to speech

tts:

  • platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
Automation file

Automation for 5 times Azan

  • action:
    • alias: ‘’
      data:
      entity_id: media_player.living_room_speaker
      media_content_id: https://www.islamcan.com/audio/adhan/azan2.mp3
      media_content_type: audio/mp3
      #media_content_type: audio/youtube
      service: media_extractor.play_media
    • data:
      entity_id: media_player.living_room_speaker
      volume_level: ‘0.9’
      service: media_player.volume_set
      alias: Adhan
      condition: []
      id: ‘1517693010922’
      trigger:
      • platform: template
        value_template: ‘{{ as_timestamp(strptime(states(“sensor.time_date”), “%H:%M, %Y-%m-%d”)) == as_timestamp(strptime(states(“sensor.islamic_prayer_time_fajr”), “%Y-%m-%dT%H:%M:%S”)) }}’
      • platform: template
        value_template: ‘{{ as_timestamp(strptime(states(“sensor.time_date”), “%H:%M, %Y-%m-%d”)) == as_timestamp(strptime(states(“sensor.islamic_prayer_time_dhuhr”), “%Y-%m-%dT%H:%M:%S”)) }}’
      • platform: template
        value_template: ‘{{ as_timestamp(strptime(states(“sensor.time_date”), “%H:%M, %Y-%m-%d”)) == as_timestamp(strptime(states(“sensor.islamic_prayer_time_asr”), “%Y-%m-%dT%H:%M:%S”)) }}’
      • platform: template
        value_template: ‘{{ as_timestamp(strptime(states(“sensor.time_date”), “%H:%M, %Y-%m-%d”)) == as_timestamp(strptime(states(“sensor.islamic_prayer_time_maghrib”), “%Y-%m-%dT%H:%M:%S”)) }}’
      • platform: template
        value_template: ‘{{ as_timestamp(strptime(states(“sensor.time_date”), “%H:%M, %Y-%m-%d”)) == as_timestamp(strptime(states(“sensor.islamic_prayer_time_isha”), “%Y-%m-%dT%H:%M:%S”)) }}’
        `

So i figured out the islamic prayer times is now available as an integration.

then in your configuration.yaml remove

platform: islamic_prayer_times
calculation_method: makkah
sensors:

* fajr
* dhuhr
* asr
* maghrib
* isha

Following which in your automations.yaml rename the islamic prayer sensors

islamic_prayer_time_fajr = fajr_prayer
islamic_prayer_time_dhuhr = dhuhr_prayer
islamic_prayer_time_asr = asr_prayer
islamic_prayer_time_maghrib = maghrib_prayer
islamic_prayer_time_isha = isha_prayer
3 Likes

Can you please share the complete automation file with the new configuration you mentioned above. Thanks.

@firozozman

Below are the configuration files. You have to modify the configuration.yaml for your location information.

You may have to modfy the automation.yaml for your prayer time calculation method.

After updating the configurations restart the server and create your entity cards as needed to show the time & automation controls.
This is what i have on my dashboard.

Automations.yaml

# Automation for Sehri Dua
- action:
  - alias: 'Sehri Dua'
    data:
      entity_id: media_player.adhan_group
      media_content_id: https://www.thesufi.com/Islamic-Collection/Islamic_Audio_Section/67-Islamic-Masnoon-Dua-Arabic-with-Urdu-Translation-MP3/Dua-and-Supplications--22-.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.adhan_group
      volume_level: '0.6'
    service: media_player.volume_set
  alias: Sehri_Dua
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.fajr_prayer"), "%Y-%m-%dT%H:%M:%S"))-35 }}'

# Automation for Iftari Dua
- action:
  - alias: 'Aftari Dua'
    data:
      entity_id: media_player.adhan_group
      media_content_id: https://www.thesufi.com/Islamic-Collection/Islamic_Audio_Section/67-Islamic-Masnoon-Dua-Arabic-with-Urdu-Translation-MP3/Dua-and-Supplications--23-.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.adhan_group
      volume_level: '0.6'
    service: media_player.volume_set
  alias: Aftari_Dua
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.maghrib_prayer"), "%Y-%m-%dT%H:%M:%S"))-45 }}'


# Automation for  Fajr Azan
- action:
  - alias: 'FajrAzan'
    data:
      entity_id: media_player.adhan_group
      media_content_id: https://archive.org/details/MakkahFajrAdhan6913SheikhAliMullah
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.adhan_group
      volume_level: '0.6'
    service: media_player.volume_set
  alias: Fajr_Adhan
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.fajr_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'

# Automation for 4 times Azan
- action:
  - alias: 'Azan'
    data:
      entity_id: media_player.adhan_group
      media_content_id: http://praytimes.org/audio/adhan/Sunni/Adhan%20Makkah.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.adhan_group
      volume_level: '0.8'
    service: media_player.volume_set
  alias: Adhan
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.dhuhr_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.asr_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.maghrib_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.isha_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'

### Restart HA to force update Islamic Time Sensors at 1AM ###
- alias: Restart HA
  trigger: 
    platform: time
    at: "01:00:00"
  action:
    - service: homeassistant.restart
    

Configuration.yaml


homeassistant:
  latitude: YOUR_LAT
  longitude: YOUR_LONG
  elevation: YOUR_ELEVATION
  unit_system: metric
  time_zone: YOUR_TZ
  
default_config:
discovery:
media_extractor:

# Example configuration.yaml using a non-default calculation method
islamic_prayer_times:
    calculation_method: isna
    
# Sensors
sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'time_date'
  - platform: template
    sensors:
      salah_fajr:
        friendly_name: "Salah Fajr"
        value_template: >
           {%- set a = states("sensor.fajr_prayer").split("T")[1].split(":")[0] -%}
           {%- set b = states("sensor.fajr_prayer").split("T")[1].split(":")[1] -%}
           {{ a + ":" + b }}
      salah_dhuhr:
        friendly_name: "Salah Dhuhr"
        value_template: >
           {%- set a = states("sensor.dhuhr_prayer").split("T")[1].split(":")[0] -%}
           {%- set b = states("sensor.dhuhr_prayer").split("T")[1].split(":")[1] -%}
           {{ a + ":" + b }}
      salah_asr:
        friendly_name: "Salah Asr"
        value_template: >
           {%- set a = states("sensor.asr_prayer").split("T")[1].split(":")[0] -%}
           {%- set b = states("sensor.asr_prayer").split("T")[1].split(":")[1] -%}
           {{ a + ":" + b }}
      salah_maghrib:
        friendly_name: "Salah Maghrib"
        value_template: >
           {%- set a = states("sensor.maghrib_prayer").split("T")[1].split(":")[0] -%}
           {%- set b = states("sensor.maghrib_prayer").split("T")[1].split(":")[1] -%}
           {{ a + ":" + b }}
      salah_isha:
        friendly_name: "Salah Isha"
        value_template: >
           {%- set a = states("sensor.isha_prayer").split("T")[1].split(":")[0] -%}
           {%- set b = states("sensor.isha_prayer").split("T")[1].split(":")[1] -%}
           {{ a + ":" + b }}
           
# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

Hello all, i am trying my code out. everything was working and recently has stopped working. I cant still get the 4 prayers to play but the Farj and Morning quls and night quls, not playing. It only makes a beep sound and thats it. Would be great if anyone can help look into my code. Thanks in advance. Also how do i make my timing to follow malaysia? currently i’ve added a few minutes but it changes each day depending on the world’s islamic timing… so i have to change manually each time.

# Automation for 4 times Azan
- action:
  - alias: 'Azan'
    data:
      entity_id: media_player.living_speaker
      media_content_id: https://www.youtube.com/watch?v=IYww573mn9U
      media_content_type: audio/youtube
    service: media_extractor.play_media
  - data:
      entity_id: media_player.living_speaker
      volume_level: '0.9'
    service: media_player.volume_set
    alias: Adhan
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_dhuhr"), "%Y-%m-%dT%H:%M:%S")) +180}}'
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_asr"), "%Y-%m-%dT%H:%M:%S")) +60}}'
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_maghrib"), "%Y-%m-%dT%H:%M:%S")) +120}}'
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_isha"), "%Y-%m-%dT%H:%M:%S")) +360}}'
# Automation for 4 times Azan
- action:
  - alias: 'Azan farj'
    data:
      entity_id: media_player.living_speaker
      media_content_id: https://www.youtube.com/watch?v=VHcRTIcRvN
      media_content_type: audio/youtube
    service: media_extractor.play_media
  - data:
      entity_id: media_player.living_speaker
      volume_level: '0.5'
    service: media_player.volume_set
    alias: Adhan Farj
  trigger:
  - platform: template
    value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_time_fajr"), "%Y-%m-%dT%H:%M:%S")) +60}}'
### Restart HA to force update Islamic Time Sensors at 1AM ###
- alias: Restart HA
  trigger: 
    platform: time
    at: "01:00:00"
  action:
    - service: homeassistant.restart
# Automation for Morning Quls
- action:
  - alias: 'Morning Quls'
    data:
      entity_id: media_player.living_speaker
      media_content_id: https://www.youtube.com/watch?v=Zap5DPPgZJM
      media_content_type: audio/youtube
    service: media_extractor.play_media
  - data:
      entity_id: media_player.living_speaker
      volume_level: '0.7'
    service: media_player.volume_set
    alias: Morning Quls
  trigger:
      platform: time
      at: "08:30:00"
# Automation for Night Quls
- action:
  - alias: 'Night Quls'
    data:
      entity_id: media_player.living_speaker
      media_content_id: https://www.youtube.com/watch?v=Zap5DPPgZJM
      media_content_type: audio/youtube
    service: media_extractor.play_media
  - data:
      entity_id: media_player.living_speaker
      volume_level: '0.9'
    service: media_player.volume_set
    alias: Night Quls
  trigger:
      platform: time
      at: "22:45:00"

Could you please show me your config and automation scripts

Thanks for sharing. Perfect timing… worked well for me

Amazing effort.

This is my Salah dashboard.image

Assalamu Alikum
I have read all above instruction and then i have one question.
I want to Adjust Azar Prayer Offset 30 Minutes .how can i do it .
(i found for 5 minutes - +3600) i didnt get this calculation

Can you please explain for me

Have you found the fix? Same Issue here.