Skip to content

Instantly share code, notes, and snippets.

@zubir2k
Last active March 1, 2025 16:22
Show Gist options
  • Save zubir2k/4d39dba287b2252771904d2f08d1d1e8 to your computer and use it in GitHub Desktop.
Save zubir2k/4d39dba287b2252771904d2f08d1d1e8 to your computer and use it in GitHub Desktop.

Revisions

  1. zubir2k revised this gist Feb 15, 2024. 2 changed files with 13 additions and 2 deletions.
    13 changes: 12 additions & 1 deletion HomeAssistantIslamicPrayerTimeExtended.md
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,18 @@ The automation example given calls the following action:
    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).
    - For alexa users, the action to play the audio would be as follows:

    ```jinja
    service: notify.alexa_media_xxx #Change this to your alexa device
    data:
    data:
    type: tts
    message: >-
    <audio src='{%if is_state("sensor.now_prayer","Fajr")
    %}https://dl.sndup.net/rkrk/azansubuh_alexa.mp3{% else
    %}https://dl.sndup.net/c62p/azan_alexa.mp3{% endif %}'/>
    ```

    May this be beneficial to all. Insha'Allah
    2 changes: 1 addition & 1 deletion configuration.yaml
    Original file line number Diff line number Diff line change
    @@ -88,7 +88,7 @@ automation:
    data:
    media_content_type: audio/mp3
    media_content_id: >-
    {% if states('sensor.now_prayer') == 'Fajr'
    {% if is_state('sensor.now_prayer','Fajr')
    %}https://dl.sndup.net/rkrk/azansubuh_alexa.mp3{% else
    %}https://dl.sndup.net/c62p/azan_alexa.mp3{% endif %}
    extra:
  2. zubir2k revised this gist Feb 15, 2024. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion HomeAssistantIslamicPrayerTimeExtended.md
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,6 @@ Installation:
    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:
  3. zubir2k revised this gist Feb 15, 2024. 1 changed file with 73 additions and 111 deletions.
    184 changes: 73 additions & 111 deletions configuration.yaml
    Original file line number Diff line number Diff line change
    @@ -3,136 +3,98 @@
    sensor:
    - platform: template
    sensors:
    imsak_time:
    friendly_name: "Imsak"
    islamic_prayer_times_imsak_time:
    friendly_name: "Islamic Prayer Times Imsak time"
    device_class: timestamp
    icon_template: mdi:calendar-clock
    value_template: "{{ (as_timestamp(states('sensor.fajr_prayer')) | int - (10*60)) | timestamp_utc }}"
    value_template: >-
    {% set prayer_times = integration_entities("Islamic Prayer Times") %}
    {{ (as_timestamp(states(prayer_times[0])) | int - (10*60)) | timestamp_utc }}
    now_prayer:
    friendly_name: "Prayer Time"
    icon_template: mdi:calendar-clock
    value_template: >-
    {% if as_local(now()) >= as_local(states('sensor.imsak_time') | as_datetime) and as_local(now()) <= as_local(states('sensor.fajr_prayer') | as_datetime) + timedelta(seconds=-1) %}Imsak
    {% elif as_local(now()) >= as_local(states('sensor.fajr_prayer') | as_datetime) and as_local(now()) <= as_local(states('sensor.sunrise_time') | as_datetime) + timedelta(seconds=-1) %}Fajr
    {% elif as_local(now()) >= as_local(states('sensor.sunrise_time') | as_datetime) and as_local(now()) <= as_local(states('sensor.dhuhr_prayer') | as_datetime) + timedelta(seconds=-1) %}Sunrise (Syuruk)
    {% elif as_local(now()) >= as_local(states('sensor.dhuhr_prayer') | as_datetime) and as_local(now()) <= as_local(states('sensor.asr_prayer') | as_datetime) + timedelta(seconds=-1) %}Dhuhr
    {% elif as_local(now()) >= as_local(states('sensor.asr_prayer') | as_datetime) and as_local(now()) <= as_local(states('sensor.maghrib_prayer') | as_datetime) + timedelta(seconds=-1) %}Asr
    {% elif as_local(now()) >= as_local(states('sensor.maghrib_prayer') | as_datetime) and as_local(now()) <= as_local(states('sensor.isha_prayer') | as_datetime) + timedelta(seconds=-1) %}Maghrib
    {% elif as_local(now()) >= as_local(states('sensor.isha_prayer') | as_datetime) and as_local(now()) <= as_local(states('sensor.imsak_time') | as_datetime) + timedelta(days=1, seconds=-1) %}Isha
    {% elif as_local(now()) >= as_local(states('sensor.isha_prayer') | as_datetime) + timedelta(days=-1) and as_local(now()) <= as_local(states('sensor.imsak_time') | as_datetime) + timedelta(seconds=-1) %}Isha
    {% set prayer_times = integration_entities("Islamic Prayer Times") %}
    {% if now().timestamp() >= as_timestamp(states('sensor.islamic_prayer_times_imsak_time')) and now().timestamp() < as_timestamp(states(prayer_times[0])) %}Imsak
    {% elif now().timestamp() >= as_timestamp(states(prayer_times[0])) and now().timestamp() < as_timestamp(states(prayer_times[1])) %}Fajr
    {% elif now().timestamp() >= as_timestamp(states(prayer_times[1])) and now().timestamp() < as_timestamp(states(prayer_times[2])) %}Sunrise
    {% elif now().timestamp() >= as_timestamp(states(prayer_times[2])) and now().timestamp() < as_timestamp(states(prayer_times[3])) %}Dhuhr
    {% elif now().timestamp() >= as_timestamp(states(prayer_times[3])) and now().timestamp() < as_timestamp(states(prayer_times[4])) %}Asr
    {% elif now().timestamp() >= as_timestamp(states(prayer_times[4])) and now().timestamp() < as_timestamp(states(prayer_times[5])) %}Maghrib
    {% elif now().timestamp() >= as_timestamp(states(prayer_times[5])) and now().timestamp() < as_timestamp(states(prayer_times[6])) %}Isha
    {% elif now().timestamp() >= as_timestamp(states(prayer_times[6])) %}Midnight
    {% else %}Midnight
    {% 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') }}
    {% set prayer_times = integration_entities("Islamic Prayer Times") %}
    {%if is_state('sensor.now_prayer', 'Imsak') %}{{ states('sensor.islamic_prayer_times_imsak_time') }}
    {%elif is_state('sensor.now_prayer', 'Fajr') %}{{ states(prayer_times[0]) }}
    {%elif is_state('sensor.now_prayer', 'Sunrise') %}{{ states(prayer_times[1]) }}
    {%elif is_state('sensor.now_prayer', 'Dhuhr') %}{{ states(prayer_times[2]) }}
    {%elif is_state('sensor.now_prayer', 'Asr') %}{{ states(prayer_times[3]) }}
    {%elif is_state('sensor.now_prayer', 'Maghrib') %}{{ states(prayer_times[4]) }}
    {%elif is_state('sensor.now_prayer', 'Isha') %}{{ states(prayer_times[5]) }}
    {%elif is_state('sensor.now_prayer', 'Midnight') %}{{ states(prayer_times[6]) }}
    {%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') }}
    {% set prayer_times = integration_entities("Islamic Prayer Times") %}
    {%if is_state('sensor.now_prayer', 'Imsak') %}{{ as_timestamp(states('sensor.islamic_prayer_times_imsak_time')) | timestamp_custom('%I:%M %p') }}
    {%elif is_state('sensor.now_prayer', 'Fajr') %}{{ as_timestamp(states(prayer_times[0])) | timestamp_custom('%I:%M %p') }}
    {%elif is_state('sensor.now_prayer', 'Sunrise') %}{{ as_timestamp(states(prayer_times[1])) | timestamp_custom('%I:%M %p') }}
    {%elif is_state('sensor.now_prayer', 'Dhuhr') %}{{ as_timestamp(states(prayer_times[2])) | timestamp_custom('%I:%M %p') }}
    {%elif is_state('sensor.now_prayer', 'Asr') %}{{ as_timestamp(states(prayer_times[3])) | timestamp_custom('%I:%M %p') }}
    {%elif is_state('sensor.now_prayer', 'Maghrib') %}{{ as_timestamp(states(prayer_times[4])) | timestamp_custom('%I:%M %p') }}
    {%elif is_state('sensor.now_prayer', 'Isha') %}{{ as_timestamp(states(prayer_times[5])) | timestamp_custom('%I:%M %p') }}
    {%elif is_state('sensor.now_prayer', 'Midnight') %}{{ as_timestamp(states(prayer_times[6])) | 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') }}
    {% set prayer_times = integration_entities("Islamic Prayer Times") %}
    {%if is_state('sensor.now_prayer', 'Imsak') %}{{ as_timestamp(states('sensor.islamic_prayer_times_imsak_time')) | timestamp_custom('%H:%M') }}
    {%elif is_state('sensor.now_prayer', 'Fajr') %}{{ as_timestamp(states(prayer_times[0])) | timestamp_custom('%H:%M') }}
    {%elif is_state('sensor.now_prayer', 'Sunrise') %}{{ as_timestamp(states(prayer_times[1])) | timestamp_custom('%H:%M') }}
    {%elif is_state('sensor.now_prayer', 'Dhuhr') %}{{ as_timestamp(states(prayer_times[2])) | timestamp_custom('%H:%M') }}
    {%elif is_state('sensor.now_prayer', 'Asr') %}{{ as_timestamp(states(prayer_times[3])) | timestamp_custom('%H:%M') }}
    {%elif is_state('sensor.now_prayer', 'Maghrib') %}{{ as_timestamp(states(prayer_times[4])) | timestamp_custom('%H:%M') }}
    {%elif is_state('sensor.now_prayer', 'Isha') %}{{ as_timestamp(states(prayer_times[5])) | timestamp_custom('%H:%M') }}
    {%elif is_state('sensor.now_prayer', 'Midnight') %}{{ as_timestamp(states(prayer_times[6])) | 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
    {{ is_state('sensor.now_prayer', ['Fajr','Dhuhr','Asr','Maghrib','Isha'])
    and is_state_attr('sensor.now_prayer', '24hours', now().strftime('%H:%M'))
    }}
    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: https://dl.sndup.net/rkrk/azansubuh_alexa.mp3
    extra:
    title: Adzan {{states('sensor.now_prayer')}}
    thumb: https://i.imgur.com/1U9Ehvr.png
    - 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: https://dl.sndup.net/c62p/azan_alexa.mp3
    extra:
    title: Adzan {{states('sensor.now_prayer')}}
    thumb: https://i.imgur.com/1U9Ehvr.png
    default: []
    mode: single
    - service: notify.notify
    data:
    title: 🕋 Prayer Alert - {{states('sensor.now_prayer')}}
    message: >-
    {{ now().strftime('%-I:%M %p') }} - It is now
    {{states('sensor.now_prayer')}}. Perform your salah.
    - service: persistent_notification.create
    data:
    message: >-
    {{ now().strftime('%-I:%M %p') }} - It is now
    {{states('sensor.now_prayer')}}. Perform your salah.
    title: 🕋 Prayer Alert - {{states('sensor.now_prayer')}}
    notification_id: prayertime
    - service: media_player.play_media
    data:
    media_content_type: audio/mp3
    media_content_id: >-
    {% if states('sensor.now_prayer') == 'Fajr'
    %}https://dl.sndup.net/rkrk/azansubuh_alexa.mp3{% else
    %}https://dl.sndup.net/c62p/azan_alexa.mp3{% endif %}
    extra:
    title: Adzan {{states('sensor.now_prayer')}}
    thumb: https://i.imgur.com/1U9Ehvr.png
    target:
    entity_id: media_player.all_devices #Change this to your media player
    mode: single

  4. zubir2k revised this gist Oct 6, 2023. 1 changed file with 14 additions and 11 deletions.
    25 changes: 14 additions & 11 deletions configuration.yaml
    Original file line number Diff line number Diff line change
    @@ -12,14 +12,15 @@ sensor:
    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%}
    {% if as_local(now()) >= as_local(states('sensor.imsak_time') | as_datetime) and as_local(now()) <= as_local(states('sensor.fajr_prayer') | as_datetime) + timedelta(seconds=-1) %}Imsak
    {% elif as_local(now()) >= as_local(states('sensor.fajr_prayer') | as_datetime) and as_local(now()) <= as_local(states('sensor.sunrise_time') | as_datetime) + timedelta(seconds=-1) %}Fajr
    {% elif as_local(now()) >= as_local(states('sensor.sunrise_time') | as_datetime) and as_local(now()) <= as_local(states('sensor.dhuhr_prayer') | as_datetime) + timedelta(seconds=-1) %}Sunrise (Syuruk)
    {% elif as_local(now()) >= as_local(states('sensor.dhuhr_prayer') | as_datetime) and as_local(now()) <= as_local(states('sensor.asr_prayer') | as_datetime) + timedelta(seconds=-1) %}Dhuhr
    {% elif as_local(now()) >= as_local(states('sensor.asr_prayer') | as_datetime) and as_local(now()) <= as_local(states('sensor.maghrib_prayer') | as_datetime) + timedelta(seconds=-1) %}Asr
    {% elif as_local(now()) >= as_local(states('sensor.maghrib_prayer') | as_datetime) and as_local(now()) <= as_local(states('sensor.isha_prayer') | as_datetime) + timedelta(seconds=-1) %}Maghrib
    {% elif as_local(now()) >= as_local(states('sensor.isha_prayer') | as_datetime) and as_local(now()) <= as_local(states('sensor.imsak_time') | as_datetime) + timedelta(days=1, seconds=-1) %}Isha
    {% elif as_local(now()) >= as_local(states('sensor.isha_prayer') | as_datetime) + timedelta(days=-1) and as_local(now()) <= as_local(states('sensor.imsak_time') | as_datetime) + timedelta(seconds=-1) %}Isha
    {% endif %}
    attribute_templates:
    timestamp: >-
    {%if is_state('sensor.now_prayer', 'Imsak') %}{{ states('sensor.imsak_time') }}
    @@ -91,9 +92,10 @@ automation:
    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
    media_content_id: https://dl.sndup.net/rkrk/azansubuh_alexa.mp3
    extra:
    title: Adzan {{states('sensor.now_prayer')}}
    thumb: https://i.imgur.com/1U9Ehvr.png
    - conditions:
    - condition: template
    value_template: >-
    @@ -128,8 +130,9 @@ automation:
    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
    media_content_id: https://dl.sndup.net/c62p/azan_alexa.mp3
    extra:
    title: Azan {{states('sensor.now_prayer')}}
    title: Adzan {{states('sensor.now_prayer')}}
    thumb: https://i.imgur.com/1U9Ehvr.png
    default: []
    mode: single
  5. zubir2k revised this gist Sep 30, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion HomeAssistantIslamicPrayerTimeExtended.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,8 @@ This will add 2 additional sensors which will ease in creating adzan automation:

    Installation:
    - Add the following yaml into configuration.yaml
    - Create an automation by following the conditions shared in automation.yaml
    - It will automatically create an automation for the adzan. Be sure to adjust the media_player and audio.
    - You may also create your own automation based on the automation conditions that I have prepared.

    The automation example given calls the following action:
    - Alert Persistent Notification
  6. zubir2k revised this gist Sep 30, 2022. 2 changed files with 86 additions and 85 deletions.
    84 changes: 0 additions & 84 deletions automation.yaml
    Original file line number Diff line number Diff line change
    @@ -1,84 +0,0 @@
    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
    87 changes: 86 additions & 1 deletion configuration.yaml
    Original file line number Diff line number Diff line change
    @@ -47,4 +47,89 @@ sensor:
    {%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%}
    {%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
  7. zubir2k renamed this gist Sep 30, 2022. 1 changed file with 0 additions and 0 deletions.
  8. zubir2k created this gist Sep 30, 2022.
    27 changes: 27 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    ### 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
    84 changes: 84 additions & 0 deletions automation.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,84 @@
    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
    50 changes: 50 additions & 0 deletions configuration.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    ## 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%}