Athan on Google Home (via Home Assistant)

I have a Google Home which I have been using for various things as I very slowly build my collection of “smart” devices.

One thing I was very interested in making my Google Home do is to have the Athan play when it is time for prayer. Unfortunately, there isn’t any native way to do this with a Google Home at the moment.

I have seen people do it using IFTTT, but as I am already using Home Assistant as my automation platform, I wanted to keep everything within it.

What is very interesting about doing it using Home Assistant is that while I can get the basic functionality of the Athan playing, I can also perform other automation that may be useful.

For example, I can switch off or pause what ever is on the TV, switch on the lights on dimly for Fajr prayer, even maybe switch on the Ambi Pur 3volution air freshener that I have plugged into an Espurna flashed Sonoff S20, so my flat smells nice during salah time!.

The way I have implemented this is as follows:

  •  Add a REST sensor which fetches the Athan time using the Al Adhan Service’s API:
  • Add template which extracts the timings for each prayer
  • Create an automation to play the Athan

I haven’t put my Home Assistant configuration on GitHub, so I’ll put it all here for now in case anyone else wants to do something similar.

  - platform: rest
    name: "Prayer Times"
      - data
    resource: ""
    value_template: '{{ value_json["data"]["meta"]["method"]["name"].title() }}'
    scan_interval: 86400

  - platform: template
        friendly_name: 'Fajr Prayer Time'
        value_template: '{{["Fajr"] | timestamp_custom("%H:%M") }}'
        friendly_name: 'Dhuhr Prayer Time'
        value_template: '{{["Dhuhr"] | timestamp_custom("%H:%M") }}'
        friendly_name: 'Asr Prayer Time'
        value_template: '{{["Asr"] | timestamp_custom("%H:%M") }}'
        friendly_name: 'Magrib Prayer Time'
        value_template: '{{["Maghrib"] | timestamp_custom("%H:%M") }}'
        friendly_name: 'Isha Prayer Time'
        value_template: '{{["Isha"] | timestamp_custom("%H:%M") }}'

  - alias: "Fajr Athan"
    initial_state: true
    hide_entity: true
      - condition: template
        value_template: '{{ states.sensor.time.state == states("sensor.fajr") }}'
      - service: media_player.volume_set
          entity_id: media_player.living_room_speaker
          volume_level: 0.75
      - service: media_player.play_media
          entity_id: media_player.living_room_speaker
          media_content_type: audio/mp3

  - alias: "Athan"
    initial_state: true
    hide_entity: true
      - platform: template
        value_template: '{{ states.sensor.time.state == states("sensor.dhuhr") }}'
      - platform: template
        value_template: '{{ states.sensor.time.state == states("sensor.asr") }}'
      - platform: template
        value_template: '{{ states.sensor.time.state == states("sensor.maghrib") }}'
      - platform: template
        value_template: '{{ states.sensor.time.state == states("sensor.isha") }}'
      - service: media_player.volume_set
          entity_id: media_player.living_room_speaker
          volume_level: 0.75
      - service: media_player.play_media
          entity_id: media_player.living_room_speaker
          media_content_type: audio/mp3

This is just a basic automation that sets the volume and plays the Athan. I will expand this so that it only plays the Athan when someone is home, and use input booleans so it can be disabled if needed (for example, during Ramadan when we switch on Islam Channel for the Maghrib Athan). Now that I think of it, it’s also possible to make Home Assistant automatically switch the TV on, and over to Islam Channel during Ramadan!

One annoyance I have found is that before anything is casted to the Google Home, it makes a “blomp” sound. Unfortunately, there isn’t any way to disable this, but there are some tricks on the Home Assistant forums which allow you to get around it. I opted to just live with it as the using those methods would require Home Assistant to keep the casting connection active, and in doing so, would stop the Google Home from entering its low power sleep mode.

I hope this is helpful for anyone else trying to achieve something similar.

42 thoughts on “Athan on Google Home (via Home Assistant)”

  1. Thanks for the write up, will be using your automations for the athan. There is also an islamic prayer times sensor offered by HA (starting in 0.85) so we don’t have to go through anymore 🙂

      1. Actually… it looks like the component is actually just a wrapper around the API anyway. And since it hides a lot of the options available there we’re probably better off sticking to the direct implementation in this post for now.

        I did look into creating a true local HA component for prayer times but as the existing Python local library is a bit of a mess it would be better to start from scratch by porting over the original JS library (here: I’ll do it one day, but since I challenged myself to have automatic sahoor warnings done by the end of Ramadhan I’ll lean on the Aladhan API for now ;).

        1. Oh you are absolutely right, the python module that the HA component uses (both written by the same author) is just a wrapper for

          The current HA component is still cleaner than how I have done it at the moment, but I’ve stopped using Aladhan, and now use the API provided by the London Unified Prayer Times website just because my local Masjid uses the same timings.

          A true, local HA component would be the best option though.

          1. Thanks for the London Unified Prayer Times tip. It’s a great initiative.

            I fell into a bit of a rabbit hole trying to find out where ELM and LCM (and subsequently my local) get their times from. I’ll approach the Unified guys to see how they’re calculating their times with a view to building a local implementation of that too (one day).

          2. It would be great if we could get a local implementation of it.
            I’m not entirely happy with the London Unified Prayer Times API as they expose the prayer times in 12-hour format, and as far as I can tell there isn’t any way to get it to expose in a 24-hour format.
            In order to get around this, I had to write a very poorly written PHP script which acts as a middleman between HA and the API. It converts the times to 24-hour times, so it’s easier to handle in HA.

          3. After an initial look it seems that it’s actually a curated list of times from various sources and manually adapted to cope with London-centric exceptions (one of the updates say that they’ve added times for 2020!). ELM has more info, also has methods.

            So not really a reproducible bunch of times unfortunately. One approach would therefore be to download the times (annually? Monthly?) and store them locally in a more appropriate format.

            It’s a bit unfortunate actually, but at least it’s known and consistent.

          4. Salaam, are you able to share your code with the London Unified Prayer Times?

            many thanks

          5. Walikum Salam,

            I actually had to do it in a way that I’m not really happy with.
            The London Unified Prayer Times API returns the times in 12 hour format, and I couldn’t figure out how to covert them to 24 hour in my HA automation, so instead I have a PHP script which, when accessed, fetches the prayer times, and converts the times to be in 24 hour format.

            Then the rest is exactly the same as how I have done it in the post, except the URL is pointing at the PHP script.

    1. Anyway above can be explained for a non tech person?? Above went over my head with all the tech jargon, better yet put a YouTube video if possible. Lastly keep it short and simple

      Please and Thanks

  2. Salamualikom,

    Thank you brother for taking the time to find a solution for what many of us who are looking for this for a while now.

    However, could you please post the detailed step by step to replicate for the non tech savvy like me?

    Jazaka laho khayran in advance.

    1. Wa-alaykumu as-salam,

      Unfortunately, Home-Assistant has a bit of a learning curve if you aren’t really familar with configuration files and Linux, but if you are interested I would highly advise starting with these two videos:

      They are both very good videos that visually show you how to install Home-Assistant on a Raspberry Pi and also start configuring some basic automations.

      I believe it’s possible to do something similar with IFTTT which is a bit more non-techy friendly, but unfortunately I don’t really use it.

      When I have some time to play with IFTTT, I will try to figure out how to replicate it with that InshAllah.

  3. Salamualikom,

    Thank you brother for your good work i am using Hassiso 9.0 and i have setting like this but i can not Athan playing, I can also perform ca not automation
    any help will be good thanks
    – platform: islamic_prayer_times
    calculation_method: makkah
    – fajr
    – sunrise
    – dhuhr
    – asr
    – maghrib
    – isha
    – midnight

    1. Wa-alaykumu as-salam,

      I actually haven’t converted my automation to work with the islamic_prayer_times sensor.
      Are you getting any error? It would help in trying to debug the issue you are seeing.

      1. Asassalamualaikum,
        no bother no error but i can get the Athan on Google Home to play.
        see below for code
        i am also trying to use node-red too
        any help
        my phone :646-543-2204

    1. Asassalamualaikum,

      It has been on my to-do list for quite some time, but I’ve been a bit lazy about it as it’s been working. The Prayer Time sensor would definitely be better as it doesn’t rely on an external service to function. I’ll try to get my configuration moved over, and publish it on Git sometime this week.

  4. # Automation for Dhuhr, Asr, Maghrib, and Isha Adhan
    – action:
    – alias: ”
    entity_id: media_player.home # replace with your Google Home’s id
    media_content_id: # replace with your choice of Adhan
    media_content_type: music
    service: media_extractor.play_media
    – data:
    entity_id: media_player.home # replace with your Google Home’s id
    volume_level: ‘0.7’
    service: media_player.volume_set
    alias: Adhan
    condition: []
    id: ‘1517693010922’
    – platform: template
    value_template: ‘{{ states.salat.dhuhr.state == states.sensor.time.state }}’
    – platform: template
    value_template: ‘{{ states.salat.asr.state == states.sensor.time.state }}’
    – platform: template
    value_template: ‘{{ states.salat.maghrib.state == states.sensor.time.state }}’
    – platform: template
    value_template: ‘{{ states.salat.isha.state == states.sensor.time.state }}’

    # Separate Automation for Fajr Adhan
    – action:
    – data:
    entity_id: media_player.home # replace with your Google Home’s id
    media_content_id: # replace with your choice of Fajr Adhan
    media_content_type: music
    service: media_extractor.play_media
    – data:
    entity_id: media_player.home # replace with your Google Home’s id
    volume_level: ‘0.7’
    service: media_player.volume_set
    alias: Fajr Adhan
    condition: []
    id: ‘1517694139112’
    – platform: template
    value_template: ‘{{ states.salat.fajr.state == states.sensor.time.state }}’

    this is my code

  5. Salaam,

    Thank you for posting your code. I actually prefer this over the Islamic Prayer Times sensor as it allows for a greater choice of calculation methods.

    I have spent about a week to make this work but the commands do not trigger as expected. The prayer times are downloaded and if I manually trigger the automation, it works but for some reason it is not automatically triggered.

    Do you have any suggestions?

    1. Walikum Salam,

      I apologise for the delay in my reply, I didn’t see the comment until now!

      Did you manage to solve your issue? If not, if you can post the relevant parts of your config in GitHub or something, I can try to assist.



  6. Salam Alaikum,

    Jazak Allah for this blog on creating a home automation.

    I’m a developer myself but fairly new to the HA world and IFTTT. Just a bit of background on how your page inspired me.

    Currently I build Raspberry Pi Athan and Qur’an players for friends, family and other members at my mosque (done 87 builds so far). Essentially it’s all developed in python, hits an API, grabs the prayer times and generates Cron entries to play the Athan at the specified times. Schedule in Cron is recreated every morning. The Qur’an player is another python script which I’ve wired some media player buttons for the functionality of playing, pausing, stopping.

    Given the Google Home Mini is now super cheap, I bought one and fell in love with how easy it is to use. I then started thinking about how I can migrate the functionality from my existing python scripts and over to my Google Home Mini.

    My question is, do you have this project setup in Git? My intention is to fully automate the build of HA and a similar type of Athan automation using Ansible and documenting installation. That way, any non-tech user can simply run one script and be on their way.

    Please let me know inshallah. It would be greatly beneficial to my community.

    Salam alaikum

      1. Salam brother

        I’m in UK and want to have something similar
        Any clue what to do and where to start or any video showing step by step

        Totally new to all this

        1. Walikum Salam,

          I am also in the UK.
          I don’t think there is any specific video showing step by step how to do this specifically for Athan, but there are quite a few of getting started video guides for Home Assistant on YouTube.
          I would advise starting with those, so you can become familiar with how this works.

  7. salam
    can you please advise what raspberry pi module will be best suited for this application? I don’t plan on anything more than automate the call to prayers and maybe some basic home automation here and there. With that said, I rather not buy the latest and greatest pi if I don’t have to.

    1. I personally use a Raspberry Pi 3 for HomeAssistant and haven’t had any issues so far and it hardly breaks a sweat. That said, I don’t have a huge amount of automation at the moment.
      If you are only using it for the Athan, it might be OK on a Raspberry Pi 2. I’m not really sure, to be honest. It would probably be best to check on the HomeAssistant forums.

      The Athan automation isn’t really a resource-intensive operation so if the base installation of HomeAssistant runs the Pi smoothly, it would probably be fine for adding just the Athan automation and related sensors.

  8. @M. Hamzah Khan. i am using your automation. everything is perfect. and triggers on time.
    I just want to know that, If i want little time offset, then how to do that.
    i tried
    – platform: template
    value_template: ‘{{ states.sensor.time.state == states(“sensor.asr”) +300 }}’
    like this. but not working.
    Please reply.


  9. Salam guys,

    it will be very helpful if you guys share some basic details how to get start with this? where to put this code? I am not a professional programmer but I know some stuff so with starting tips I can get through.


  10. Thanks for this – works very well.
    question: is volume action still working for you? I have it set but it doesn’t seem to be changing volume when executing automation,..

    1. Assalamu’Alaikum,

      Yes the volume action still seems to work for me. Have you tried changing the logging to a bit more verbose so you can see if the volume control action was sent?

  11. I am trying to convert the prayer timings from 24 hr to 12 hrs, I am simply displaying the prayer time entities in Lovelace. How can I convert the timings on the frontend to 12 hours ?

  12. Recently received the below error:

    “The islamic_prayer_times platform for the sensor integration does not support platform setup. Please remove it from your config.”

    Has anyone else run into this?Any suggested solutions?

  13. Brother, Thanks for this utility. I’m new to Home Assistant and just added it to my Synology NAS. Could you help in what section do I need to place this code?

    Also, I’m based out of Toronto, Canada. Is there any other changes I have to made in the above script to make it working for me?

    1. Salam,
      This is great! It simplifies setup significantly. I’ll be switching my HA and my parents HA instance to using your custom component.
      Thank you so much for sharing it!

    2. Assalam o alikum,

      Hope you are doing well.

      I am looking to automate azan using Home Assistant but I am a newbie without any coding experience. I understand you would be busy but happy to pay for your help. Hoping to share the code publicly for everyone to use.

      Let me know if you interested.


  14. HA dropped the support for Azan plugin in the last few updates. Although you can probably still install it directly from the git repo. A few months back I ended up using Azan and a few more projects and I cooked up my own extension for HA. So thank you for Azan plugin as its a great starting place if you wish to get started on automations based on prayer timings

  15. Assalam o alikum. really thankful for your help. i have copied and pasted this script and am getting this error “Message malformed: extra keys not allowed @ data[‘sensor’]” . any help is appreciated. thanks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.