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

It was fixed the next day after the switch to DST. I opened an issue with the developers

Oh, I’m aware of that, I meant the UI doesn’t support (show) multiple trigger entities, only via yaml. Jzk

Salaam ou alaikum, Can anyone help me with the following. I cannot adjust the prayer times

Jazakallah khair

1 Like

Salaam ou Alaikoum Brothers,
Do any of you know how I can add Hijri calendar to the prayer times?

I would like to know also. How do we create offsets, or use London based timings?

For anyone who wish to have offset configurable without restarting HA and also in addition to that I play the quran everyday before the Magrib prayer. I am a newbie with HA and with the help of all the posts here I was able to make some changes for my need.

All the media files I kept it local and not relying on the internet.
I have added the Islamic Prayer Times using the integration. And using the prayer sensors, I have built as below

I have done all the configuration through the UI and below is the automation I have created for the prayer time to be played on my google nest

alias: Play Azaan for Rest
description: ''
trigger:
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.dhuhr_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_text.offset_dhuhr")) }}
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.asr_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_text.offset_asr")) }}
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.maghrib_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_text.offset_maghrib")) }}
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.isha_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_text.offset_isha")) }}
condition: []
action:
  - service: media_player.play_media
    data:
      media_content_id: 'http://192.168.86.20:8143/local/sound/azan3.mp3'
      media_content_type: audio/mp3
    target:
      entity_id: media_player.all_speakers
  - service: media_player.volume_set
    data:
      volume_level: 0.5
    target:
      entity_id: media_player.bedroom_wifi
  - service: media_player.volume_set
    data:
      volume_level: 0.3
    target:
      entity_id: media_player.studyroom_wifi
  - service: media_player.volume_set
    data:
      volume_level: 0.7
    target:
      entity_id: media_player.kitchen_speaker
mode: single

Below is one of the input text I had created for the offset. Which can be updated anytime. Set the value to be in seconds and also I had to make sure the seconds I set always converts to an integer minute. If not the automation does not trigger.

Below are the details on how I play the quran everyday and finishes couple of seconds before Magrib prayer. Two helpers used here, a counter to keep track of the juz and input text to save the media duration.

alias: Get Media Duration
description: ''
trigger:
  - platform: time
    at: '06:00'
condition: []
action:
  - service: media_player.volume_mute
    data:
      is_volume_muted: true
    target:
      entity_id: media_player.kitchen_speaker
  - service: media_player.play_media
    data:
      media_content_type: video/mp4
      media_content_id: >-
        media-source://media_source/local/quran/Para{{states("counter.juzcounter")}}.mp3
    entity_id: media_player.kitchen_speaker
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: input_text.set_value
    data:
      value: >
        {% set actual_duration =
        state_attr("media_player.kitchen_speaker","media_duration") | round(0)
        %}  {% set duration_in_min = (actual_duration/60)|round(0)%}  {% if
        (duration_in_min*60) > actual_duration -%}  {% set duration_update =
        duration_in_min*60 %}  {%- else -%} {% set duration_update =
        (duration_in_min*60) + 60 %}  {%- endif %}  {{duration_update}}
    target:
      entity_id: input_text.mediaduration
  - service: media_player.media_stop
    data: {}
    target:
      entity_id: media_player.kitchen_speaker
  - service: media_player.volume_mute
    target:
      entity_id: media_player.kitchen_speaker
    data:
      is_volume_muted: false
  - service: media_player.turn_off
    target:
      entity_id: media_player.kitchen_speaker
mode: single
alias: Play Quran before Magrib
description: ''
trigger:
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.maghrib_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_text.offset_maghrib")) -
      float(states("input_text.mediaduration"))  }}
condition: []
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.3
    target:
      entity_id: media_player.all_speakers
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: media_player.play_media
    data:
      media_content_type: video/mp4
      media_content_id: >-
        media-source://media_source/local/quran/Para{{states("counter.juzcounter")}}.mp3
    entity_id: media_player.all_speakers
  - service: script.increment_and_reset_juz_counter
mode: single
alias: Increment and Reset Juz Counter
sequence:
  - choose:
      - conditions:
          - condition: state
            entity_id: counter.juzcounter
            state: '30'
        sequence:
          - service: counter.reset
            target:
              entity_id: counter.juzcounter
    default:
      - service: counter.increment
        target:
          entity_id: counter.juzcounter
mode: single

I have saved all the (30) juz/para of the Quran in my media and using the juzcounter dynamically I play it one by one daily and resets once it reaches 30.

counter:
juzcounter:
  initial: 1
  step: 1
  maximum: 30
  minimum: 1

