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

@123 I also want to say that your help is always appreciated, here and everywhere else. I always find your answers clear, simple, and to the point.

9 out of 10 times when I google a problem your name comes up with the best answer!

I’m sorry, I made a small mistake:

in configuration.yaml:

 - platform: template
    sensors:
     imsak_vakti:
      friendly_name: "İmsak Vakti"
      value_template: "{{ states('sensor.imsak') == states('sensor.time') }}"

instead of states(‘sensor.aksam’).

I’ve changed this in my original post for future reference.

1 Like

I have a csv file with whole year timings for my local mosque is it possible to implement this into the timings?

Thank you so much for the code and perfect explanation. I had been using a windows 97 software for 10 years now for Azaan. Finally switched over that task to my HA. MANY MANY THANKS!

If your mosque posts the timings on a website every day. You can use the scrape function to create a sensor via home assistant or node-red. set it to scrape that value every night and then implement the method as described in this post. Just make sure that if the value you scrape is not in iso format you make it so.

Hi,
Check this video, it is in Arabic, but the steps are very clear.

https://www.youtube.com/watch?v=kl7kYHVtDRs

Salam Brothers,
After recants updates to system my adahna cant be triggered automatically , i can still trigger it manually through Home assistance, below are the error logs. your help is much appreciated brothers.

Logger: homeassistant.components.template.trigger
Source: components/template/trigger.py:73
Integration: Template (documentation, issues)
First occurred: 16:49:18 (5 occurrences)
Last logged: 16:49:18

Error evaluating ‘template’ trigger for ‘Adhan’: ValueError: Template error: strptime got invalid input ‘2022-06-15T19:30:00+00:00’ when rendering 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”)) }}’ but no default was specified
Error evaluating ‘template’ trigger for ‘Adhan’: ValueError: Template error: strptime got invalid input ‘2022-06-16T01:57: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
Error evaluating ‘template’ trigger for ‘Adhan’: ValueError: Template error: strptime got invalid input ‘2022-06-16T04:36:00+00:00’ when rendering 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”)) }}’ but no default was specified
Error evaluating ‘template’ trigger for ‘Adhan’: ValueError: Template error: strptime got invalid input ‘2022-06-16T06:54:00+00:00’ when rendering 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”)) }}’ but no default was specified
Error evaluating ‘template’ trigger for ‘Adhan’: ValueError: Template error: strptime got invalid input ‘2022-06-16T08:19:00+00:00’ when rendering 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”)) }}’ but no default was specified

Logger: homeassistant.helpers.event
Source: helpers/template.py:411
First occurred: 16:49:00 (5 occurrences)
Last logged: 16:49:00

Error while processing template: 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”)) }}")
Error while processing template: 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”)) }}")
Error while processing template: 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”)) }}")
Error while processing template: 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”)) }}")
Error while processing template: 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”)) }}")
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 1546, in strptime
return datetime.strptime(string, fmt)
File “/usr/local/lib/python3.9/_strptime.py”, line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File “/usr/local/lib/python3.9/_strptime.py”, line 352, in _strptime
raise ValueError(“unconverted data remains: %s” %
ValueError: unconverted data remains: +00:00

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 409, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 1842, in _render_with_context
return template.render(**kwargs)
File “/usr/local/lib/python3.9/site-packages/jinja2/environment.py”, line 1301, in render
self.environment.handle_exception()
File “/usr/local/lib/python3.9/site-packages/jinja2/environment.py”, line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File “”, line 1, in top-level template code
File “/usr/local/lib/python3.9/site-packages/jinja2/sandbox.py”, line 393, in call
return __context.call(__obj, *args, **kwargs)
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 1549, in strptime
raise_no_default(“strptime”, string)
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 1331, in raise_no_default
raise ValueError(
ValueError: Template error: strptime got invalid input ‘2022-06-15T19:30:00+00:00’ when rendering 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”)) }}’ but no default was specified

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 525, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 411, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: strptime got invalid input ‘2022-06-15T19:30:00+00:00’ when rendering 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”)) }}’ but no default was specified

Logger: homeassistant.components.template.trigger
Source: components/template/trigger.py:60
Integration: Template (documentation, issues)
First occurred: 16:49:00 (5 occurrences)
Last logged: 16:49:00

