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

Thanks for your immediate replay .
I will wait up to 2 days and after that confirm with you the status .
If not working after 2 days I believe you will help me to fix

If anyone want to offset the prayer times by several minutes, you can use a single Template Trigger like this:

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

It offsets each of the five prayer times by 5 minutes (300 seconds). Each prayer time’s offset can, of course, be set to whatever you want. The example adds the offset to the prayer time but, if needed, you can change it so it subtracts the offset from the time,

If you want the ability to adjust the offset time in the Lovelace UI, I suggest creating five input_number entities, one for each prayer time. The following example shows how to configure five input_numbers where each one permits setting a value between 0 and 20 minutes.


Click to reveal configuration example for input_numbers
input_number:
  fajr:
    name: 'Fajr Offset'
    min: 00
    max: 20
    step: 1
  dhuhr:
    name: 'Dhuhr Offset'
    min: 00
    max: 20
    step: 1
  asr:
    name: 'Asr Offset'
    min: 00
    max: 20
    step: 1
  isha:
    name: 'Isha Offset'
    min: 00
    max: 20
    step: 1
  Maghrib:
    name: 'Maghrib Offset'
    min: 00
    max: 20
    step: 1

Then you can use the following Template Trigger:

- alias: 'Example 2'
  trigger:
  - platform: template
    value_template: >
      {% set f = as_timestamp(states('sensor.fajr_prayer'))  + states('input_number.fajr')|int * 60 %}
      {% set d = as_timestamp(states('sensor.dhuhr_prayer')) + states('input_number.dhuhr')|int * 60 %}
      {% set a = as_timestamp(states('sensor.asr_prayer'))   + states('input_number.asr')|int * 60 %}
      {% set i = as_timestamp(states('sensor.isha_prayer'))  + states('input_number.isha')|int * 60 %}
      {% set m = as_timestamp(states('sensor.maghrib_prayer')) + states('input_number.maghrib')|int * 60 %}
      {{ now().timestamp() | int in [f, d, a, i, m] }}
  action:
  ... etc ...
1 Like

Dear aamans .
From today night it has started working for me .I didn’t do anything.
But there is one issue only .the Isha prayer time is different with Qatar actual prayer time .
Actual Isha Time 7:29 PM
BUT showing in home assistant 7:58 PM
Kindly helpe to fix the issue .
Other everything is good

@shamseer change the calculation method to one that gives the right time.

Google aladhan prayer api and read through the different methods. Change the code in config.yaml to define sensors. HTH

As salam,

I would like to know will this also work with Amazon Alexa Echo Dot?

@fshaikh15 I have made it work is Echo that’s what I am using now, it’s a bit more involved as you need to install HACS and Alexa media player. see my post on the Hanafi Islamic prayer topic here

hi, my salah times are showing UTC values. sensor.salah_fajr is UTC but sensor.fajr_prayer is correct. how can i solve this?

Hi,
for some reason now my Dhuhr Prayer Athan is not triggering, everything else is. It’s not even giving an error in the log file
anyone having the same problem

Please help, Automated adhan not working for me. No adhan has happened. I used your code.

Hi Team,

I am new to Home Assistant and following the code above but to no avail. Can someone please help on the below code:

Configuration.Yaml:
homeassistant:
latitude: -35.282001
longitude: 149.128998
elevation: 577
unit_system: metric
time_zone: Australia/Sydney

#default_config:
discovery:
media_extractor:
#sun:

sensor:
#- platform: weather_data

  • 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
  • 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 }}

automation.yaml:

Automation for 4 times Azan

  • action:
    • alias: ‘Azan’
      data:
      entity_id: media_player.family_room_speaker
      media_content_id: Azan masjid e nabvi madina munawra|| beautiful voice 2021|| Azan | madina - YouTube
      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: ‘1517693010822’
      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 = 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.islamic_prayer_time_asr = 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.islamic_prayer_time_maghrib = 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.islamic_prayer_time_isha = isha_prayer”), “%Y-%m-%dT%H:%M:%S”)) }}’

Separate alarm for Fajar Azan

  • action:
    • alias: ‘FajrAzan’
      data:
      entity_id: media_player.family_room_speaker
      media_content_id: Azan e Fajar Live | Madina Live | 2021 | Masjid e Nabawi - YouTube
      media_content_type: video/youtube
      service: media_extractor.play_media
    • data:
      entity_id: media_player.family_room_speaker
      volume_level: ‘0.8’
      service: media_player.volume_set
      alias: Fajr_Adhan
      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 = fajr_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

Even if i execute it manually, Azan is not played either on minor Google Nest Hub. Your help will be really appreciated please.

image

