Home assistant is a great tool to automate your house. As we have recently move to our own apartment I wanted to integrate the muslim prayer times in Home assistant so that I could get automatic reminders when it is time to pray.
Unfortunatly, the official integration for these prayer times does not support Diyanet (Turkey) Ezan times. Additionally, all integrations or API’s that do provide times based on the Diyanet calculation method always seemed to give slightly different times than the ones I get when looking it up on the official website.
<aside> 💡 originally I wrote this guide to scrape the data from the original website. But the diyanet website currently blocks this method. The scrape sensor is therefore not recommended. Furkan Tektas created an API that shows the same exact times as the official diyanet website.
</aside>
<aside> 📧 If you have any questions or issues with the Diyanet Ezan integration in Home Assistant, please feel free to send me an email. My email address can be found on my website. Thank you for your interest in this project!
</aside>
<aside> 🪧 changes: 29-12-2025: Made compatible with new YAML structure HA & updated URL for API
</aside>
For this to work we need to get the diyanet prayer times from: https://ezanvakti.emushaf.net. You will have to change the number in the end of the url (see below) to match your local city. You can find this number via the https://ezanvakti.emushaf.net. Change the country and city. The number in the URL can be used to change the script below:
Configuration.yaml :
rest:
method: GET
scan_interval: 2800
resource: "<https://ezanvakti.emushaf.net/vakitler/13929>"
sensor:
- name: Imsak
value_template: "{{ value_json | selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y')) | map(attribute='Imsak') | first }}"
- name: Gunes
value_template: "{{ value_json | selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y')) | map(attribute='Gunes') | first }}"
- name: Ogle
value_template: "{{ value_json | selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y')) | map(attribute='Ogle') | first }}"
- name: Ikindi
value_template: "{{ value_json | selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y')) | map(attribute='Ikindi') | first }}"
- name: Aksam
value_template: "{{ value_json | selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y')) | map(attribute='Aksam') | first }}"
- name: Yatsi
value_template: "{{ value_json | selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y')) | map(attribute='Yatsi') | first }}"
- name: hicri
value_template: "{{ value_json | selectattr('MiladiTarihKisa','eq',now().strftime('%d.%m.%Y')) | map(attribute='HicriTarihUzun') | first }}"
The scan_interval is set to 48 hours. You do not have to change this as the API shows the times for the complete month.
The above snipped will create a couple of sensors (sensor.imsak etc) that display HH:MM timestamp for each prayer. As the API returns data for the complete month we need to match the day of the month with the data returned from the API. This is done in the value template.
Use below code to check if the data returned by the sensors created in above code matches the current time:
template:
- sensor:
# -------------------------
# Ramadan
# -------------------------
- name: "Ramadan"
unique_id: ramadan
state: "{{ 'Ramazan' in states('sensor.hicri') }}"
# -------------------------
# Next Prayer (time string)
# -------------------------
- name: "Next Prayer"
unique_id: next_prayer
state: >
{% set t = now().strftime('%H:%M') %}
{% if t < states('sensor.imsak') %}{{ states('sensor.imsak') }}
{% elif t < states('sensor.gunes') %}{{ states('sensor.gunes') }}
{% elif t < states('sensor.ogle') %}{{ states('sensor.ogle') }}
{% elif t < states('sensor.ikindi') %}{{ states('sensor.ikindi') }}
{% elif t < states('sensor.aksam') %}{{ states('sensor.aksam') }}
{% elif t < states('sensor.yatsi') %}{{ states('sensor.yatsi') }}
{% else %}{{ states('sensor.imsak') }}{% endif %}
# -------------------------
# Time remaining
# -------------------------
- name: "Namaz Time Remaining"
unique_id: namaz_time_remaining
state: >
{% set next_prayer = states('sensor.next_prayer') %}
{% if next_prayer not in ['unknown', 'unavailable'] %}
{% set ct = today_at(next_prayer) %}
{% set remaining = (ct - now()).total_seconds() | int %}
{% if remaining < 0 %}
{% set ct = ct + timedelta(days=1) %}
{% set remaining = (ct - now()).total_seconds() | int %}
{% endif %}
{{ '%02d:%02d' | format(remaining // 3600, (remaining % 3600) // 60) }}
{% else %}
00:00
{% endif %}
# -------------------------
# Prayer Time Binary Sensors
# -------------------------
- name: "İmsak Vakti"
unique_id: imsak_vakti
state: "{{ now().strftime('%H:%M') == states('sensor.imsak') }}"
- name: "Güneş Vakti"
unique_id: gunes_vakti
state: >
{% set gunes = states('sensor.gunes') %}
{% if gunes not in ['unknown', 'unavailable'] %}
{% set time = today_at(gunes) %}
{% set start = time - timedelta(minutes=35) %}
{{ start <= now() <= time }}
{% else %}
false
{% endif %}
- name: "Öğle Vakti"
unique_id: ogle_namazi
state: "{{ now().strftime('%H:%M') == states('sensor.ogle') }}"
- name: "İkindi Vakti"
unique_id: ikindi_namazi
state: "{{ now().strftime('%H:%M') == states('sensor.ikindi') }}"
- name: "Akşam Vakti"
unique_id: aksam_namazi
state: "{{ now().strftime('%H:%M') == states('sensor.aksam') }}"
- name: "Yatsı Vakti"
unique_id: yatsi_namazi
state: "{{ now().strftime('%H:%M') == states('sensor.yatsi') }}"
- name: "Sahur Vakti"
unique_id: sahur_vakti
state: >
{% set imsak = states('sensor.imsak') %}
{% if imsak not in ['unknown', 'unavailable'] %}
{% set time = today_at(imsak) %}
{% set start = time - timedelta(minutes=40) %}
{{ start <= now() <= time }}
{% else %}
false
{% endif %}
As stated previously the above code checks if the time now matches the time we got from the API. If this is true the sensor created will return true. This happens for each prayer. For the morning prayer I make the sensor trigger 35 minutes before the sunrise time (gunes). Additionally above creates: