Automate Islamic Adhan (also called Azan or Azzan) or other prayer calls - Updated 3_24_2023 for Node-RED

* Template warning: 'strptime' got invalid input '2022-04-21T18:20:00+00:00' when rendering 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")) }}' but no default was specified. Currently 'strptime' will return '2022-04-21T18:20:00+00:00', however this template will fail to render in Home Assistant core 2022.1

I keep getting this error. Does anyone know how to resolve it or what can I use to replace ‘strptime’? If someone could point in the right direction, I would appreciate it.

I found a solution from another post. I am going to link his answer here. Azan or Adhan automation Islamic Prayer Times - #5 by 123 Thanks @123

Hello, with latest ha version the get template has error.
Do you have a workaround please

My adhan automation stopped working after updating to latest version

Dear all my brothers & sisters,

After the recent update on my HA, my Adhan suddenly stop working, upon searching the error in log, it’s likely due to the time template.

For those who have similar issues, please refer below ‘before’ and ‘after’ changes in my template.

BEFORE

- platform: template
  sensors:
    subuh_selangor:
      friendly_name: 'Subuh'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Fajr"] | timestamp_custom("%H:%M") }}'
    zuhur_selangor:
      friendly_name: 'Zuhur'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Dhuhr"] | timestamp_custom("%H:%M") }}'
    asar_selangor:
      friendly_name: 'Asar'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Asr"] | timestamp_custom("%H:%M") }}'
    maghrib_selangor:
      friendly_name: 'Maghrib'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Maghrib"] | timestamp_custom("%H:%M") }}'
    isyak_selangor:
      friendly_name: 'Isyak'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Isha"] | timestamp_custom("%H:%M") }}'

AFTER

- platform: template
  sensors:
    subuh_selangor:
      friendly_name: 'Subuh'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Fajr"] }}'
    zuhur_selangor:
      friendly_name: 'Zuhur'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Dhuhr"] }}'
    asar_selangor:
      friendly_name: 'Asar'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Asr"] }}'
    maghrib_selangor:
      friendly_name: 'Maghrib'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Maghrib"] }}'
    isyak_selangor:
      friendly_name: 'Isyak'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Isha"] }}'

MY WORKABLE FULL CONFIGURATION

#Time Data
- platform: time_date
  display_options:
    - 'time'
    - 'date'
    - 'date_time'
    - 'time_date'
    - 'time_utc'
    - 'beat'

#selangor
- platform: rest
  name: "Prayer selangor"
  json_attributes:
    - data
  resource: "http://api.aladhan.com/v1/timings?latitude=3.333333&longitude=333.33333&method=3"
  value_template: '{{ value_json["data"]["meta"]["method"]["name"].title() }}'
  scan_interval: 86400

- platform: template
  sensors:
    subuh_selangor:
      friendly_name: 'Subuh'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Fajr"] }}'
    zuhur_selangor:
      friendly_name: 'Zuhur'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Dhuhr"] }}'
    asar_selangor:
      friendly_name: 'Asar'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Asr"] }}'
    maghrib_selangor:
      friendly_name: 'Maghrib'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Maghrib"] }}'
    isyak_selangor:
      friendly_name: 'Isyak'
      value_template: '{{ states.sensor.prayer_selangor.attributes.data.timings["Isha"] }}'

In summary what i did, is to remove the ‘timestamp_custom’ line from the template. Hope it helps.

If you want to keep the timestamp_custom filter, this is what it should look like now that de default parameter is a required parameter:

timestamp_custom("%H:%M", default = 0)

Updating Templates with the new default values in 2021.10.x

Edwin

i tried your above method but got all my time 0.
tttttt

That would normally happen if the value before is undefined. Wat exactly is displayed if you remove ithe filter entirely?

Hello, I am using version 2022.7.4, I have installed islamic prayer times, all is well, but the adhan won’t go off automatically. I have put my configuration files below for your idea. The scripts below used to work on an extremely old version of HA that I was running for the past few years. Since my old raspberry died, I’ve put this on a vmware esxi server for more stability. Please let me know if you can see what am I missing.

config/configuration.yaml

homeassistant:
latitude: 43.21824
longitude: -79.7875487
elevation: 106
unit_system: metric
time_zone: America/Toronto

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: isna
    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

config/automation.yaml

Fajr Adhan

################################################################################

  • alias: Fujr Adhan
    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”)) -3600 }}’ # Activate this in November right after the time change

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”)) +3600 }}’ # Activate this in March right after the time change

  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")) }}'       # Always the Normal

