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

There was an upgrade last week, but I installed it though. It’s weired, what the reason my sensors didn’t update ? Do you have any doc or explanation about how sensor works , will be highly appreciated.

Ok last try. Open your configuration.yaml file, delete everything in it and then paste the code below in it. Do not modify anything in the code below. Just copy and paste and save the file.

homeassistant:
  name: Home
  latitude: 45.5182423
  longitude: -73.7256242
  unit_system: metric
  time_zone: America/Toronto
  
default_config:
discovery:
media_extractor:

# 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
  
# Text to speech
tts:
  - platform: google_translate
    
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

Now open your automation.yaml file and delete everything in it. Then copy the code below and paste it there and save the file. Do not modify any line or entry in the code below.

# Automation for Azan
- action:
  - alias: 'Azan'
    data:
      entity_id: media_player.family_room_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.family_room_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_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")) }}'

Then restart your raspberry Pi and check whether your sensors could get an update or not.

Salam Msahar,
I did what you suggest to me but not working again.

  1. There is something wrong with your config file. If you have used config file that I have provided, then there must be no sunrise senor in states but you are having sunrise senor. Thats means your hassIO is still using old file.
  2. Your family speaker is not available to hassIO. It is in unavailable state. It should be either in OFF or ON state.

I have sent you private msg. plz check it out.

I also still continue to see the same issue that no timely update of adhan sensors - sometimes they update at 3pm sometimes later, depending on the time they update, rest of the adhan for that day only will play and then next day when it updates and so on. Not sure what is the issue. We discussed in details before but it was not resolved and now this user also facing same issue like me. I did not get time to load the home-assistant on SD card though and run through that. It is still through python.

Then I guess there is something wrong with Adhan API being used in islamic_prayer_times. However, it is working fine for me for the last 2 months and I never faced a problem. It is very difficult to report this behaviour to its developers if we can not reproduce it :frowning:

Just informing you that this user has solved his problem. He had some problems in his configuration.yaml file and I helped him out via private message (sent him config file specifically built for him based on his time zone)

Could you help me as well in a similar fashion? I too using the config file that you shared with me publicly. Thank you.

1 Like

We have to test your Hass with a bare-minimum of config and automation file. Please reply me privately with this info.

  1. Longitude
  2. Latitude
  3. Time Zone
  4. Name of your google home mini

Jazakallah Sahar! I was able to install Home Assistant on a Windows PC with a virtual setup and run the config and automation files with no issues :slight_smile: My parents are thrilled. Just to add to one of the previous comments from user to run a dua after athan, I was able to simply use a youtube video with dua in it. I wasn’t able to find one for regular athan though, I will try running it will a delay to see if that works and report back.

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

Hope this helps others.

2 Likes

Glad to hear @imateen that you have made it. I also haven’t found any easy method to play dua after Adhan and my workaround is similar to yours. I have appended a dua to my azan mp3 file (using online audio joiner).

Salam alikoum , I already posted this message in other thread but I wanted to post here again just to be sure that I’m in correct one.
I successfully got work this athan sensor ,and I changed calculated method to isna and I reload the scripts automations , and now the sensors didn’t get changed till restart control server, so I have to restart it every day to make it work, i updated the ha to the last version but still not working. Did someone get same issue? What’s the solution? Jazakoum allahou khayrane

1 Like

@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.