Adhan Automation (الأذان التلقائي للصلاة) using google speaker

@Unixman Put this at the end of your 'automation.yaml' file. Save it and restart your Pi. This will restart your Pi automatically at 2 AM every night.

- alias: Restart HA
  trigger: 
    platform: time
    at: "02:00:00"  
  action:
    - service: homeassistant.restart

Thank you for the clue i just added like you mentioned, so it seems like a bug?

Actually it is difficult to comment on it. Some people have mentioned that they have this problem when their Pi was connected to the internet via WiFi and the problem is gone once they connected it to the internet via LAN cable whereas others reported quite opposite to it. Just monitor the behaviour of your Pi for one or two days to make sure everything is working as desired.

General Announcement

If due to some reason, Islamic prayer sensors are not updating automatically, considering adding the following code to the end of automation.yaml file. This code is meant to restart your raspberry pi at 1 AM every night thereby forcing the sensors to update.

############### Restart HA ############### 
- alias: Restart HA
  trigger: 
    platform: time
    at: "01:00:00"
  action:
    - service: homeassistant.restart
2 Likes

Salam Sahar, How do I add more speakers or devices(media_player.playroom_speaker) to this script? Also would it be any different for adding a google home hub?

Automation for 4 times Azan

  • action:
    • alias: ‘Azan’
      data:
      entity_id: media_player.family_room_speaker
      media_content_id: ‘https://youtu.be/iLctLGheEuM
      media_content_type: video/youtube
      service: media_extractor.play_media
    • data:
      entity_id: media_player.family_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_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”)) }}’

Separate alarm for Fajar Azan

  • action:
    • alias: ‘Azan_Fajr’
      data:
      entity_id: media_player.family_room_speaker
      media_content_id: ‘https://youtu.be/VHcRTIcRvN8
      media_content_type: video/youtube
      service: media_extractor.play_media
    • data:
      entity_id: media_player.family_room_speaker
      volume_level: ‘0.6’
      service: media_player.volume_set
      alias: Azan_Fajr
      condition: []
      id: ‘1517693034922’
      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”)) }}’

Iqbal

Have a look at this automation.yaml file. It uses multiple speakers.
automation.yaml

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

Please share your configuration.yaml and automation.yaml files.

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: