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

Adhan is not playing on all the google devices. It’s playing only on one. Can someone please help.
Jazak Allah

you need to modify your automation.yaml file. How many google devices you have in total?

3 in total. Here is my automation.yaml

Automation for 5 times Azan

  • action:
    • alias: ‘’
      data:
      entity_id: media_player.kitchen_display
      entity_id: media_player.yumnas_bedroom_speaker
      media_content_id: https://www.islamcan.com/audio/adhan/azan2.mp3
      media_content_type: audio/mp3
      service: media_extractor.play_media
    • data:
      entity_id: media_player.kitchen_display
      entity_id: media_player.yumnas_bedroom_speaker
      volume_level: ‘0.6’
      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_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”)) }}’

Seperate Automation for Fajr Adhan

  • action:
    • alias: ‘Fajr Adhan’
      data:
      entity_id: media_player.kitchen_display
      entity_id: media_player.yumnas_bedroom_speaker
      media_content_id: https://www.youtube.com/watch?v=bFaIHrol5ck
      media_content_type: audio/mp3
      service: media_extractor.play_media
    • data:
      entity_id: media_player.kitchen_display
      entity_id: media_player.yumnas_bedroom_speaker
      volume_level: ‘0.6’
      service: media_player.volume_set
      alias: Fajr Adhan
      condition: []
      id: ‘1517694139112’
      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”)) }}’

Restart HA to force update Islamic Time Sensors at 1AM

  • alias: Restart HA
    trigger:
    platform: time
    at: “20:00:00”
    action:
    • service: homeassistant.restart

Assalaamualaikum,
Thanks, Sahar, for all of your work on this project! I have been dreaming of implementing Adhan into my home ever since I got my first Google Home Mini about 3 years ago. I had head of Home Assistant, but never had the nerve to dive into it until now. I now have Adhan echoing throughout my house through my Google Home devices!

I wanted to mention that if you have multiple devices, just simply create a group within the Google Home app on your phone and then add your devices to it. Then use that group as your media device in automations.yaml. My group is called “zgroup”, so it’s entity_id: media_player.zgroup

Works perfectly for me!

1 Like

Wa Alaikum Salam. Glad you made it.
Thanks for the information on how to deal with multiple google speakers. I reckon it would be of great help if post a few screenshots showing steps on how to group devices in the google app and also the concerned portion of your autiomation.yaml file.
JazakAllah.

I have lost access to the sensors. They are all saying… Entity not available: sensor.islamic_prayer_time_fajr (and the same error for the rest of the prayers). I can’t think of any change I made that would be causing this. Is this happening to anyone else? I have tried restarting everything but same errors.

Try restarting your server or even look for an update if available under Hass.io -> dashboard.
My senors are up and running fine.

I just had a quick question, would it be possible to do this using a Raspberry Pi Zero W, it has the required ports, my question is would the RAM be an issue at all ?

Welcome @fast900 to HassIO community. Yes, it is possible to install HassIO on a raspberry pi zero W. In fact my first installation was on Pi Zero W too. But Pi zero W is too slow because of having just 512 MB of RAM and it takes normally 20 to 30 minutes at its first boot.

what would be the recommended size of the ram otherwise, or should I just use the suggested Pi 3 or 4?

I suggest you buying a Raspberry Pi 4 with 2GB or 4GB RAM. Go for a 4GB model if you are not on a tight budget, otherwise, a 2GB model would be more than enough.

I’m happy to say that I got the sensors working again! I cloned my Linux VirtualBox, and then restored an older snapshot and the sensors were there :slight_smile:

Now the next things I’d like would be to have my hue lights blink a few times during adhan, and to have an adhan image display on my Google smart displays instead of a little icon. Both of these aren’t necessary, but they would be cool :slight_smile:

@msahar thanks for the great work,May Allah bless you.

I have 2 questions the first one, is this the right way to disable the Fajr

homeassistant:
  latitude: 40.921323
  longitude: -74.24435249999999
  unit_system: metric
  time_zone: America/New_York
  
default_config:
discovery:
media_extractor:
sun:

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'
  - platform: islamic_prayer_times
    calculation_method: mwl
    sensors:
#      - fajr
      - sunrise
      - dhuhr
      - asr
      - maghrib
      - isha
      - midnight

# Text to speech
tts:
  - platform: google_translate

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

