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

hi may i know where can i get the “ID” from?

The value of the automation’s id option can be whatever you want, as long as it’s different from any other automation.

Did you have found any solution? I am looking a solution to see on an separate sensor the next Prayer TIme.

i have now problem with fetching data and i think something breaks now with REST api. The sensors says unknown now. By me nothing was changed. What can be the problem?

@Himdola Still working fine for me.
@starnetworks FYI also interesting for you

See Diyanet Ezan in Home Assistant which I updated to reflect the latest changes.

For the next prayer sensor:

- platform: template

    sensors:

      next_prayer:

        friendly_name: Next Prayer

        value_template: >-

          {% set state = states('sensor.time') %} {% if '00:00' <= state <

          states('sensor.imsak') %} {{ states('sensor.imsak') }}  {% elif

          states('sensor.imsak') <= state < states('sensor.gunes') %} {{

          states('sensor.gunes') }}  {% elif states('sensor.gunes') <= state <

          states('sensor.ogle') %} {{ states('sensor.ogle') }}  {% elif

          states('sensor.ogle') <= state < states('sensor.ikindi') %} {{

          states('sensor.ikindi') }}  {% elif states('sensor.ikindi') <= state <

          states('sensor.aksam') %} {{ states('sensor.aksam') }}  {% elif

          states('sensor.aksam') <= state < states('sensor.yatsi') %} {{

          states('sensor.yatsi') }}  {% elif states('sensor.yatsi') <= state <

          '23:59' %} {{ states('sensor.imsak') }}  {% endif %}

Hi Salih, the code only generates eg. sensor.imsak but not sensor.imsak.vakti
Am I missing something?
@Salerg

rest:
  method: GET
  scan_interval: 172800
  resource: "https://ezanvakti.herokuapp.com/vakitler/11421"
  sensor:
    - name: Imsak
      value_template: >-
        {% for entry in value_json %} {% if entry.MiladiTarihKisa ==
        now().strftime('%d.%m.%Y') %} {{ entry.Imsak }} {% endif %} {% endfor %}
    - name: Ogle
      value_template: >-
        {% for entry in value_json %} {% if entry.MiladiTarihKisa ==
        now().strftime('%d.%m.%Y') %} {{ entry.Ogle }} {% endif %} {% endfor %}
    - name: Ikindi
      value_template: >-
        {% for entry in value_json %} {% if entry.MiladiTarihKisa ==
        now().strftime('%d.%m.%Y') %} {{ entry.Ikindi }} {% endif %} {% endfor
        %}
    - name: Aksam
      value_template: >-
        {% for entry in value_json %} {% if entry.MiladiTarihKisa ==
        now().strftime('%d.%m.%Y') %} {{ entry.Aksam }} {% endif %} {% endfor %}
    - name: Yatsi
      value_template: >-
        {% for entry in value_json %} {% if entry.MiladiTarihKisa ==
        now().strftime('%d.%m.%Y') %} {{ entry.Yatsi }} {% endif %} {% endfor %}
    - name: hicri
      value_template: >-
        {% for entry in value_json %} {% if entry.MiladiTarihKisa ==
        now().strftime('%d.%m.%Y') %} {{ entry.HicriTarihUzun }} {% endif %} {%
        endfor %}
    - name: Gunes
      value_template: >-
        {% for entry in value_json %} {% if entry.MiladiTarihKisa ==
        now().strftime('%d.%m.%Y') %} {{ entry.Gunes }} {% endif %} {% endfor %}

@Salerg also it does not create

entity: input_boolean.disableprayer

I got this error on my logs and state is unknown with the DIyanet Prayer TIme api.

Logger: homeassistant.components.rest.sensor
Source: components/rest/sensor.py:170
Integration: RESTful (documentation, issues)
First occurred: April 18, 2023 at 10:59:11 PM (3 occurrences)
Last logged: 12:59:11 PM
Empty reply found when expecting JSON data

AND

 Logger: homeassistant.components.rest.data
Source: components/rest/data.py:85
Integration: RESTful (documentation, issues)
First occurred: April 18, 2023 at 10:59:11 PM (3 occurrences)
Last logged: 12:59:11 PM
Error fetching data: http://localhost:1453/api/dailyPrayerTimes/12345 failed with All connection attempts failed

@Himdola

After one month of trying to figure out how to get the times correct, I finally figured it all out today :confused:

Just remove the current addon and anything else you have with it and add the following to configuration.yaml (dont forget to change the number to your city)

rest:
  method: GET
  scan_interval: 172800
  resource: "https://ezanvakti.herokuapp.com/vakitler/11421"
  sensor:
    - name: Imsak
      device_class: timestamp
      value_template: "{{ today_at(value_json|selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y'))|map(attribute='Imsak')|first) }}"
    - name: Ogle
      device_class: timestamp
      value_template: "{{ today_at(value_json|selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y'))|map(attribute='Ogle')|first) }}"
    - name: Ikindi
      device_class: timestamp
      value_template: "{{ today_at(value_json|selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y'))|map(attribute='Ikindi')|first) }}"
    - name: Aksam
      device_class: timestamp
      value_template: "{{ today_at(value_json|selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y'))|map(attribute='Aksam')|first) }}"
    - name: Yatsi
      device_class: timestamp
      value_template: "{{ today_at(value_json|selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y'))|map(attribute='Yatsi')|first) }}"