Error initializing ‘template’ trigger for ‘Adhan’: ValueError: Template error: strptime got invalid input ‘2022-06-15T19:30:00+00:00’ when rendering 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”)) }}’ but no default was specified
Error initializing ‘template’ trigger for ‘Adhan’: ValueError: Template error: strptime got invalid input ‘2022-06-16T01:57: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
Error initializing ‘template’ trigger for ‘Adhan’: ValueError: Template error: strptime got invalid input ‘2022-06-16T04:36:00+00:00’ when rendering 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”)) }}’ but no default was specified
Error initializing ‘template’ trigger for ‘Adhan’: ValueError: Template error: strptime got invalid input ‘2022-06-16T06:54:00+00:00’ when rendering 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”)) }}’ but no default was specified
Error initializing ‘template’ trigger for ‘Adhan’: ValueError: Template error: strptime got invalid input ‘2022-06-16T08:19:00+00:00’ when rendering 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”)) }}’ but no default was specified

@msahar can you please tell me what the problem and how can i fix it

Same issue here. Ending up doing a roll back on the update to get it working again.

My guess is it’s something with the time parsing function changed with the latest update, thus breaking all the triggers.

Salam did it end up working ? And to what version you rolled back and how please

To what version have you rolled back plz.

Salam alikom, did anybody figure out a way to add a countdown to the next prayer?

I would like to have this too

The sensor’s time format changed over a year ago and for a good reason. Its format is compatible for use with a Time Trigger (no template is needed). I explained this in July 2021 and posted an example:

With this new format, what if we wanted to set up 10 minute reminders/alarms. Would we be able to do

sensor.fajr_prayer - 600

Or is there a different way to do it?

Currently, the Time Trigger doesn’t support an offset value so you must use a Template Trigger.

Here’s an example of a Template Trigger that triggers 10 minutes (600 seconds) before any of the five prayer times.

trigger:
  - platform: template
    value_template: >
      {{ now().timestamp() | int(0) + 600 in expand('sensor.fajr_prayer', 'sensor.dhuhr_prayer', 
        'sensor.asr_prayer', 'sensor.isha_prayer', 'sensor.maghrib_prayer')
        | map(attribute='state') | map('as_timestamp') | list }}

Looks like the prayer times API is down. After the 1AM restart, it’s showing all athan sensors unavailable. And Prayer Times integration is showing an error fetching a response from the API. Anyone else getting this?

@123 . Thank you brother for your assistance in this thread. I would be grateful if you can repost the revised process to automate adthan and make it sticky because this thread is long and a lot of information that confuse the newbies like me. Thank you again.

Something like this would be very helpful to glance at wall dashboards. maybe using mushroom cards.
something like from praywatch app on IOS
image

Guys , can someone post the updated Configuration Files along with the Automation files that worked ?

I can manually trigger the automation and the AZAN works, but its not being triggered by any sensors. Also the Groups.yaml is missing in the installation

My Configuration File

homeassistant:
  latitude: -37.840935
  longitude: 144.946457
  unit_system: metric
  time_zone: Australia/Melbourne
  
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

MY Automation File

- id: '1517693010922'
  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"))
      }}'
  - 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"))
      }}'
  condition: []
  action:
  - alias: ''
    data:
      entity_id: media_player.living_room_speaker
      media_content_id: http://www.shianeali.com/dua/Azan/1%20-%20Abathar%20Al%20Halawaji%20-%20Azan%20(Call%20For%20Prayer).mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      volume_level: 0.4
    service: media_player.volume_set
    target:
      entity_id: media_player.living_room_speaker
  mode: single
- id: '1517693034922'
  alias: Fajar Azaan
  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"))
      }}'
  condition: []
  action:
  - alias: Fajar
    data:
      entity_id: media_player.living_room_speaker
      media_content_id: https://www.islamcan.com/audio/adhan/azan3.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      volume_level: 0.4
    service: media_player.volume_set
    target:
      area_id: living_room
      device_id: 83982c1f80fda986dd93cfbee8f335d7
      entity_id: media_player.living_room_speaker
  mode: single
- alias: Restart HA
  trigger:
    platform: time
    at: 02:00:00
  action:
  - service: homeassistant.restart```