The second question, how I can add Morning Azkar to play everyday at 10 am? I know it’s not part of the project but it will be great addon.

No. This is not a right way. You have to disable it from automation.yaml file.

You can use this code to play Azkaar at 10 AM in the morning. You need to add this code to your automation.yaml file.

Play Azkaar

- alias: Play Azkaar
  trigger: 
    platform: time
    at: "10:10:00"  
  action:
    - service: media_player.play_media
      entity_id: media_player.sahar_google_mini    #  Replace this with name of your google home mini
      data:
        media_content_id: https://myhomepi.tk:8123/local/azan.mp3   # Replace this with location of your Azkar file
        media_content_type: audio/mp3

@msahar Thank u so much.

1 Like

@msahar
I made this video with voice if someone want to step by step instructions.

2 Likes

جزاکم اللہ خیرا

Brother msahar.
Please I need help.
Alhamdulellah I had the azan automation working now jazak allah khira. However I have a such hard time to show the Azan time in the format of Am/Pm. I tried all the options to replace the strptime to strftime and use %I:%m%p. And because I am not a professional in writing the code I am struggling. So please help.
By the way config and the automation.yaml are exactly like yours and the azan Is working fine but the the time issue is my problem.

You need to edit your configuration.yaml file and replace all sensor with this code.

# Sensors
sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'time_date'
  - platform: islamic_prayer_times
    calculation_method: mwl
    sensors:
      - fajr
      - dhuhr
      - asr
      - maghrib
      - isha
  - platform: template
    sensors:
      salah_fajr:
        friendly_name: "Salah Fajr"
        value_template: >
           {%- set a = states("sensor.islamic_prayer_time_fajr").split("T")[1].split(":")[0] -%}
           {%- set b = states("sensor.islamic_prayer_time_fajr").split("T")[1].split(":")[1] -%}
           {{ a + ":" + b }}
      salah_dhuhr:
        friendly_name: "Salah Dhuhr"
        value_template: >
           {%- set a = states("sensor.islamic_prayer_time_dhuhr").split("T")[1].split(":")[0] -%}
           {%- set b = states("sensor.islamic_prayer_time_dhuhr").split("T")[1].split(":")[1] -%}
           {{ a + ":" + b }}
      salah_asr:
        friendly_name: "Salah Asr"
        value_template: >
           {%- set a = states("sensor.islamic_prayer_time_asr").split("T")[1].split(":")[0] -%}
           {%- set b = states("sensor.islamic_prayer_time_asr").split("T")[1].split(":")[1] -%}
           {{ a + ":" + b }}
      salah_maghrib:
        friendly_name: "Salah Maghrib"
        value_template: >
           {%- set a = states("sensor.islamic_prayer_time_maghrib").split("T")[1].split(":")[0] -%}
           {%- set b = states("sensor.islamic_prayer_time_maghrib").split("T")[1].split(":")[1] -%}
           {{ a + ":" + b }}
      salah_isha:
        friendly_name: "Salah isha"
        value_template: >
           {%- set a = states("sensor.islamic_prayer_time_isha").split("T")[1].split(":")[0] -%}
           {%- set b = states("sensor.islamic_prayer_time_isha").split("T")[1].split(":")[1] -%}
           {{ a + ":" + b }}

and then change your automation.yaml file like this,

# Automation for Azan
- action:
  - alias: 'Azan'
    data:
      entity_id: media_player.sahar_google_mini   # replace with your Google Home's id
      media_content_id: https://www.islamcan.com/audio/adhan/azan2.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.sahar_google_mini   # replace with your Google Home's id
      volume_level: '0.4'
    service: media_player.volume_set
  alias: Adhan
  trigger:
    - platform: template
      value_template: "{{ states('sensor.salah_fajr') == states('sensor.time') }}"
    - platform: template
      value_template: "{{ states('sensor.salah_dhuhr') == states('sensor.time') }}"
    - platform: template
      value_template: "{{ states('sensor.salah_asr') == states('sensor.time') }}"
    - platform: template
      value_template: "{{ states('sensor.salah_maghrib') == states('sensor.time') }}"
    - platform: template
      value_template: "{{ states('sensor.salah_isha') == states('sensor.time') }}"

first thank you bro for giving the time to help me.
however i tried it and it didn’t work.