action:
- service: media_player.volume_set
data:
entity_id:
- media_player.family_room_speaker
- media_player.master_bedroom_speaker
volume_level: ‘0.40’

# Fujr Adhan
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.master_bedroom_speaker
    media_content_id: http://192.168.1.160/aud/adhan/adhan_fajr_makkah.mp3
    #media_content_id: http://192.168.1.160/aud/adhan/adhan_al-aqsa.mp3
    media_content_type: audio/mp3
- delay: '00:03:50'
#- delay: '00:04:15'

# Adhan Dua
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.master_bedroom_speaker
    media_content_id: http://192.168.1.160/aud/dua/dua-e-adhan.mp3
    media_content_type: audio/mp3
- delay: '00:00:19'

#- service: media_player.volume_set
#  data:
#    entity_id:
#        - media_player.family_room_speaker
#        - media_player.guest_room_wifi
#    volume_level: '0.29'

# 96 Surah Al'Alaq
#- service: media_extractor.play_media
#  data:
#    entity_id:
#        - media_player.family_room_speaker
#        - media_player.guest_room_wifi
#    media_content_id: http://192.168.1.160/aud/surah/quran_96.mp3
#    media_content_type: audio/mp3

#- delay: '00:02:46'

# 109 Surah Al'Kafirun
#- service: media_extractor.play_media
#  data:
#    entity_id:
#        - media_player.family_room_speaker
#        - media_player.guest_room_wifi
#    media_content_id: http://192.168.1.160/aud/surah/quran_109.mp3
#    media_content_type: audio/mp3

#- delay: '00:01:19'

# 110 Surah An'Nasr
#- service: media_extractor.play_media
#  data:
#    entity_id:
#        - media_player.family_room_speaker
#        - media_player.guest_room_wifi
#    media_content_id: http://192.168.1.160/aud/surah/quran_110.mp3
#    media_content_type: audio/mp3

#- delay: '00:00:57'

# 01 Surah Al'Fatiha
- service: media_extractor.play_media
  data:
    entity_id:
      - media_player.family_room_speaker
      - media_player.guest_room_wifi
      - media_player.master_bedroom_speaker
    media_content_id: http://192.168.1.160/aud/surah/quran_01.mp3
    media_content_type: audio/mp3
- delay: '00:01:28'

# 112 Surah Al'Ikhlas
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
        - media_player.master_bedroom_speaker
    media_content_id: http://192.168.1.160/aud/surah/quran_112.mp3
    media_content_type: audio/mp3
- delay: '00:00:41'

# 113 Surah Al'Falaq
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
        - media_player.master_bedroom_speaker
    media_content_id: http://192.168.1.160/aud/surah/quran_113.mp3
    media_content_type: audio/mp3
- delay: '00:00:56'

# 114 Surah An'Nas
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
        - media_player.master_bedroom_speaker
    media_content_id: http://192.168.1.160/aud/surah/quran_114.mp3
    media_content_type: audio/mp3
- delay: '00:01:17'

# Ayat'ul Kursi
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
        - media_player.master_bedroom_speaker
    media_content_id: http://192.168.1.160/aud/ayah/ayat_ul-kursi.mp3
    media_content_type: audio/mp3

Dhuhr Adhan

################################################################################

  • alias: Dhuhr Adhan
    id: ‘1517693010923’
    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”)) -3600 }}’ # Activate this in November right after the time change

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”)) +3600 }}’ # Activate this in March right after the time change

  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")) }}'       # Always the Normal

action:
- service: media_player.volume_set
data:
entity_id:
- media_player.family_room_speaker
- media_player.guest_room_wifi
volume_level: ‘0.5’

- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    #media_content_id: http://192.168.1.160/aud/adhan/adhan_makkah.mp3
    media_content_id: http://192.168.1.160/aud/adhan/adhan_al-aqsa.mp3
    media_content_type: audio/mp3
#- delay: '00:03:22'
- delay: '00:04:15'

- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/dua/dua-e-adhan.mp3
    media_content_type: audio/mp3
- delay: '00:00:19'

- service: media_extractor.play_media

data:

entity_id: media_player.family_room_speaker_2

media_content_id: http://192.168.1.160/aud/surah/quran_36.mp3

media_content_type: audio/mp3

# 01 Surah Al'Fatiha
- service: media_extractor.play_media
  data:
    entity_id:
      - media_player.family_room_speaker
      - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_01.mp3
    media_content_type: audio/mp3
- delay: '00:01:28'

# 112 Surah Al'Ikhlas
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_112.mp3
    media_content_type: audio/mp3
- delay: '00:00:41'