template:
  - binary_sensor:
      - name: Imsak is now
        state: "{{ as_datetime(states('sensor.imsak')).strftime('%H:%M') == states('sensor.time') }}"   
      - name: Ogle is now
        state: "{{ as_datetime(states('sensor.ogle')).strftime('%H:%M') == states('sensor.time') }}"
      - name: Ikindi is now
        state: "{{ as_datetime(states('sensor.ikindi')).strftime('%H:%M') == states('sensor.time') }}"
      - name: Aksam is now
        state: "{{ as_datetime(states('sensor.aksam')).strftime('%H:%M') == states('sensor.time') }}"
      - name: Yatsi is now
        state: "{{ as_datetime(states('sensor.yatsi')).strftime('%H:%M') == states('sensor.time') }}"

The binary_sensor.imsak_is_now will show “On” when the time is correct and “Off” when it is not.
But what I have done is created 5 different automations using each ezan entity to play a different ezan.

alias: Ezan - Sabah
description: ""
trigger:
  - platform: time
    at: sensor.imsak
condition: []
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.6
    target:
      entity_id: media_player.living_room
  - service: media_player.play_media
    target:
      entity_id: media_player.living_room
    data:
      media_content_id: >-
        media-source://media_source/local/Sabah Ezanı (Saba Makamı) - Nurettin
        Okumuş.mp3
      media_content_type: audio/mpeg
    metadata:
      title: Sabah Ezanı (Saba Makamı) - Nurettin Okumuş.mp3
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://media_source
mode: single

@Zotech I have answered you already. But anyways, including you here
@Himdola As Zotech mentioned.

I have updated the website to be complete now. Additionally I share my complete automation with comments in the code. See the website: https://ergezen.nl/Diyanet-Ezan-in-Home-Assistant-7186fe119843435d802ca3c0b71f1c5f

Specifically sharing the link, as it is rather long. No problem to share code snippets here and or further discuss.

Also shared the UI element I created to display nicely the relevant prayer times.
image

1 Like

That is one intense automation code, well done!

Does your source web site has all the times for USA, state and cities?

I see ABD (USA) is included. These are diyanet times only. So most likely only relevant if you are Turkish…

Thank you. I am not Turkish but I was interested in Imsak notification and would love to implement it in my setup from the Islamic prayer times integration.

I have been trying to scrape my local website for timings for the past few weeks and just cant get my head around how to get it to work. I have managed to scrape the time which shows as 4:57 am but can not get it to format as a timestamp. This is my code:

scrape:
  - resource: https://www.noorulislam.org.uk
    sensor:
      - name: "Fajr_Prayer_Time"
        select: "tr"
        index: 2
        value_template: '{{ value.split("am")[0] }}'

The value template for this is:

    value_template: >
      {{ strptime(states('sensor.fajr_prayer_time'), '%I:%M %p').strftime('%H:%M') }}

This turned out to be a bit messy, as the HTML in that table is a long way from standards-compliant. The data is in the third <tr> element, but the mess of <td> and <th> tags make it impossible to scrape any further.

Scraping that <tr> element gives this (for today):

Begins4:07 am5:42 am1:04 pm5:58 pm8:16 pm9:29 pm

So we’ll configure our sensors to pull out those times, with the second time being sunrise. The regex pattern is looking for an optional 1 (in e.g. 10:15 am) followed by digit:digit digit then am or pm. It should find all six as a list, so we just need to tell each sensor which one it’s using.

scrape:
  - resource: https://www.noorulislam.org.uk
    sensor:
      - name: "Fajr Prayer Time"
        select: "tr"
        index: 2
        value_template: '{{ today_at(strptime((value|regex_findall("(1?\d:\d\d\ [ap]m)"))[0], "%I:%M %p").strftime("%H:%M")) }}'
        device_class: timestamp

      - name: "Zuhr Prayer Time"
        select: "tr"
        index: 2
        value_template: '{{ today_at(strptime((value|regex_findall("(1?\d:\d\d\ [ap]m)"))[2], "%I:%M %p").strftime("%H:%M")) }}'
        device_class: timestamp

      - name: "Asr Prayer Time"
        select: "tr"
        index: 2
        value_template: '{{ today_at(strptime((value|regex_findall("(1?\d:\d\d\ [ap]m)"))[3], "%I:%M %p").strftime("%H:%M")) }}'
        device_class: timestamp

      - name: "Maghrib Prayer Time"
        select: "tr"
        index: 2
        value_template: '{{ today_at(strptime((value|regex_findall("(1?\d:\d\d\ [ap]m)"))[4], "%I:%M %p").strftime("%H:%M")) }}'
        device_class: timestamp

      - name: "Isha Prayer Time"
        select: "tr"
        index: 2
        value_template: '{{ today_at(strptime((value|regex_findall("(1?\d:\d\d\ [ap]m)"))[5], "%I:%M %p").strftime("%H:%M")) }}'
        device_class: timestamp

This assumes sunrise is always in between Fajr and Zuhr. If that’s not the case, it gets a bit more difficult but not impossible.

Also, you can create these sensors via the UI:

Settings / Devices & Services / Integrations (at the top) / Add integration / Scrape

Brother you dont understand how much i appreciate your post. I’ve been trying to figure this out for weeks losing my sleep. Thank you so much!

I managed to get the timings separated by using this code which looked for the td tables, however the code you provided worked instantly and can not thank you enough.

scrape:
  - resource: https://www.noorulislam.org.uk
    sensor:
      - name: "Fajr_Prayer_Time"
        select: "td"
        index: 1
        value_template: "{{ strptime(states('sensor.fajr_prayer_time'), '%H:%M %p').strftime('%H:%M %p') }}"
1 Like


finally done! :smiley:

Nice!

Where do you get the icons from?