🕋
Diyanet Ezan in Home Assistant
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.
As I couldn’t get this to work using the tools provided by others I made a small automation myself. It utilized the scrape component to get the current times displayed on the https://namazvakitleri.diyanet.gov.tr website.
 
Configuration.yaml :
sensor:
#Time sensor required for prayer times
  - platform: time_date
    display_options:
      - 'time'
#Scrape prayer times from diyanet website
  - platform: scrape
    resource: https://namazvakitleri.diyanet.gov.tr/tr-TR/13980/rotterdam-icin-namaz-vakti
    select: "#today-pray-times-row > div:nth-child(1) > div > div.tpt-time"
    name: İmsak
  - platform: scrape
    resource: https://namazvakitleri.diyanet.gov.tr/tr-TR/13980/rotterdam-icin-namaz-vakti
    name: Güneş
    select: "#today-pray-times-row > div:nth-child(2) > div > div.tpt-time"
  - platform: scrape
    resource: https://namazvakitleri.diyanet.gov.tr/tr-TR/13980/rotterdam-icin-namaz-vakti
    name: Öğle
    select: "#today-pray-times-row > div:nth-child(3) > div > div.tpt-time"
  - platform: scrape
    resource: https://namazvakitleri.diyanet.gov.tr/tr-TR/13980/rotterdam-icin-namaz-vakti
    name: İkindi
    select: "#today-pray-times-row > div:nth-child(4) > div > div.tpt-time"
  - platform: scrape
    resource: https://namazvakitleri.diyanet.gov.tr/tr-TR/13980/rotterdam-icin-namaz-vakti
    name: Akşam
    select: "#today-pray-times-row > div:nth-child(5) > div > div.tpt-time"
  - platform: scrape
    resource: https://namazvakitleri.diyanet.gov.tr/tr-TR/13980/rotterdam-icin-namaz-vakti
    name: Yatsı
    select: "#today-pray-times-row > div:nth-child(6) > div > div.tpt-time"

#Check if prayer times scraped match current time. If so, set value to True
  - platform: template
    sensors:
     imsak_vakti:
      friendly_name: "İmsak Vakti"
      value_template: "{{ states('sensor.imsak') == states('sensor.time') }}"
  - platform: template
    sensors:
     gunes_vakti:
      friendly_name: "Güneş Vakti"
      value_template: "{{ states('sensor.gunes') == states('sensor.time') }}"      
  - platform: template
    sensors:
     ogle_namazi:
      friendly_name: "Öğle Vakti"
      value_template: "{{ states('sensor.ogle') == states('sensor.time') }}"   
  - platform: template
    sensors:
     ikindi_namazi:
      friendly_name: "İkindi Vakti"
      value_template: "{{ states('sensor.ikindi') == states('sensor.time') }}" 
  - platform: template
    sensors:
     aksam_namazi:
      friendly_name: "Akşam Vakti"
      value_template: "{{ states('sensor.aksam') == states('sensor.time') }}" 
  - platform: template
    sensors:
     yatsi_namazi:
      friendly_name: "Yatsı Vakti"
      value_template: "{{ states('sensor.yatsi') == states('sensor.time') }}"
  - platform: template
 
In the above code the url should be replaced with the URL you get when you search for your city on: https://namazvakitleri.diyanet.gov.tr
The above snipped will create a couple of sensors (sensor.imsak) and create an additional sensor (sensor.imsak.vakti) that becomes true when sensor.imsak and the current time (based on sensor.time) match. This can be used to create an automation that will trigger when one of these sensors becomes true:
automations.yaml:
- id: '1641288286388'
  alias: Namaz
  trigger:
  - platform: state
    entity_id:
    - sensor.imsak_vakti
    - sensor.ogle_namazi
    - sensor.ikindi_namazi
    - sensor.aksam_namazi
    - sensor.yatsi_namazi
    to: 'True'
  - condition: state
    entity_id: input_boolean.disableprayer
    state: 'off'
  - service: media_player.volume_set
    data:
      volume_level: 0.2
    target:
      entity_id: media_player.home_group
  - service: media_player.play_media
    data:
      entity_id: media_player.home_group
      media_content_id: https://www.naataudio.com/downloads/IslamicRingtones/bismillah_ir_rahman.mp3
      media_content_type: music
 
The above code snipped will:
  • Check if one of the sensors is true
  • Check if condition disable prayer is set to off. For this create a helper called disableprayer
  • Set the media player volume to 0,2
  • play an MP3 file on the media player
 
For lovelace I use this code to create a nice card:
type: custom:vertical-stack-in-card
cards:
  - type: glance
    entities:
      - entity: sensor.imsak
        icon: mdi:hands-pray
      - entity: sensor.ogle
        icon: mdi:hands-pray
      - entity: sensor.ikindi
        icon: mdi:hands-pray
      - entity: sensor.aksam
        icon: mdi:hands-pray
      - entity: sensor.yatsi
        icon: mdi:hands-pray
    title: 'Namaz '
    show_icon: true
    show_state: true
  - type: entities
    entities:
      - entity: input_boolean.disableprayer
        name: Zet Ezan uit
    state_color: true
notion image
It uses the custom vertical-stack-in-card component available in HACS.