Skip to content

Instantly share code, notes, and snippets.

@zubir2k
Last active March 1, 2025 16:22
Show Gist options
  • Select an option

  • Save zubir2k/4d39dba287b2252771904d2f08d1d1e8 to your computer and use it in GitHub Desktop.

Select an option

Save zubir2k/4d39dba287b2252771904d2f08d1d1e8 to your computer and use it in GitHub Desktop.
Home Assistant Islamic Prayer Time [Extended]
## Official Islamic Prayer Time (extended) ##
## https://www.home-assistant.io/integrations/islamic_prayer_times
sensor:
- platform: template
sensors:
imsak_time:
friendly_name: "Imsak"
device_class: timestamp
icon_template: mdi:calendar-clock
value_template: "{{ (as_timestamp(states('sensor.fajr_prayer')) | int - (10*60)) | timestamp_utc }}"
now_prayer:
friendly_name: "Prayer Time"
icon_template: mdi:calendar-clock
value_template: >-
{%if now().timestamp() >= as_timestamp(states('sensor.imsak_time')) and now().timestamp() < as_timestamp(states('sensor.fajr_prayer')) %}Imsak
{%elif now().timestamp() >= as_timestamp(states('sensor.fajr_prayer')) and now().timestamp() < as_timestamp(states('sensor.sunrise_time')) %}Fajr
{%elif now().timestamp() >= as_timestamp(states('sensor.sunrise_time')) and now().timestamp() < as_timestamp(states('sensor.dhuhr_prayer')) %}Sunrise (Syuruk)
{%elif now().timestamp() >= as_timestamp(states('sensor.dhuhr_prayer')) and now().timestamp() < as_timestamp(states('sensor.asr_prayer')) %}Dhuhr
{%elif now().timestamp() >= as_timestamp(states('sensor.asr_prayer')) and now().timestamp() < as_timestamp(states('sensor.maghrib_prayer')) %}Asr
{%elif now().timestamp() >= as_timestamp(states('sensor.maghrib_prayer')) and now().timestamp() < as_timestamp(states('sensor.isha_prayer')) %}Maghrib
{%elif now().timestamp() >= as_timestamp(states('sensor.isha_prayer')) %}Isha
{%endif%}
attribute_templates:
timestamp: >-
{%if is_state('sensor.now_prayer', 'Imsak') %}{{ states('sensor.imsak_time') }}
{%elif is_state('sensor.now_prayer', 'Fajr') %}{{ states('sensor.fajr_prayer') }}
{%elif is_state('sensor.now_prayer', 'Syuruk') %}{{ states('sensor.sunrise_time') }}
{%elif is_state('sensor.now_prayer', 'Dhuhr') %}{{ states('sensor.dhuhr_prayer') }}
{%elif is_state('sensor.now_prayer', 'Asr') %}{{ states('sensor.asr_prayer') }}
{%elif is_state('sensor.now_prayer', 'Maghrib') %}{{ states('sensor.maghrib_prayer') }}
{%elif is_state('sensor.now_prayer', 'Isha') %}{{ states('sensor.isha_prayer') }}
{%endif%}
12hours: >-
{%if is_state('sensor.now_prayer', 'Imsak') %}{{ as_timestamp(states('sensor.imsak_time')) | timestamp_custom('%I:%M %p') }}
{%elif is_state('sensor.now_prayer', 'Fajr') %}{{ as_timestamp(states('sensor.fajr_prayer')) | timestamp_custom('%I:%M %p') }}
{%elif is_state('sensor.now_prayer', 'Syuruk') %}{{ as_timestamp(states('sensor.sunrise_time')) | timestamp_custom('%I:%M %p') }}
{%elif is_state('sensor.now_prayer', 'Dhuhr') %}{{ as_timestamp(states('sensor.dhuhr_prayer')) | timestamp_custom('%I:%M %p') }}
{%elif is_state('sensor.now_prayer', 'Asr') %}{{ as_timestamp(states('sensor.asr_prayer')) | timestamp_custom('%I:%M %p') }}
{%elif is_state('sensor.now_prayer', 'Maghrib') %}{{ as_timestamp(states('sensor.maghrib_prayer')) | timestamp_custom('%I:%M %p') }}
{%elif is_state('sensor.now_prayer', 'Isha') %}{{ as_timestamp(states('sensor.isha_prayer')) | timestamp_custom('%I:%M %p') }}
{%endif%}
24hours: >-
{%if is_state('sensor.now_prayer', 'Imsak') %}{{ as_timestamp(states('sensor.imsak_time')) | timestamp_custom('%H:%M') }}
{%elif is_state('sensor.now_prayer', 'Fajr') %}{{ as_timestamp(states('sensor.fajr_prayer')) | timestamp_custom('%H:%M') }}
{%elif is_state('sensor.now_prayer', 'Syuruk') %}{{ as_timestamp(states('sensor.sunrise_time')) | timestamp_custom('%H:%M') }}
{%elif is_state('sensor.now_prayer', 'Dhuhr') %}{{ as_timestamp(states('sensor.dhuhr_prayer')) | timestamp_custom('%H:%M') }}
{%elif is_state('sensor.now_prayer', 'Asr') %}{{ as_timestamp(states('sensor.asr_prayer')) | timestamp_custom('%H:%M') }}
{%elif is_state('sensor.now_prayer', 'Maghrib') %}{{ as_timestamp(states('sensor.maghrib_prayer')) | timestamp_custom('%H:%M') }}
{%elif is_state('sensor.now_prayer', 'Isha') %}{{ as_timestamp(states('sensor.isha_prayer')) | timestamp_custom('%H:%M') }}
{%endif%}
automation:
- alias: πŸ•‹ Adzan Automation
description: Play Audio and Notification (Disable this if you wish to use your own)
trigger:
- platform: template
value_template: >-
{{ is_state_attr('sensor.now_prayer', '24hours',
now().strftime('%H:%M'))}}
id: solat
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ is_state('sensor.now_prayer', 'fajr') }}"
sequence:
- service: persistent_notification.create
data:
message: >-
{{ now().strftime('%-I:%M %p') }} - It is now
{{states('sensor.now_prayer')}} prayer. Perform your salah.
notification_id: esolat_azan
title: πŸ•‹ Prayer Alert - {{states('sensor.now_prayer')}}
- service: notify.notify
data:
message: >-
{{ now().strftime('%-I:%M %p') }} - It is now
{{states('sensor.now_prayer')}} prayer. Perform your salah.
title: πŸ•‹ Prayer Alert - {{states('sensor.now_prayer')}}
- service: tts.google_translate_say
data:
entity_id: media_player.all_devices #Change this to your media player
language: en
message: >-
It is now {{ states('sensor.now_prayer') }} prayer. Perform your
salah.
- delay: "00:00:10"
- service: media_player.play_media
target:
entity_id: media_player.all_devices #Change this to your media player
data:
media_content_type: audio/mp3
media_content_id: media-source://media_source/local/adzan_fajr.mp3
extra:
title: Adzan {{states('sensor.now_prayer')}}
- conditions:
- condition: template
value_template: >-
{{ is_state('sensor.now_prayer', 'Dhuhr') or
is_state('sensor.now_prayer', 'Asr') or
is_state('sensor.now_prayer', 'Maghrib') or
is_state('sensor.now_prayer', 'Isha') }}
sequence:
- service: persistent_notification.create
data:
message: >-
{{ now().strftime('%-I:%M %p') }} - It is now
{{states('sensor.now_prayer')}} prayer. Perform your salah.
notification_id: esolat_azan
title: πŸ•‹ Prayer Alert - {{states('sensor.now_prayer')}}
- service: notify.notify
data:
message: >-
{{ now().strftime('%-I:%M %p') }} - It is now
{{states('sensor.now_prayer')}} prayer. Perform your salah.
title: πŸ•‹ Prayer Alert - {{states('sensor.now_prayer')}}
- service: tts.google_translate_say
data:
entity_id: media_player.all_devices #Change this to your media player
language: en
message: >-
It is now {{ states('sensor.now_prayer') }} prayer. Perform your
salah.
- delay: "00:00:10"
- service: media_player.play_media
target:
entity_id: media_player.all_devices #Change this to your media player
data:
media_content_type: audio/mp3
media_content_id: media-source://media_source/local/adzan.mp3
extra:
title: Azan {{states('sensor.now_prayer')}}
default: []
mode: single

Home Assistant Islamic Prayer Time [Extended]

Reference: https://www.home-assistant.io/integrations/islamic_prayer_times

Assalamu'alaikum

The current integration only creates sensors consist of fajr, dhuhr, asr, maghrib, isha, sunrise and midnight. This will add 2 additional sensors which will ease in creating adzan automation:

  1. Current Prayer Time
  2. Imsak Time

Installation:

  • Add the following yaml into configuration.yaml
  • Create an automation by following the conditions shared in automation.yaml

The automation example given calls the following action:

  • Alert Persistent Notification
  • Alert via Notify.notify (for HA companion app)
  • Alert via TTS
  • Play adzan audio

Notes:

  • You are free to choose what type of action upon triggering the prayer time
  • Please change the media_player to your own. Do note that this automation works on Google Nest speakers.
  • Please ensure your TTS is working
  • Please ensure to have 2 adzan mp3 (fajr and the rest of the prayer time).

May this be beneficial to all. Insha'Allah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment