Hanafi --- islamic_prayer_time

@shehzan does the automation work? and are you able to add as card in your dashboard? I am verry interested switching from Islamic Prayer Time to Aladhan because it have Turkish Diyanet calculation method…

hello, ladies and gentlemen, boys and girls,

I would like to use the islamic_prayer_time integration but the application is not working at the right time, and yet I have the correct times (and I have the correct localization too) of prayers on the start page. I don’t understand, what is the process to use this integration?

This is what i get in Home Assistant :
id: ‘1632078662400’
alias: TESTTTTTTT
description: ‘’
trigger:

  • platform: state
    entity_id: sensor.asr_prayer
    for:
    hours: 0
    minutes: 0
    seconds: 30
    milliseconds: 0
  • platform: state
    entity_id: sensor.dhuhr_prayer
    for:
    hours: 0
    minutes: 0
    seconds: 30
    milliseconds: 0
  • platform: state
    entity_id: sensor.fajr_prayer
    for:
    hours: 0
    minutes: 0
    seconds: 30
    milliseconds: 0
  • platform: state
    entity_id: sensor.isha_prayer
    for:
    hours: 0
    minutes: 0
    seconds: 30
    milliseconds: 0
  • platform: state
    entity_id: sensor.maghrib_prayer
    for:
    hours: 0
    minutes: 0
    seconds: 30
    milliseconds: 0
    condition: []
    action:
  • service: script.save_etat_initial
  • scene: scene.nouvelle_scene_ampoule_verte_test (a service to put in green my light)
  • service: script.flashing_lights_10_times (a service for flashing my light)
  • delay:
    hours: 0
    minutes: 0
    seconds: 5
    milliseconds: 0
  • scene: scene.before
    mode: single

When I test this automation, it makes my bulb flash and the color is changed and I also have the memory of the state of my bulb (so no problem on my side), the ONLY problem comes from the fact that this automation does NOT launch at the correct times.

Just started noticing, my prayer times are showing unavailable on my dashboard. Also no no adhan trigers happening.

found the following in the log. I am not sure exactly what is going on with the sensors, appear to be a time date format issue. on HA 2002.6.2

Is anyone else having the same issue?

Logger: homeassistant.helpers.template
Source: helpers/template.py:1862
First occurred: 7:13:07 PM (152 occurrences)
Last logged: 7:30:07 PM

Template variable error: 'None' has no attribute 'attributes' when rendering '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Asr"] | timestamp_custom("%H:%M") }}'
Template variable error: 'None' has no attribute 'attributes' when rendering '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Isha"] | timestamp_custom("%H:%M") }}'
Template variable error: 'None' has no attribute 'attributes' when rendering '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Midnight"] | timestamp_custom("%H:%M") }}'
Template variable error: 'None' has no attribute 'attributes' when rendering '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Maghrib"] | timestamp_custom("%H:%M") }}'
Template variable error: 'None' has no attribute 'attributes' when rendering '{{ states("sensor.date") }} {{ states.sensor.prayer_times.attributes.data.timings["Imsak"] | timestamp_custom("%H:%M") }}'
Logger: homeassistant.components.template.trigger
Source: components/template/trigger.py:60
Integration: Template (documentation, issues)
First occurred: 7:13:07 PM (5 occurrences)
Last logged: 7:13:07 PM

Error initializing 'template' trigger for 'Adhan': ValueError: Template error: strptime got invalid input '2022-06-05T09:47:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.fajr_prayer"), "%Y-%m-%d %H:%M")) }}' but no default was specified
Error initializing 'template' trigger for 'Adhan': ValueError: Template error: strptime got invalid input '2022-06-05T18:21:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.dhuhr_prayer"), "%Y-%m-%d %H:%M")) }}' but no default was specified
Error initializing 'template' trigger for 'Adhan': ValueError: Template error: strptime got invalid input '2022-06-05T21:56:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.asr_prayer"), "%Y-%m-%d %H:%M")) }}' but no default was specified
Error initializing 'template' trigger for 'Adhan': ValueError: Template error: strptime got invalid input '2022-06-06T01:21:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.maghrib_prayer"), "%Y-%m-%d %H:%M")) }}' but no default was specified
Error initializing 'template' trigger for 'Adhan': ValueError: Template error: strptime got invalid input '2022-06-06T02:55:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.isha_prayer"), "%Y-%m-%d %H:%M")) }}' but no default was specified

There have been warnings since 2021.10 that certain templates, including as_timestamp() and timestamp_custom(), will require defaults. Update you templates with the necessary defaults, or better yet use a cleaner template:

{{today_at(state_attr('sensor.prayer_times','data').timings["Asr"]).strftime("%F %R") }}

{{ now() >= states("sensor.fajr_prayer")|as_datetime|as_local }}

sir

i’ve having problems with the value template you provided.
Ive got:
bad indentation of a mapping entry
value_template: '{{ today_at(sta …

Im using this template:
platform: rest
value_template: ‘{{ value_json[“data”][“meta”][“method”][“name”].title() }}’

platform: template
sensor:
value_template: ‘{{ states.sensor.prayer_times.attributes.data.timings[“Fajr”] |
timestamp_custom("%H:%M") }}’

How can I change or create new template.

Thank you very much.

Assuming you’re using the API from earlier in this thread your configuration should look something like:

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

  - platform: template
    sensors:
      fajr_prayer_time:
        friendly_name: "Fajr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Fajr']).strftime('%H:%M') }}
      asr_prayer_time:
        friendly_name: "Asr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Asr']).strftime('%H:%M') }}    

      ... the rest of your sensors...

1 Like

This solved the problem. Thank you so much! Do you know how to show prayer times in 12h format instead of 24h?

You will need to change the strftime formatting values at the end of the template. There are a few option for a 12-hr time depending on exactly how you want it to look:

“%I:%M” = 05:12
“%-I:%M %p” = 5:12 AM

1 Like

Thank you, thank you and thank you very much. it works.

My God bless you and family.

thank you but after changing the time format automation stopped again!

here’s how my automation script looks like:

`alias: Magrib Adhan
description: ‘’
trigger:

  • platform: template
    value_template: ‘{{ states.sensor.maghrib_prayer_time.state == states.sensor.time.state }}’
    condition: []
    action:
  • data:
    volume_level: 0.5
    service: media_player.volume_set
    target:
    entity_id:
    - media_player.master_bedroom_speaker
  • alias: ‘’
    data:
    entity_id: media_player.master_bedroom_speaker
    media_content_id: https://url.duckdns.org/local/azaan.mp3
    media_content_type: music
    service: media_player.play_media
    mode: single`

By changing the output of the sensor to 12hr format it will no longer match the output of sensor.time.

It is still possible to use a template trigger, it’s just a bit more involved. The following template assumes you are using the option that includes am/pm:

alias: Magrib Adhan
description: ‘’
trigger:
  - platform: template
    value_template: >
      {% set x = states('sensor.maghrib_prayer_time') %}
      {{ now() >= today_at(strptime(x, "%I:%M %p").time()) }}
condition: []
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.5
    target:
      entity_id: media_player.master_bedroom_speaker
  - service: media_player.play_media
    data:
      media_content_id: https://url.duckdns.org/local/azaan.mp3
      media_content_type: music
    target:
      entity_id: media_player.master_bedroom_speaker
mode: single
1 Like

platform: template
value_template: >
{% set x = states(‘sensor.maghrib_prayer_time’ %}
{{ now() >= today_at(strptime(x, “%I:%M %p”).time()) }}

i got an error while saving the above template.
message malformed: invalid template (TemplateSyntaxError: unexpected ‘}’, expected ‘)’) for dictionary value @ data[‘value_template’]

Please advice. Ive tried removing the colon but no success.

Thank you

You are missing a ) at the end of states(‘sensor.maghrib_prayer_time'

Thank you for the fast respond. It really works.
Anyway Im new to HOme Asistant and im learning day by day.

How can I intergrate all the prayer sensor into 1 automation like the below example.

eg;
alias: Adhan
description: ‘’
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”) }}’

Should I do the same as the above? with the new template you given.

Thank you again for your assistant.

Yes, use the template from my previous post to set up a trigger for each prayer sensor.

