Adhan Azan Automation Home Assistant

Salam all, thanks for all of the information posted by previous posters. I just recently got into Home Assistant and was working on getting this setup (previously was using Tasker on Android which worked OK, but was not 100% reliable). In the end, I ended up using a combination of the first post here and a post on another guide as well with some additional tweaks.

  1. I have 3 devices in my house - fortunately after adding them to a speaker group in the Google Home App, Home Assistant recognized that entity and I’m able to have it directly broadcast to that group to hit all of the speakers at the same time.

  2. For Hanafi timing, rather than using the built in prayer time sensor I instead use the Al-Adhan API (as mentioned by someone else here). You can customize it to your calculation method and school via this guide - https://aladhan.com/prayer-times-api.

  3. I have one automation for Fajr specifically (plays at a lower volume) and one for the remaining times. The sequence in each automation is set speakers to volume for athan, play athan, stop playing media (it takes the display back to the photo frame then), and then set volume back to baseline levels. I’ve also made some changes to pause TVs when athan is playing automatically.

After doing the above, it was triggering manually just fine but it was having trouble with the timed trigger so I made a couple of changes for that as well.

In the end, my configuration file looked like this:

default_config:
mobile_app:
tts:
  - platform: google_translate
group: !include groups.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
automation: !include automations.yaml

sensor:
  - platform: rest
    name: "Prayer Times"
    json_attributes:
      - data
    resource: "http://api.aladhan.com/v1/timings?latitude=INSERT_LATITUDE&longitude=INSERT_LONGITUDE&method=2&school=1"
    value_template: '{{ value_json["data"]["meta"]["method"]["name"].title() }}'
    scan_interval: 43200

  - platform: template
    sensors:
      fajr:
        friendly_name: 'Fajr'
        entity_id: sensor.time
        value_template: '{{ states.sensor.prayer_times.attributes.data.timings["Fajr"] | timestamp_custom("%H:%M") }}'
      dhuhr:
        friendly_name: 'Dhuhr'
        entity_id: sensor.time
        value_template: '{{ states.sensor.prayer_times.attributes.data.timings["Dhuhr"] | timestamp_custom("%H:%M") }}'
      asr:
        friendly_name: 'Asr'
        entity_id: sensor.time
        value_template: '{{ states.sensor.prayer_times.attributes.data.timings["Asr"] | timestamp_custom("%H:%M") }}'
      magrib:
        friendly_name: 'Magrib'
        entity_id: sensor.time
        value_template: '{{ states.sensor.prayer_times.attributes.data.timings["Maghrib"] | timestamp_custom("%H:%M") }}'
      isha:
        friendly_name: 'Isha'
        entity_id: sensor.time
        value_template: '{{ states.sensor.prayer_times.attributes.data.timings["Isha"] | timestamp_custom("%H:%M") }}'
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'time_date'

And my automation file looks like:

- id: '1517693010922'
  alias: Fajr Adhan
  trigger:
  - platform: template
    value_template: '{{ states.sensor.fajr.state == states.sensor.time.state }}'
  condition: []
  action:
  - data:
      entity_id: media_player.homespeakers
      volume_level: '0.2'
    service: media_player.volume_set
  - alias: ''
    data:
      entity_id: media_player.homespeakers
      media_content_id: WEB_ADDRESS_OF_DESIRED_ATHAN
      media_content_type: music
    service: media_player.play_media
  - delay: 00:05:00
  - data: {}
    entity_id: media_player.homespeakers
    service: media_player.turn_off
  - data:
      entity_id: media_player.homespeakers
      volume_level: '0.7'
    service: media_player.volume_set
  mode: restart
- id: '1517693010923'
  alias: Adhan
  trigger:
  - platform: template
    value_template: '{{ states.sensor.dhuhr.state == states.sensor.time.state }}'
  - platform: template
    value_template: '{{ states.sensor.asr.state == states.sensor.time.state }}'
  - platform: template
    value_template: '{{ states.sensor.magrib.state == states.sensor.time.state }}'
  - platform: template
    value_template: '{{ states.sensor.isha.state == states.sensor.time.state }}'
  condition: []
  action:
  - data:
      entity_id: media_player.homespeakers
      volume_level: '0.6'
    service: media_player.volume_set
  - alias: ''
    data:
      entity_id: media_player.homespeakers
      media_content_id: WEB_ADDRESS_OF_DESIRED_ATHAN
      media_content_type: music
    service: media_player.play_media
  - delay: 00:05:00
  - data: {}
    entity_id: media_player.homespeakers
    service: media_player.turn_off
  - data:
      entity_id: media_player.homespeakers
      volume_level: '0.7'
    service: media_player.volume_set
  mode: restart
1 Like