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}}'