Can’t thank you enough for this! Jazaakallahi khairan.

Salam,

How can I make the hijri_date_text have the Arabic month name between the day and year? doesn’t matter if it is RTL or LTR?

I could use any piece of advice.

Thanks in advance

##################################################
#                                                #
#   HIJRI DATE & PRAYER TIMES                    #
#                                                #
##################################################


- platform: rest
  name: Hijri Calendar
  json_attributes:
    - data
  #resource: http://api.aladhan.com/v1/gToH?adjustment=1&date=07-11-2022
  resource: http://api.aladhan.com/v1/timings?latitude=xx.xxxxxxx&longitude=xx.xxxxx&method=1&school=0
  value_template: '{{ value_json["data"]["meta"]["method"]["name"].title() }}'
  scan_interval: 86400    

- platform: template
  sensors:
    hijri_date:
      friendly_name: 'Hijri Date'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.date.hijri.date}}'
    hijri_day_num:
      friendly_name: 'Hijri Day'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.date.hijri.day}}'
    hijri_month_num:
      friendly_name: 'Hijri Month'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.date.hijri.month["number"]}}'
    hijri_year_num:
      friendly_name: 'Hijri Year'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.date.hijri.year}}'
    hijri_month_eng:
      friendly_name: 'Hijri Month ENG'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.date.hijri.month["en"]}}'
    hijri_month_ara:
      friendly_name: 'Hijri Month ARA'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.date.hijri.month["ar"]}}'
    hijri_holidays:
      friendly_name: 'Hijri Holidays'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.date.hijri.holidays}}'
    hijri_date_text:
      friendly_name: 'Hijri_Date'
      value_template: '{{ [states("sensor.hijri_day_num"),states("sensor.hijri_month_ara"),states("sensor.hijri_year_num")] | join(" ") }}'

It has been a long time since this started, I forgot to post my latest code, so here it is:

WIP: Need to create Days to Ramadan - Countdown timer.

Input number - day adjustment
input_number:
  hijri_date_adjustment:
    name: Hijri Date Adjustment
    icon: mdi:calendar-expand-horizontal-outline
    min: -2
    max: 2
    step: 1
    mode: box
Hijri date data and variables
#############################################################################
#                                                                           #
#                              DATE-TIME-HIJRI                              #
#                                VARIABLES                                  #
#############################################################################


var:
  hijri_months_ara:
    friendly_name: "Hijri Arabic Months"
    value_template: >-
      {% set hijri = ["محرم", "صفر", "ربيع الأول", "ربيع الآخر", "جمادى الأولى", "جمادى الآخرة", "رجب", "شعبان", "رمضان", "شوال", "ذو القعدة", "ذو الحجة"] %}
      {{ hijri }}
    tracked_entity_id:
      - sensor.hijri_date

  gregorian_months_ara:
    friendly_name: "Gregorian Arabic Months"
    value_template: >-
      {% set gregorian = ["كانون الثاني", "شباط", "آذار", "نيسان", "أيار", "حزيران", "تموز", "آب", "أيلول", "تشرين الأول", "تشرين الثاني", "كانون الأول"] %}
      {{ gregorian }}
    tracked_entity_id:
      - sensor.hijri_date
Hijri Calendar
##################################################
#                                                #
#   ISLAM related matters                        #
#   Prayer times - Hijri calndar - Ramadan       #
#                                                #
##################################################

sensor:
- platform: rest
  name: Hijri Calendar
  json_attributes:
    - data
  #resource: http://api.aladhan.com/v1/gToH?adjustment=1&date=07-11-2022
  #resource: http://api.aladhan.com/v1/timings?adjustment=1&latitude=31.963127&longitude=35.822627&method=1&school=0
  resource_template: >-
    {% set url_start = 'http://api.aladhan.com/v1/gToH?' %}
    {% set adjustment = '&adjustment=' + states('input_number.hijri_date_adjustment') | int | string %}
    {% set today = '&date=' + now().strftime('%d-%m-%Y') %}
    {% set my_url = url_start + adjustment + today   %}
    {{ my_url }}
  value_template: '{{ value_json["data"]["hijri"]["date"] }}'
  scan_interval: 86400    

