🔊 Ready to go blueprint for playing adhan / azan on media players with many optional features

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.
Summary
This blueprint pauses selected media players such as TVs, then plays the appropriate adhan, and optionally resumes selected paused media players.
No files need to be moved into your system. The adhan is stored in my GitHub and it plays it from there. If you would like to add your own adhan files you can edit the content ID path.
It looks at the following entity_ids with timestamp device class to get the adhan time. These are the default names the Islamic Prayer Times creates
sensor.fajr_prayer
sensor.dhuhr_prayer
sensor.asr_prayer
sensor.maghrib_prayer
sensor.isha_prayer

Optional features:
You can also play iftar and suhoor dua for Ramadan by adding a sensor that can tell which Islamic month it is. Here is a sensor you can use. Outputs Ramaḍān when it is Ramadan.

sensor:
  - platform: rest
    name: Islamic month
    resource_template: http://api.aladhan.com/v1/gToH?date={{ now().strftime("%d-%m-%Y") }}&adjustment=1
    value_template: "{{ value_json.data.hijri.month.en }}"

You can also disable Fajr Adhan if needed. If you want me to add more flexibility to this I can surely add it.
If you like to use your own adhan audio files, you can upload it via media browser and enter the path, ex media-source://media_source/local/fajr_adhan.mp3


Template sensor for next prayer (optional)
Here is a quick template sensor that can give you the exact time for the next prayer.

sensor:
  - platform: template
    sensors:
      next_prayer:
        friendly_name: Next Prayer
        icon_template: mdi:star-crescent
        value_template: >
          {% if as_timestamp(now()) > as_timestamp(states('sensor.fajr_prayer')) and as_timestamp(now()) < as_timestamp(states('sensor.dhuhr_prayer')) %}
            {{ states('sensor.dhuhr_prayer') | as_timestamp | timestamp_custom('%I:%M') }}
          {%  elif as_timestamp(now()) > as_timestamp(states('sensor.dhuhr_prayer')) and as_timestamp(now()) < as_timestamp(states('sensor.asr_prayer')) %}
            {{ states('sensor.asr_prayer') | as_timestamp | timestamp_custom('%I:%M') }}
          {%  elif as_timestamp(now()) > as_timestamp(states('sensor.asr_prayer')) and as_timestamp(now()) < as_timestamp(states('sensor.maghrib_prayer')) %}
            {{ states('sensor.maghrib_prayer') | as_timestamp | timestamp_custom('%I:%M') }}
          {%  elif as_timestamp(now()) > as_timestamp(states('sensor.maghrib_prayer')) and as_timestamp(now()) < as_timestamp(states('sensor.isha_prayer')) %}
            {{ states('sensor.isha_prayer') | as_timestamp | timestamp_custom('%I:%M') }}
          {% else %}
            {{ states('sensor.fajr_prayer') | as_timestamp | timestamp_custom('%I:%M') }}
          {% endif %}

Node-Red (optional):
I use node-red and this API to get my adhan times and Islamic month because it has more institutions. You can copy and paste this into your own node-red. You will have to add the custom hass node-red component
Here is the flow for node-red, you can easily copy and paste this. it gets your approximate location via your IP. The month sensor outputs Ramaḍān when it is Ramadan.