Hope it can help someone.

3 Likes

@rr86 JazakAllah Khair, very nice setup!
I’ve used your offset method, but can’t figure out how to reduce the offset after creating the input_select, nothing updates on the Islamic Prayer sensor. Would appreciate help, jzk.

@hazio it will not update the Islamic Prayer sensors.
I have used additional sensors to monitor the actual time of the prayer with the offsets.

configuration.yaml

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'time_date'
      - 'date_time'
  - platform: template
    sensors:
      salah_fajr:
        friendly_name: "Salah Fajr"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.fajr_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_text.offset_fajr")) )| timestamp_custom ('%r')}}
      salah_dhuhr:
        friendly_name: "Salah Dhuhr"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.dhuhr_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_text.offset_dhuhr")) )| timestamp_custom ('%r')}}
      salah_asr:
        friendly_name: "Salah Asr"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.asr_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_text.offset_asr")) )| timestamp_custom ('%r')}}
      salah_maghrib:
        friendly_name: "Salah Maghrib"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.maghrib_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_text.offset_maghrib")) )| timestamp_custom ('%r')}}
      salah_isha:
        friendly_name: "Salah Isha"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.isha_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_text.offset_isha")) )| timestamp_custom ('%r')}}
      quran_time:
        friendly_name: "Quran Time"
        value_template: >
           {{ (as_timestamp(strptime(states("sensor.maghrib_prayer"), "%Y-%m-%dT%H:%M:%S")) + float(states("input_text.offset_maghrib")) - float(states("input_text.mediaduration")) )| timestamp_custom ('%r')}}

And I added a view to lovelace to show the time from these sensors configured
image

If you see my automations in my previous post, I have used the Prayer time sensor + offset for trigger.

So in your case, I believe you need to use the Prayer time sensors + input_selection to get the actual time for the prayer.

Could you explain more on this? I’m fairly new when it comes to setting up input_select, thanks

In the helper create an input select and add the required options you need. Make sure the options are in seconds.
Then change the value under configuration by selecting one of the options added earlier

The input select created above then can be used as below for a time sensor or for the trigger.

sensors:
      salah_fajr:
        friendly_name: "Salah Fajr"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.fajr_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_select.offsetselection")) )| timestamp_custom ('%r')}}
1 Like

Guys i need to setup the correct times for the Azan on my local time, now looks to makkah but it should be different. I will do it for Netherlands and the time from Diyanet.

So I can use a single entity which will be offsetted by the options created on the dialogue config in order, or do I need to create a indiviual input select for each salah sensor, i.e input_select.asr etc…? jzk

@hazio if the offset time is the same across all the prayer time then you can use one.

In my case, I had to adjust for each prayer time by couple of minutes up and down thus I created individually for all prayer time.

1 Like

im trying to use your code to get the offset working. all these while i’ve just been using the default prayer sensor. Now that ramdhan is around the corner, i have to make sure it is following my local timing.

here is my code (config) after copying it from yours.

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'time_date'
      - 'date_time'
  - platform: template
    sensors:
      salah_fajr:
        friendly_name: "Salah Fajr"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.fajr_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_text.offset_fajr")) )| timestamp_custom ('%r')}}
      salah_dhuhr:
        friendly_name: "Salah Dhuhr"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.dhuhr_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_text.offset_dhuhr")) )| timestamp_custom ('%r')}}
      salah_asr:
        friendly_name: "Salah Asr"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.asr_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_text.offset_asr")) )| timestamp_custom ('%r')}}
      salah_maghrib:
        friendly_name: "Salah Maghrib"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.maghrib_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_text.offset_maghrib")) )| timestamp_custom ('%r')}}
      salah_isha:
        friendly_name: "Salah Isha"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.isha_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_text.offset_isha")) )| timestamp_custom ('%r')}}
      quran_time:
        friendly_name: "Quran Time"
        value_template: >
           {{ (as_timestamp(strptime(states("sensor.maghrib_prayer"), "%Y-%m-%dT%H:%M:%S")) + float(states("input_text.offset_maghrib")) - float(states("input_text.mediaduration")) )| timestamp_custom ('%r')}}


I haven’t changed anything here.

Then i tried to open up the entity to put in the offset values and it gives me this error.

image

im at a lost here as i do not know how to input the offset.

Here’s my automation script. Hope u can assist me.