# 113 Surah Al'Falaq
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_113.mp3
    media_content_type: audio/mp3

- delay: '00:00:56'

# 114 Surah An'Nas
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_114.mp3
    media_content_type: audio/mp3
- delay: '00:01:17'

# Ayat'ul Kursi
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/ayah/ayat_ul-kursi.mp3
    media_content_type: audio/mp3

Asr Adhan

################################################################################

  • alias: Asr Adhan
    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_asr”), “%Y-%m-%dT%H:%M:%S”)) -3600 }}’ # Activate this in November right after the time change

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”)) +3600 }}’ # Activate this in March right after the time change

  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")) }}'       # Always the Normal

action:
- service: media_player.volume_set
data:
entity_id:
- media_player.family_room_speaker
- media_player.guest_room_wifi
volume_level: ‘0.5’

- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    #media_content_id: http://192.168.1.160/aud/adhan/adhan_makkah.mp3
    media_content_id: http://192.168.1.160/aud/adhan/adhan_al-aqsa.mp3
    media_content_type: audio/mp3
#- delay: '00:03:22'
- delay: '00:04:15'

- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/dua/dua-e-adhan.mp3
    media_content_type: audio/mp3
- delay: '00:00:19'

# 01 Surah Al'Fatiha
- service: media_extractor.play_media
  data:
    entity_id:
      - media_player.family_room_speaker
      - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_01.mp3
    media_content_type: audio/mp3
- delay: '00:01:28'

# 112 Surah Al'Ikhlas
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_112.mp3
    media_content_type: audio/mp3
- delay: '00:00:41'

# 113 Surah Al'Falaq
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_113.mp3
    media_content_type: audio/mp3
- delay: '00:00:56'

# 114 Surah An'Nas
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_114.mp3
    media_content_type: audio/mp3
- delay: '00:01:17'

# Ayat'ul Kursi
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/ayah/ayat_ul-kursi.mp3
    media_content_type: audio/mp3

Maghrib Adhan

################################################################################

  • alias: Maghrib Adhan
    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_maghrib”), “%Y-%m-%dT%H:%M:%S”)) -3600 }}’ # Activate this in November right after the time change

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”)) +3600 }}’ # Activate this in March right after the time change

  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")) }}'       # Always the Normal

action:
- service: media_player.volume_set
data:
entity_id:
- media_player.family_room_speaker
- media_player.guest_room_wifi
volume_level: ‘1.0’

- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    #media_content_id: http://192.168.1.160/aud/adhan/bahrain_tv_athan_akmagraib.mp3
    media_content_id: http://192.168.1.160/aud/adhan/adhan_al-maghrib_madinah.mp3
    media_content_type: audio/mp3
- delay: '00:03:37' # adhan_al-maghrib_madinah

- service: media_player.volume_set
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    volume_level: '0.5'

- service: media_extractor.play_media
  data:
    entity_id: media_player.family_room_speaker
    media_content_id: http://192.168.1.160/aud/dua/dua-e-adhan.mp3
    media_content_type: audio/mp3
- delay: '00:00:19'

# 01 Surah Al'Fatiha
- service: media_extractor.play_media
  data:
    entity_id:
      - media_player.family_room_speaker
      - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_01.mp3
    media_content_type: audio/mp3
- delay: '00:01:28'

# 112 Surah Al'Ikhlas
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_112.mp3
    media_content_type: audio/mp3
- delay: '00:00:41'

# 113 Surah Al'Falaq
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_113.mp3
    media_content_type: audio/mp3
- delay: '00:00:56'

# 114 Surah An'Nas
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_114.mp3
    media_content_type: audio/mp3

- delay: '00:01:17'

# Ayat'ul Kursi
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/ayah/ayat_ul-kursi.mp3
    media_content_type: audio/mp3

Isha Adhan

################################################################################

  • alias: Isha Adhan
    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_isha”), “%Y-%m-%dT%H:%M:%S”)) -3600 }}’ # Activate this in November right after the time change

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”)) +3600 }}’ # Activate this in March right after the time change

  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")) }}'       # Always the Normal

action:
- service: media_player.volume_set
data:
entity_id:
- media_player.family_room_speaker
- media_player.guest_room_wifi
volume_level: ‘0.5’

- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    #media_content_id: http://192.168.1.160/aud/adhan/adhan_makkah.mp3
    media_content_id: http://192.168.1.160/aud/adhan/adhan_al-aqsa.mp3
    media_content_type: audio/mp3
#- delay: '00:03:22'
- delay: '00:04:15'

- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/dua/dua-e-adhan.mp3
    media_content_type: audio/mp3
- delay: '00:00:19'