Even the prayer times are not correct based on the Australia/Sydney Timezone.

Alright Alhumdulilah I sorted out. All good.

Usman brother computers love to work is zulu time aka UTC/GMT. so if you convert this time to your local time it will be a correct time.

Asalamu Alaykum,
I was having the same issue (manually triggering works but automatic doesn’t work), so I copied this code but it is still not working, please advise.
JazakAllahu Khairan

alrighty, Alhumdulillah I fixed it. The sensor entity id was wrong in my “Actions” area.

Hi guys, followed the instructions but Adhan times are note accurate… I set time zone and gps coordination accordingly… changed the calculation method to isna
I should have times below as of Jun 27th…
05:00
13:02
17:12
20:54
22:14

Hi, anyone could help, I am trying to setup this for the mosque… I set time zone and gps coordination accordingly… changed the calculation method to isna but prayers times are incorrect

Time display as UTC. someone figured out how to convert to local times?

Assalm u alikum, I hope someone can help me. I am trying to setup the automation script so that it mutes my Samsung soundbar before playing the Adhan on the google home mini (for Duhur, Asr, Magrib and Isha).

I am very new to all this.

# Automation for 5 times Azan
# Automation for Zuhur, Asr, Magrib, and Isha
- action:
service: media_player.volume_mute
  - data:
      entity_id: media_player.home_theater_speaker
      is_volume_muted: true

  - alias: 'Azan'
    data:
      entity_id: media_player.living_room_speaker
      media_content_id: https://www.islamcan.com/audio/adhan/azan1.mp3
      media_content_type: audio/mp3

    service: media_extractor.play_media
  - data:
      entity_id: media_player.living_room_speaker
      volume_level: '0.6'
    service: media_player.volume_set

#Turning on the input boolean to trigger the Google Homes to start playing the Adhan
  - service: input_boolean.turn_on
    entity_id: input_boolean.Adhan
#The delay is based on how long the actual Adhan audio is, for this Adhan, it is just around 2 minutes and 14 seconds
  - delay: '00:02:14'

  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")) +2400 }}'
    - 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")) }}'

- service: media_player.volume_mute
    data:
      entity_id: media_player.home_theater_speaker
      is_volume_muted: false

#Seperate Automation for Fajr 
- action:
  - alias: 'Azan'
    data:
      entity_id: media_player.living_room_speaker
      media_content_id: https://download.tvquran.com/download/TvQuran.com__Athan/TvQuran.com__01.athan.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.living_room_speaker
      volume_level: '0.4'
    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")) }}'


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

I am getting the following parse error.

YAMLException: end of the stream or a document separator is expected at line 4, column 1:
    service: media_player.volume_mute
    ^

Could some one please help.

Jazzakallah

Update

  1. I am based in Sydney Australia.

  2. Hardware: Using VM through Virtualbox and following the instructions on
    Windows - Home Assistant.

  3. Windows PC is always running

  4. Integrated Google Home Mini successfully.

  5. Followed the instructions (installing file editor, updating configuration.yaml and automation.yaml as advised in this article)

Configuration.yaml

homeassistant:
  latitude: -33.907028
  longitude: 151.022690
  unit_system: metric
  time_zone: Australia/Sydney
  
default_config:
discovery:
media_extractor:
sun:

# Islamic prayer times integration
islamic_prayer_times:
    calculation_method: karachi

# 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

automations.yaml

# Automation for 4 times Azan
- action:
  - alias: ''
    data:
      entity_id: media_player.dining_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.dining_room_speaker
      volume_level: '0.4'
    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: ''
    data:
      entity_id: media_player.dining_room_speakerr
      media_content_id: https://www.islamcan.com/audio/adhan/azan3.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.dining_room_speaker
      volume_level: '0.4'
    service: media_player.volume_set
  alias: Adhan
  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")) }}'
- alias: Restart HA
  trigger: 
    platform: time
    at: "02:00:00"  
  action:
    - service: homeassistant.restart

Results / Outcome

  1. Automations does not work, as per the states in developer tool, the did not trigger, snip is attached. One Observation is that the name of YAML file for automation in HA is named as automations.yaml


    snip of entities states in developer tools

  1. Dashboard widget looks like this, although the timings of Adhan are not as per my timezone. Please advise how can I show the Adhan timings as per my timezone?

Looking forward hearing from you.
JazzahAllah

Salam @msahar , really appreciate your effort in setting adhan automation. I have been following the thread and found myself bit lost after an integration of Islamic Prayer Time was introduced in Home Assistant.

Is it possible to have specific instructions to configure and automate with Islamic Prayer Time. You probably have already done that but wanted to segregate it from current topic.

JazzakAllah.
Mohsin