- alias: Azan
  trigger:
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.dhuhr_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_text.offset_dhuhr")) }}
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.asr_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_text.offset_asr")) }}
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.maghrib_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_text.offset_maghrib")) }}
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.isha_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_text.offset_isha")) }}
  condition: []
  action:
  - service: media_extractor.play_media
    data:
      entity_id: media_player.living_speaker
      media_content_id: https://www.dropbox.com/s/zr93i3be3gmdhap/Omar%20%20Hana%20%20Adhan%20%20Islamic%20cartoons%20for%20kids.mp3?dl=0
      media_content_type: music
  - service: media_player.volume_set
    data:
      entity_id: media_player.living_speaker
      volume_level: '0.9'
      mode: single

ok not to worry - i think i got the codes working.

here is my config:

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'time_date'
      - 'date_time'
  - platform: template
    sensors:
      salah_dhuhr:
        friendly_name: "Salah Zohor"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.dhuhr_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_select.offset_zohor")) )| timestamp_custom ('%r')}}
      salah_asr:
        friendly_name: "Salah Asar"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.asr_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_select.offset_asar")) )| timestamp_custom ('%r')}}   
      salah_maghrib:
        friendly_name: "Salah Maghrib"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.maghrib_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_select.offset_maghrib")) )| timestamp_custom ('%r')}}   
      salah_isha:
        friendly_name: "Salah Isyak"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.isha_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_select.offset_isyak")) )| timestamp_custom ('%r')}}   
      salah_fajr:
        friendly_name: "Salah Subuh"
        value_template: >
           {{((as_timestamp(strptime(states("sensor.fajr_prayer"), "%Y-%m-%dT%H:%M:%S"))) + float(states("input_select.offset_subuh")) )| timestamp_custom ('%r')}}   

here’s my auto:

- alias: Azan
  trigger:
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.dhuhr_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_select.offset_zohor")) }}
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.asr_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_select.offset_asar")) }}
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.maghrib_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_select.offset_maghrib")) }}
  - platform: template
    value_template: >-
      {{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d"))
      == as_timestamp(strptime(states("sensor.isha_prayer"),
      "%Y-%m-%dT%H:%M:%S")) + float(states("input_select.offset_isyak")) }}
  condition: []
  action:
  - service: media_extractor.play_media
    data:
      entity_id: media_player.living_speaker
      media_content_id: https://www.dropbox.com/s/zr93i3be3gmdhap/Omar%20%20Hana%20%20Adhan%20%20Islamic%20cartoons%20for%20kids.mp3?dl=0
      media_content_type: music
  - service: media_player.volume_set
    data:
      entity_id: media_player.living_speaker
      volume_level: '0.9'

hope it works with the offset timing. thanks @rr86 for your work around on the offset.

1 Like

@Meaku15 You will not be able to change anything on the sensors in the UI.
From your post you have not mentioned if you did create all the input_text from the UI under Helpers.
If you did create, you will be able to change the value of the input_text to offset accordingly.
I have provided screenshots on this post

https://community.home-assistant.io/t/adhan-automation-using-home-assistant-and-google-home-mini/135622/315?u=rr86

you need to make sure you create all 5 input_text and assign the value
input_text.offset_fajr
input_text.offset_dhuhr
input_text.offset_asr
input_text.offset_maghrib
input_text.offset_isha

I have created the helper entry. Dhuhr azan just played at the time of my local timing based on the offsets that I have set. It is much easier now. But need to do it manually daily.

Thank you so much for your post.

1 Like

Can you please help me? Azan is working on google home but not with the correct times. I have adde +300 seconds there after but is not working.

- action:
  - alias: Azan
    data:
      entity_id: media_player.googlehomemini
      media_content_id: http://xxx.xxx.xxx.xxx/local/audio/3times.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.googlehomemini
      volume_level: '0.3'
    service: media_player.volume_set
  alias: Adhan
  trigger:
  - platform: template
    value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M,
      %Y-%m-%d")) == as_timestamp(strptime(states("sensor.dhuhr_prayer"), "%Y-%m-%dT%H:%M:%S")) +300 }}'
  - platform: template
    value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M,
      %Y-%m-%d")) == as_timestamp(strptime(states("sensor.asr_prayer"), "%Y-%m-%dT%H:%M:%S")) +240 }}'
  - platform: template
    value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M,
      %Y-%m-%d")) == as_timestamp(strptime(states("sensor.isha_prayer"), "%Y-%m-%dT%H:%M:%S")) +300 }}'
  id: 52f2386ead0b45f5b5493d0f12a950a9

@rr86 I’m must be doing something wrong, but how do I trigger the offset selection? Here is my setup

Edit: Okay, I figured it out, but the time sensors are not updating on lovelace.

My Islamic prayer time integration doesn’t show entities suddenly from today. anyone else facing same issue?