# {% set my_longitude = '&longitude=' + '35.822627' %}
# {% set my_latitude =  '&latitude=' + '31.963127' %}


- platform: template
  sensors:
    hijri_date:
      friendly_name: 'Hijri Date'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.hijri.date}}'
    hijri_day_num:
      friendly_name: 'Hijri Day'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.hijri.day}}'
    hijri_month_num:
      friendly_name: 'Hijri Month'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.hijri.month["number"]}}'
#      value_template: '{{ states.sensor.hijri_calendar.attributes.data.hijri.month["number"]}}'
    hijri_year_num:
      friendly_name: 'Hijri Year'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.hijri.year}}'
    hijri_month_eng:
      friendly_name: 'Hijri Month ENG'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.hijri.month["en"]}}'
    hijri_month_ara:
      friendly_name: 'Hijri Month ARA'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.hijri.month["ar"]}}'
    hijri_holidays:
      friendly_name: 'Hijri Holidays'
      value_template: '{{ states.sensor.hijri_calendar.attributes.data.hijri.holidays}}'
    hijri_date_text:
      friendly_name: 'Hijri_Date'
      value_template: '{{ [states("sensor.hijri_day_num"),states("sensor.hijri_month_ara"),states("sensor.hijri_year_num")] | join(" ") }}'
Automation to refresh Hijri date
alias: Refresh Hijri Date
description: Refreshes Hijri date at midnight
trigger:
  - platform: time
    at: "00:00:01"
  - platform: homeassistant
    event: start
condition: []
action:
  - service: rest.reload
    data: {}
mode: single

However, I am still getting some errors in the logs that I can’t find a way to supress or get rid of them, anyone with advice would be much welcome:

Log Errors
I might have faced this case before (here) where attributes are not computed before the entity state, but this is Jason and the other case is related to normal HA entities.

Log Error (1)
Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:393
First occurred: 17:38:01 (7 occurrences)
Last logged: 17:38:01

TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ states.sensor.hijri_calendar.attributes.data.hijri.month["number"]}}")' for attribute '_attr_native_value' in entity 'sensor.hijri_month_num'
TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ states.sensor.hijri_calendar.attributes.data.hijri.year}}")' for attribute '_attr_native_value' in entity 'sensor.hijri_year_num'
TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ states.sensor.hijri_calendar.attributes.data.hijri.month["en"]}}")' for attribute '_attr_native_value' in entity 'sensor.hijri_month_eng'
TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ states.sensor.hijri_calendar.attributes.data.hijri.month["ar"]}}")' for attribute '_attr_native_value' in entity 'sensor.hijri_month_ara'
TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ states.sensor.hijri_calendar.attributes.data.hijri.holidays}}")' for attribute '_attr_native_value' in entity 'sensor.hijri_holidays'
Log Error (2)
Logger: homeassistant.helpers.template
Source: helpers/template.py:576
First occurred: 17:37:59 (21 occurrences)
Last logged: 17:38:01

Template variable error: 'None' has no attribute 'attributes' when rendering '{{ states.sensor.hijri_calendar.attributes.data.hijri.month["number"]}}'
Template variable error: 'None' has no attribute 'attributes' when rendering '{{ states.sensor.hijri_calendar.attributes.data.hijri.year}}'
Template variable error: 'None' has no attribute 'attributes' when rendering '{{ states.sensor.hijri_calendar.attributes.data.hijri.month["en"]}}'
Template variable error: 'None' has no attribute 'attributes' when rendering '{{ states.sensor.hijri_calendar.attributes.data.hijri.month["ar"]}}'
Template variable error: 'None' has no attribute 'attributes' when rendering '{{ states.sensor.hijri_calendar.attributes.data.hijri.holidays}}'
2 Likes

This is great brother and thank you for your efforts to create. As far as the errors logs, I think you could get get resolving them if they are posted in configuration section of this community.

you can add ‘\u202B’ to the hijri date sensor:

'{{ '\u202B' +  [states("sensor.hijri_year_num"), states("sensor.hijri_month_ara"),states("sensor.hijri_day_num")] | join(" ") }}