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
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.
sensor:
- platform: rest
name: "Prayer Times"
json_attributes:
- data
resource: "http://api.aladhan.com/v1/timings?latitude=52.587904&longitude=-0.1458179&method=3"
value_template: '{{ value_json["data"]["meta"]["method"]["name"].title() }}'
scan_interval: 86400
- platform: template
sensors:
fajr:
friendly_name: 'Fajr Prayer Time'
value_template: '{{ states.sensor.prayer_times.attributes.data.timings["Fajr"] | timestamp_custom("%H:%M") }}'
dhuhr:
friendly_name: 'Dhuhr Prayer Time'
value_template: '{{ states.sensor.prayer_times.attributes.data.timings["Dhuhr"] | timestamp_custom("%H:%M") }}'
asr:
friendly_name: 'Asr Prayer Time'
value_template: '{{ states.sensor.prayer_times.attributes.data.timings["Asr"] | timestamp_custom("%H:%M") }}'
magrib:
friendly_name: 'Magrib Prayer Time'
value_template: '{{ states.sensor.prayer_times.attributes.data.timings["Maghrib"] | timestamp_custom("%H:%M") }}'
isha:
friendly_name: 'Isha Prayer Time'
value_template: '{{ states.sensor.prayer_times.attributes.data.timings["Isha"] | timestamp_custom("%H:%M") }}'
automation:
- alias: "Fajr Athan"
initial_state: true
hide_entity: true
trigger:
- condition: template
value_template: '{{ states.sensor.time.state == states("sensor.fajr") }}'
action:
- service: media_player.volume_set
data_template:
entity_id: media_player.living_room_speaker
volume_level: 0.75
- service: media_player.play_media
data:
entity_id: media_player.living_room_speaker
media_content_id: https://s3.intahnet.co.uk/athan/fajr.mp3
media_content_type: audio/mp3
- alias: "Athan"
initial_state: true
hide_entity: true
trigger:
- 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") }}'
action:
- service: media_player.volume_set
data_template:
entity_id: media_player.living_room_speaker
volume_level: 0.75
- service: media_player.play_media
data:
entity_id: media_player.living_room_speaker
media_content_id: https://s3.intahnet.co.uk/athan/normal.mp3
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
I hope this is helpful for anyone else trying to achieve something similar.