Hanafi --- islamic_prayer_time

I got it finally working. Seems to formatting issues in yaml. I copied your config to the sensor.yaml file and then played around with the indent. Now to Automation and testing. Presume you have the automation running by now. I am trying to pass the media to my TV (Android ADB Command). I have 2 TV at home and they are mostly on. Need to get a speaker that can be integrated with HASS

IF you can share the automation that would be really helpful especially the template.

I am still working on that. for a HASS solution you can try mopidy. for a solution on a seperate pi or docker, try volumio.

Thanks @Gadgets, used your solution to switch over from Islamic Prayer Times to Al Adhan API. Here are my configuration files. Replace all the <use yours> in the files.

configuration.yml

homeassistant:
  latitude: <use yours>
  longitude: <use yours>
  elevation: <use yours>
  unit_system: <use yours>
  time_zone: <use yours>

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
discovery:
media_extractor:
sun:

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'

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

  - platform: template
    sensors:
      fajr:
        friendly_name: 'Fajr'
        value_template: '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Fajr"] | timestamp_custom("%H:%M") }}'
      sunrise:
        friendly_name: 'Sunrise'
        value_template: '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Sunrise"] | timestamp_custom("%H:%M") }}'
      dhuhr:
        friendly_name: 'Dhuhr'
        value_template: '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Dhuhr"] | timestamp_custom("%H:%M") }}'
      asr:
        friendly_name: 'Asr'
        value_template: '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Asr"] | timestamp_custom("%H:%M") }}'
      maghrib:
        friendly_name: 'Maghrib'
        value_template: '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Maghrib"] | timestamp_custom("%H:%M") }}'
      isha:
        friendly_name: 'Isha'
        value_template: '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Isha"] | timestamp_custom("%H:%M") }}'
      midnight:
        friendly_name: 'Midnight'
        value_template: '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Midnight"] | timestamp_custom("%H:%M") }}'
     tahajjud:
       friendly_name: 'Tahajjud'
       value_template: '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Imsak"] | timestamp_custom("%H:%M") }}'
  
# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

automation.yml

- action:
  - alias: 'Azan'
    data:
      entity_id: media_player.speaker
      media_content_id: http://praytimes.org/audio/adhan/Sunni/Adhan%20Makkah.mp3
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.speaker
      volume_level: '0.6'
    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.fajr"), "%Y-%m-%d %H:%M")) }}'
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.dhuhr"), "%Y-%m-%d %H:%M")) }}'
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.asr"), "%Y-%m-%d %H:%M")) }}'
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.maghrib"), "%Y-%m-%d %H:%M")) }}'
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.isha"), "%Y-%m-%d %H:%M")) }}'
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.tahajjud"), "%Y-%m-%d %H:%M")) }}'

- alias: "Play MP3 after 10 minutes of Maghrib Adhan"
  trigger:
    - platform: template
      value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.maghrib"), "%Y-%m-%d %H:%M")) + 600 }}' # Add 600s=10 minutes. Subtract for before Adhan.
  action:
  - alias: ''
    data:
      entity_id: media_player.speaker
      media_content_id: <MP3 URL>
      media_content_type: audio/mp3
    service: media_extractor.play_media
  - data:
      entity_id: media_player.speaker
      volume_level: '0.6'
    service: media_player.volume_set
2 Likes

thanks. this is great.

how do you add card for this player time ? in lovelace UI ?

Thanks, this was great. I was able to set up sensors with the correct time for my location.

Also for those with Echo or Amazon devices, you can install custom component HACS and install the Alexa Media Player Integration in both HACS and Home Assistant and use the following code in automations after “Azan”

  - alias: 'Azan'
    data:
      entity_id: media_player.your_echo_dot
      media_content_type: APPLE_MUSIC
      media_content_id: My playlist Adhan
    service: media_player.play_media

Note, I used APPLE_MUSIC as the service and a custom playlist named Adhan. I was not able to get Alexa service to play mp3. Alternatively you can use AMAZON_MUSIC service to play a playlist you have created on amazon music I could only find one Adhan on Amazon_Music

Slms.

I set up volumio on a separate pi. then enables media player in the configuration.yaml:

media_player:

i enabled discovery and the card was now available.

Salam Brother. Sensor configuration works great. automation does not work, it does not start automatically when azan prayer calls. something to do with the value template. can you please assist. thanks

Hi all,

Am using the default integration within HA for Islamic Prayer Times. However, the time does not seem correct. I believe it did not take into account the timezone set in HA. Anything can be done to correct it?

https://blog.hamzahkhan.com/tag/hassio/

Brother. Follow this code by Mr Hamzah. It works. need to change latitude, longitude, method, and for the media you change to your own entity_id. Hope yuo make it.

thanks

Remember to remove islamic prayer times in your intergration.

you need to post your automation yaml

thank you. shame though since there already is an integration but it failed to work correctly, unfortunately not that savvy enough to help fix the code. but the link you gave me looks good. thanks!

I downloaded the Adhaan and stored it on my volumio. That way if I lose internet, I will still have Adhaan.
Also, note that for maghrib use sunset (see my code below) instead of the sensor:

  • id: ‘1589102153557’
    alias: Dhuhr Adhaan
    description: ‘’
    trigger:
    • platform: template
      value_template: ‘{{ (strptime(states(“sensor.time”), “%H:%M”)) == (strptime(states(“sensor.dhuhr”),
      “%H:%M”)) }}’
      condition: []
      action:
    • data:
      entity_id: media_player.volumio
      media_content_id: http://192.xx.xx.xx:3000/api/v1/commands/?cmd=playplaylist&name=Adhaan
      media_content_type: music
      entity_id: media_player.volumio
      service: media_player.play_media
  • id: ‘1589102307791’
    alias: Asr Adhaan
    description: ‘’
    trigger:
    • platform: template
      value_template: ‘{{ (strptime(states(“sensor.time”), “%H:%M”)) == (strptime(states(“sensor.asr”),
      “%H:%M”)) }}’
      condition: []
      action:
    • data:
      entity_id: media_player.volumio
      media_content_id: http://192.xx.xx.xx:3000/api/v1/commands/?cmd=playplaylist&name=Adhaan
      media_content_type: music
      entity_id: media_player.volumio
      service: media_player.play_media
  • id: ‘1589102357875’
    alias: Isha Adhaan
    description: ‘’
    trigger:
    • platform: template
      value_template: ‘{{ (strptime(states(“sensor.time”), “%H:%M”)) == (strptime(states(“sensor.isha”),
      “%H:%M”)) }}’
      condition: []
      action:
    • data:
      entity_id: media_player.volumio
      media_content_id: http://192.xx.xx.xx:3000/api/v1/commands/?cmd=playplaylist&name=Adhaan
      media_content_type: music
      entity_id: media_player.volumio
      service: media_player.play_media
  • id: ‘1589102451359’
    alias: Maghrib Adhaan
    description: ‘’
    trigger:
  • id: ‘1589102744527’
    alias: Fajr Adhaan
    description: ‘’
    trigger:
    • platform: template
      value_template: ‘{{ (strptime(states(“sensor.time”), “%H:%M”)) == (strptime(states(“sensor.fajr”),
      “%H:%M”)) }}’
      condition: []
      action:
    • data:
      entity_id: media_player.volumio
      media_content_id: http://192.xx.xx.xx:3000/api/v1/commands/?cmd=playplaylist&name=FajrAdhaan
      media_content_type: music
      entity_id: media_player.volumio
      service: media_player.play_media

How do you add code in a “code box”?

Does anyone know how i could integrate these times?

I have got it working with the aladhan API but struggling with this

https://www.moonsighting.com/time_json.php?year=2020&tz=Asia/Riyadh&lat=26.574848&lon=50.0105216&method=0&both=false&time=0

…these are times for the whole year

I’ve managed to get the times via another API but still interested to know how to work with the above if anyone knows

We use actual sightings instead of calculated. However, I think that you could look at my example. it may help. My current experiment is to pull the database locally instead of using the API.

Do you mind sharing which API please?
I’m trying to use the same website but as it’s the whole year, I don’t know how to get it to show only the current day.
If you do get it working, please let me know.

Click on the button on the post/reply box ruler that looks like </>