[{"id":"db7be88d5a2dc900","type":"moment","z":"390ae1bbd94f7550","name":"","topic":"","input":"payload","inputType":"msg","inTz":"America/Toronto","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"C","output":"payload","outputType":"msg","outTz":"America/Toronto","x":1220,"y":340,"wires":[["0a6c13b6cfaf4c89"]]},{"id":"10faec1c62d998be","type":"moment","z":"390ae1bbd94f7550","name":"","topic":"","input":"payload","inputType":"msg","inTz":"America/Toronto","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"C","output":"payload","outputType":"msg","outTz":"America/Toronto","x":1220,"y":300,"wires":[["b76a795ca3f84e83"]]},{"id":"6df686d157506556","type":"moment","z":"390ae1bbd94f7550","name":"","topic":"","input":"payload","inputType":"msg","inTz":"America/Toronto","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"C","output":"payload","outputType":"msg","outTz":"America/Toronto","x":1220,"y":260,"wires":[["b9c75894fde698b7"]]},{"id":"11c05c6d18c6a48d","type":"moment","z":"390ae1bbd94f7550","name":"","topic":"","input":"payload","inputType":"msg","inTz":"America/Toronto","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"C","output":"payload","outputType":"msg","outTz":"America/Toronto","x":1220,"y":220,"wires":[["37d683766e325bbc"]]},{"id":"d40cc4e12dbd7c18","type":"moment","z":"390ae1bbd94f7550","name":"","topic":"","input":"payload","inputType":"msg","inTz":"America/Toronto","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"C","output":"payload","outputType":"msg","outTz":"America/Toronto","x":1220,"y":180,"wires":[["31a1330579010b14"]]},{"id":"31a1330579010b14","type":"ha-sensor","z":"390ae1bbd94f7550","name":"Fajr","entityConfig":"52f3ed29148b67f8","version":0,"state":"payload","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":1430,"y":180,"wires":[[]]},{"id":"37d683766e325bbc","type":"ha-sensor","z":"390ae1bbd94f7550","name":"Dhuhr","entityConfig":"2d9069c745819983","version":0,"state":"payload","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":1430,"y":220,"wires":[[]]},{"id":"b9c75894fde698b7","type":"ha-sensor","z":"390ae1bbd94f7550","name":"Asr","entityConfig":"8ac00d628ff4b5fa","version":0,"state":"payload","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":1430,"y":260,"wires":[[]]},{"id":"b76a795ca3f84e83","type":"ha-sensor","z":"390ae1bbd94f7550","name":"Maghrib","entityConfig":"ae7b3e8eb05fdef3","version":0,"state":"payload","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":1435,"y":300,"wires":[[]]},{"id":"0a6c13b6cfaf4c89","type":"ha-sensor","z":"390ae1bbd94f7550","name":"Isha","entityConfig":"d18a48ea9925113f","version":0,"state":"payload","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":1430,"y":340,"wires":[[]]},{"id":"854f13d5462c4a53","type":"function","z":"390ae1bbd94f7550","name":"Filtering Fajr","func":"msg.payload = msg.payload.data.timings.Fajr\n\nreturn msg;","outputs":1,"noerr":0,"x":970,"y":180,"wires":[["d40cc4e12dbd7c18"]]},{"id":"bfbbede7124dc2db","type":"function","z":"390ae1bbd94f7550","name":"Filtering Dhuhr","func":"msg.payload = msg.payload.data.timings.Dhuhr\n\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":220,"wires":[["11c05c6d18c6a48d"]]},{"id":"f36dc0089d03f672","type":"function","z":"390ae1bbd94f7550","name":"Filtering Asr","func":"msg.payload = msg.payload.data.timings.Asr\n\nreturn msg;","outputs":1,"noerr":0,"x":975,"y":260,"wires":[["6df686d157506556"]]},{"id":"0b8b352d1f57352d","type":"function","z":"390ae1bbd94f7550","name":"Filtering Maghrib","func":"msg.payload = msg.payload.data.timings.Maghrib\n\nreturn msg;","outputs":1,"noerr":0,"x":990,"y":300,"wires":[["10faec1c62d998be"]]},{"id":"88e147ef3d812f03","type":"function","z":"390ae1bbd94f7550","name":"Filtering Isha","func":"msg.payload = msg.payload.data.timings.Isha\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":975,"y":340,"wires":[["db7be88d5a2dc900"]]},{"id":"7fc1d4708583d554","type":"inject","z":"390ae1bbd94f7550","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"59 23 * * *","once":true,"onceDelay":"10","topic":"","payload":"1","payloadType":"num","x":75,"y":260,"wires":[["7c8588b3840fab5d"]]},{"id":"af37b889f3402172","type":"http request","z":"390ae1bbd94f7550","name":"Prayer Times","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":715,"y":260,"wires":[["854f13d5462c4a53","bfbbede7124dc2db","f36dc0089d03f672","0b8b352d1f57352d","88e147ef3d812f03"]]},{"id":"7c8588b3840fab5d","type":"http request","z":"390ae1bbd94f7550","name":"Get Position","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://ip-api.com/json","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":255,"y":260,"wires":[["10c253fb23a66b78"]]},{"id":"10c253fb23a66b78","type":"function","z":"390ae1bbd94f7550","name":"Inserts location ","func":"var url= \"http://api.aladhan.com/timingsByCity?city=\" + msg.payload.city + \"&country=\" + msg.payload.country + \"&method=2&school=1\";\nmsg.url = url;\n\nreturn msg;","outputs":1,"noerr":0,"x":495,"y":260,"wires":[["af37b889f3402172"]]},{"id":"675d4bce1a824c0a","type":"catch","z":"390ae1bbd94f7550","name":"","scope":["52f3ed29148b67f8","2d9069c745819983","8ac00d628ff4b5fa","ae7b3e8eb05fdef3","d18a48ea9925113f"],"uncaught":false,"x":55,"y":320,"wires":[["7c8588b3840fab5d"]]},{"id":"8727a5baac57e23d","type":"json","z":"390ae1bbd94f7550","name":"","property":"payload","action":"","pretty":false,"x":750,"y":460,"wires":[["d23b9ecc1a05324f"]]},{"id":"8b93839011aa2384","type":"function","z":"390ae1bbd94f7550","name":"Insert date","func":"msg.url = \"http://api.aladhan.com/v1/gToH?date=\" + msg.payload + \"&adjustment=2\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":460,"wires":[["d2f0176fae25da82"]]},{"id":"d2f0176fae25da82","type":"http request","z":"390ae1bbd94f7550","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":610,"y":460,"wires":[["8727a5baac57e23d"]]},{"id":"7ad751ec9bace193","type":"inject","z":"390ae1bbd94f7550","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"00 00 * * *","once":true,"onceDelay":"10","topic":"","payload":"","payloadType":"date","x":110,"y":460,"wires":[["2bafcd9712646d2d"]]},{"id":"2bafcd9712646d2d","type":"moment","z":"390ae1bbd94f7550","name":"Format date","topic":"","input":"","inputType":"msg","inTz":"America/Toronto","adjAmount":0,"adjType":"days","adjDir":"add","format":"D-MM-yyyy","locale":"C","output":"","outputType":"msg","outTz":"America/Toronto","x":270,"y":460,"wires":[["8b93839011aa2384"]]},{"id":"d23b9ecc1a05324f","type":"ha-sensor","z":"390ae1bbd94f7550","name":"Islamic Month","entityConfig":"14d6cd79d18cec58","version":0,"state":"payload.data.hijri.month.en","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":920,"y":460,"wires":[[]]},{"id":"738108efad4366df","type":"catch","z":"390ae1bbd94f7550","name":"","scope":["2bafcd9712646d2d","8b93839011aa2384","d2f0176fae25da82","8727a5baac57e23d","d23b9ecc1a05324f"],"uncaught":false,"x":90,"y":520,"wires":[["2bafcd9712646d2d"]]},{"id":"52f3ed29148b67f8","type":"ha-entity-config","server":"e2aa5a9c.ae5838","deviceConfig":"","name":"sensor config for Fajr","version":6,"entityType":"sensor","haConfig":[{"property":"name","value":"Fajr"},{"property":"device_class","value":"timestamp"},{"property":"icon","value":"mdi:calendar"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"resend":true},{"id":"2d9069c745819983","type":"ha-entity-config","server":"e2aa5a9c.ae5838","deviceConfig":"","name":"sensor config for Dhuhr","version":6,"entityType":"sensor","haConfig":[{"property":"name","value":"Dhuhr"},{"property":"device_class","value":"timestamp"},{"property":"icon","value":"mdi:calendar"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"resend":true},{"id":"8ac00d628ff4b5fa","type":"ha-entity-config","server":"e2aa5a9c.ae5838","deviceConfig":"","name":"sensor config for Asr","version":6,"entityType":"sensor","haConfig":[{"property":"name","value":"Asr"},{"property":"device_class","value":"timestamp"},{"property":"icon","value":"mdi:calendar"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"resend":true},{"id":"ae7b3e8eb05fdef3","type":"ha-entity-config","server":"e2aa5a9c.ae5838","deviceConfig":"","name":"sensor config for Maghrib","version":6,"entityType":"sensor","haConfig":[{"property":"name","value":"Maghrib"},{"property":"device_class","value":"timestamp"},{"property":"icon","value":"mdi:calendar"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"resend":true},{"id":"d18a48ea9925113f","type":"ha-entity-config","server":"e2aa5a9c.ae5838","deviceConfig":"","name":"sensor config for Isha","version":6,"entityType":"sensor","haConfig":[{"property":"name","value":"Isha"},{"property":"device_class","value":"timestamp"},{"property":"icon","value":"mdi:calendar"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"resend":true},{"id":"14d6cd79d18cec58","type":"ha-entity-config","server":"e2aa5a9c.ae5838","deviceConfig":"","name":"sensor config for Islamic Month","version":6,"entityType":"sensor","haConfig":[{"property":"name","value":"Islamic Month"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:calendar"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"resend":true},{"id":"e2aa5a9c.ae5838","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]

Blueprint:

4 Likes

How to get Islamic month sensor ?

You can add this to your configuration.yaml

1 Like

I am getting an error in developer tool when configuration Islamic sensor

And this is the config file and the error


You have 2 sensor: in your configuration.yaml
Delete one of them so it looks like

sensor:
  - platform: rest
    name: Islamic month
    resource_template: http://api.aladhan.com/v1/gToH?date={{ now().strftime("%d-%m-%Y") }}&adjustment=2
    value_template: "{{ value_json.data.hijri.month.en }}"
  - platform: some other platform

I deleted the sensor from nest doorbell
I don’t other sensor just the one you sent and I still get error



I used platform: some other platform as an example. You will have to delete that

This looks great, but how can the volume setting be added to this? Having the ability to lower or increase the volume for playing Azan and then restoring the original volume setting after the azan is done would be great. Would appreciate any help on this.

Thanks

1 Like

Salam,
This took a bit too long to figure out but unfortunately, I won’t be able to add this feature to the blueprint because the automation will have to know the volume for each media player, save it to a variable, wait for the adhan to finish, then set it back. I am not sure how to put all the volume settings for each media_player in one variable.

I tried using scenes as that would more accurately know the states for everything but it seems that you can’t save the volume, only if it is on or off. I would try working on this way more and update the blueprint if it works

So instead of adding it to the blueprint, I created a small automation that you can create to save the volume of 1 media_player, set the volume to your specified value, wait for the adhan to finish, then set it back to the previous value. You can create multiple copies for each media player you have.
Here is the YAML code for it. Remember to change the media_player.kitchen_speaker to your media player

description: ""
trigger:
  - platform: time
    at: sensor.fajr_prayer
  - platform: time
    at: sensor.dhuhr_prayer
  - platform: time
    at: sensor.asr_prayer
  - platform: time
    at: sensor.maghrib_prayer
  - platform: time
    at: sensor.isha_prayer
condition: []
action:
  - service: media_player.turn_on
    data: {}
    target:
      device_id: f8bcf8bacf0ea928a22a81bd871a05b3
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - variables:
      volume: "{{ state_attr('media_player.kitchen_speaker', 'volume_level') }}"
    alias: Save volume
  - service: media_player.volume_set
    data:
      volume_level: 0.78
    target:
      device_id: f8bcf8bacf0ea928a22a81bd871a05b3
    alias: Change volume
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - wait_template: "{{ is_state('media_player.kitchen_speaker', 'idle') }}"
    continue_on_timeout: true
    alias: Wait for the adhan to complete
    enabled: true
  - service: media_player.volume_set
    data:
      volume_level: "{{ volume }}"
    target:
      device_id: f8bcf8bacf0ea928a22a81bd871a05b3
variables:
  volume: 0.8
mode: single
1 Like

Found out how to do it with scenes

Just edit the snapshot entities and in the wait media template, replace media_player.kitchen_speaker with any media_player that will be playing the adhan

To add this, create new blank automation > Click the 3 dots at the top right > edit yaml > paste the code below > click the 3 dots again > edit in visual editor
Here is the yaml

description: ""
trigger:
  - platform: time
    at: sensor.fajr_prayer
  - platform: time
    at: sensor.dhuhr_prayer
  - platform: time
    at: sensor.asr_prayer
  - platform: time
    at: sensor.maghrib_prayer
  - platform: time
    at: sensor.isha_prayer
condition: []
action:
  - service: media_player.turn_on
    data: {}
    target:
      device_id: f8bcf8bacf0ea928a22a81bd871a05b3
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
    enabled: true
  - service: scene.create
    data:
      snapshot_entities:
        - media_player.kitchen_speaker
      scene_id: before_azan
  - service: media_player.volume_set
    data:
      volume_level: 0.78
    target:
      device_id: f8bcf8bacf0ea928a22a81bd871a05b3
    alias: Change volume
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - wait_template: "{{ is_state('media_player.kitchen_speaker', 'idle') }}"
    continue_on_timeout: true
    alias: Wait for the adhan to complete
    enabled: true
  - service: scene.turn_on
    data: {}
    target:
      entity_id: scene.before_azan
    enabled: true
mode: single

Unfortunately, I found out that I can’t use scenes either to implement volume change for this blueprint

1 Like

@AalianKhan I will be trying both these options soon and report back on which one works better. You are doing amazing work

1 Like

I would like to try this blueprint. I have no experience with node red, would this still get my location for adhan times without using node red?

Thanks

@Imygaf

You can use the above listed integration to get the prayer times. I only use node red because I can use api adhan it gives me a bit more control with hanafi Asr times and I believe it to be a bit more accurate as I give exact city. I can try to make a sensor without node red If you want the ability to change schools, method and other options.

I will try it out and let you know
Jazakallah

1 Like

Thank you for the blueprint. This is very helpful.

Along with the Islamic month sensor is there way to add islamic “date” and also a separate islamic “month with dates” calendar?

Hey,
Glad you like it
You can get the current date with this sensor

sensor:
  - platform: rest
    name: Islamic day
    resource_template: http://api.aladhan.com/v1/gToH?date={{ now().strftime("%d-%m-%Y") }}
    value_template: "{{ value_json.data.hijri.day }}"

I am not sure if we can use the API to create an Islamic calendar in the home assistant. I would like that as well so I will try to do some research on it.

Thank you !! Much appreciated.

I am not a programmer, however I try to copy and change some code to make it work. I managed to get the Islamic Date, Month(In English and Arabic) and Year based on your rest code. At the moment I have defined 4 rest sensor codes to get each of them

Is there a way to get all four value in one rest code? Like value_template: date, month, year all in the same same rest definition?

Yup, you can.
Here is the definition for one sensor to display all these.

sensor:
  - platform: rest
    name: Islamic day
    resource_template: http://api.aladhan.com/v1/gToH?date={{ now().strftime("%d-%m-%Y") }}
    value_template: "{{ value_json.data.hijri.day }} {{ value_json.data.hijri.month.en }} ({{ value_json.data.hijri.month.ar }}) {{ value_json.data.hijri.year }}"

Ahh… thank you brother!

Quick question. I noticed the api.aladhan site has full Hijri Calendar option as well. How would I get that full monthly and yearly calendar? I am looking to add it as a card along with the daily prayer times.

Any help would be highly appreciated. Thank you.