# 01 Surah Al'Fatiha
- service: media_extractor.play_media
  data:
    entity_id:
      - media_player.family_room_speaker
      - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_01.mp3
    media_content_type: audio/mp3
- delay: '00:01:28'

# 112 Surah Al'Ikhlas
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_112.mp3
    media_content_type: audio/mp3
- delay: '00:00:41'

# 113 Surah Al'Falaq
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_113.mp3
    media_content_type: audio/mp3
- delay: '00:00:56'

# 114 Surah An'Nas
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/surah/quran_114.mp3
    media_content_type: audio/mp3
- delay: '00:01:17'

# Ayat'ul Kursi
- service: media_extractor.play_media
  data:
    entity_id:
        - media_player.family_room_speaker
        - media_player.guest_room_wifi
    media_content_id: http://192.168.1.160/aud/ayah/ayat_ul-kursi.mp3
    media_content_type: audio/mp3

This is what I have on my dash board: (Please ignore the lines that are appearing as heading (bolded and enlarged) as they have a # for comment in the code)

Please Help! :confused:

Hi @Edwin_D, please Sir, when you have a chance, can you help me out? :slight_smile:

Hey! I’m sharing my configuration here so you may adopt it. First of all, you have go to https://api.aladhan.com and choose whatever method you’d like to. Here I am using Hanafi method so I chose “1”. Secondly, you have to find longitude and latitude of your home address and then modify it in the link I shared here.

Paste these codes into your configuration.yaml file:

  - platform: rest
    name: "Prayer Times"
    json_attributes:
      - data
    resource: "http://api.aladhan.com/v1/timings?latitude=40.0000000&longitude=-23.00000&method=2&school=1"
    value_template: '{{ value_json["data"]["meta"]["method"]["name"].title() }}'
    scan_interval: 3600
  - platform: template
    sensors:
      fajr_prayer_time:
        friendly_name: "Fajr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Fajr']).strftime("%I:%M %p") }}
      dhuhr_prayer_time:
        friendly_name: "Dhuhr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Dhuhr']).strftime("%I:%M %p") }}
      asr_prayer_time:
        friendly_name: "Asr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Asr']).strftime("%I:%M %p") }}
      maghrib_prayer_time:
        friendly_name: "Maghrib Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Maghrib']).strftime("%I:%M %p") }}
      isha_prayer_time:
        friendly_name: "Isha Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Isha']).strftime("%I:%M %p") }}

And add these codes to automation.yaml file:

- id: '1517693010923'
  alias: Adhan
  trigger:
 - platform: template
    value_template: '{% set x = states(''sensor.fajr_prayer_time'') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}'
  - platform: template
    value_template: '{% set x = states(''sensor.dhuhr_prayer_time'') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}'
  - platform: template
    value_template: '{% set x = states(''sensor.asr_prayer_time'') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}'
 - platform: template
    value_template: '{% set x = states(''sensor.isha_prayer_time'') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}'
  - platform: template
    value_template: '{% set x = states(''sensor.isha_prayer_time'') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}'
  condition: []
  action:
  - data:
      volume_level: 0.3
    service: media_player.volume_set
    target:
      entity_id:
      - media_player.master_bedroom_speaker
  - alias: ''
    data:
      entity_id: media_player.master_bedroom_speaker
      media_content_id: https://yourHomeAssistantIP/local/azaan.mp3
      media_content_type: music
    service: media_player.play_media

Hi @chintito4ever , Thank you for your kind help.
I removed everything from my configuration.yaml and added the above you mentioned, like so:

  - platform: rest
    name: "Prayer Times"
    json_attributes:
      - data
    resource: "http://api.aladhan.com/v1/timings?latitude=43.21824&longitude=-79.7875487&method=2&school=1"
    value_template: '{{ value_json["data"]["meta"]["method"]["name"].title() }}'
    scan_interval: 3600

  - platform: template
    sensors:
      fajr_prayer_time:
        friendly_name: "Fajr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Fajr']).strftime("%I:%M %p") }}
      dhuhr_prayer_time:
        friendly_name: "Dhuhr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Dhuhr']).strftime("%I:%M %p") }}
      asr_prayer_time:
        friendly_name: "Asr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Asr']).strftime("%I:%M %p") }}
      maghrib_prayer_time:
        friendly_name: "Maghrib Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Maghrib']).strftime("%I:%M %p") }}
      isha_prayer_time:
        friendly_name: "Isha Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Isha']).strftime("%I:%M %p") }}

I’ve updated latitude/logitude im assuming method=2 means ISNA and I have no idea about school=1.

but when I save and try to restart, I get the following error message:

Logger: homeassistant.components.hassio
Source: components/hassio/__init__.py:682 
Integration: Home Assistant Supervisor (documentation, issues) 
First occurred: 5:38:01 PM (1 occurrences) 
Last logged: 5:38:01 PM

The system cannot restart because the configuration is not valid: Error loading /config/configuration.yaml: The configuration file configuration.yaml does not contain a dictionary

What am I missing?

I suspect there’s something wrong with the code, most probably indentation problem. If you go to Settings page>Logs page you should find a detailed error. It will show exactly which line in your configuration has problem.

yeah, I checked in the logs, this is what I see:

Logger: homeassistant.config
Source: config.py:374 
First occurred: 5:37:46 PM (5 occurrences) 
Last logged: 5:38:01 PM

The configuration file configuration.yaml does not contain a dictionary

not sure which dictionary is it referring to or perhaps something im missing to install?
How about line 6; im not sure if that’s supposed to be there?

ok I resolved that by adding some of the old stuff, now it looks like this:

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: rest
    name: "Prayer Times"
    json_attributes:
      - data
    resource: "http://api.aladhan.com/v1/timings?latitude=43.21824&longitude=-79.7875487&method=2&school=1"
    value_template: '{{ value_json["data"]["meta"]["method"]["name"].title() }}'
    scan_interval: 3600

  - platform: template
    sensors:
      fajr_prayer_time:
        friendly_name: "Fajr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Fajr']).strftime("%I:%M %p") }}
      dhuhr_prayer_time:
        friendly_name: "Dhuhr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Dhuhr']).strftime("%I:%M %p") }}
      asr_prayer_time:
        friendly_name: "Asr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Asr']).strftime("%I:%M %p") }}
      maghrib_prayer_time:
        friendly_name: "Maghrib Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Maghrib']).strftime("%I:%M %p") }}
      isha_prayer_time:
        friendly_name: "Isha Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Isha']).strftime("%I:%M %p") }}
          
# Text to speech
tts:
  - platform: google_translate

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

so the error is gone. Going to wait now and see if the next prayer gets triggered or not. Will update you. Thank you.

1 Like

@chintito4ever , I noticed something odd. and I think it could be in the code. Everything runs well, but the Maghrib prayer, I have to manually trigger for it to run.

This is what I see in the error log:

2022-07-29 06:49:24 WARNING (MainThread) [homeassistant.components.template.trigger] Error initializing 'template' trigger for 'Maghrib Adhan': ValueError: Template error: strptime got invalid input 'unknown' when rendering template '{% set x = states('sensor.mughrib_prayer_time') %} {{ now() >= today_at(strptime(x, "%I:%M %p").time()) }}' but no default was specified
2022-07-29 06:49:24 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{% set x = states('sensor.mughrib_prayer_time') %} {{ now() >= today_at(strptime(x, "%I:%M %p").time()) }}")

How do I troubleshoot the above?

this is the snippet from configuration.yaml for mughrib

- alias: Maghrib Adhan
  id: '1517693010925'
  trigger:
    - platform: template
      value_template: '{% set x = states(''sensor.mughrib_prayer_time'') %} {{ now() >= today_at(strptime(x, "%I:%M %p").time()) }}'
      
  action:
    - service: media_player.volume_set
      data:
        entity_id:
            - media_player.family_room_speaker
            - media_player.master_bedroom_speaker
            - media_player.main_floor_speaker
        volume_level: '1.0'

    - service: media_extractor.play_media
      data:
        entity_id:
            - media_player.family_room_speaker
            - media_player.master_bedroom_speaker
            - media_player.main_floor_speaker
        media_content_id: http://192.168.1.160/aud/adhan/adhan_al-maghrib_madinah.mp3 #media_content_id: http://192.168.1.160/aud/adhan/bahrain_tv_athan_akmagraib.mp3
        media_content_type: audio/mp3
    - delay: '00:03:37' # adhan_al-maghrib_madinah

try changing sensor name from sensor.mughrib_prayer_time to sensor.maghrib_prayer_time.

2 Likes

as @chintito4ever suggested, use sensor.magrib_prayer as indicated in the Islamic Prayer Times entities

Salaam Brothers,

I have the automation working perfectly minus one small thing. The Islamic Prayer Time integration doesn’t have a calculation for the UK, the closest is MWL but it isn’t correct. Is there a way I can correct this without having to change anything constantly.

Thanks

Salaam Brother,

I also want to set up azan automation working my amazon echo, I have currently install Islamic prayer times and alexa media.

can you kindly share your config & auto script.