Hi All,
I have this json file:
calendar.json:
{
"json_calendars": {
"events": {
"2/14":"Valentine's Day",
"4/1":"April Fool's Day",
"5/4":"Dodenherdenking",
"5/5":"Bevrijdingsdag",
"7/4":"Independence Day",
"9/2":"Special Day P&K",
"11/23":"Black Friday",
"11/24":"Black Friday",
"11/25":"Black Friday",
"11/26":"Black Friday",
"11/27":"Black Friday",
"12/31":"New Year's Eve"
},
"birthday": {
"2/14":"Not show on forum",
"12/31":"Not show on forum"
},
"holidays": {
"2/14":"Not show on forum",
"12/31":"Not show on forum"
}
}
}
and those 3 sensors
- sensor:
name: "Birthday test"
unique_id: "93a52226-7ba7-494b-bfdf-817902920d70"
command: "cat /config/package/json/calendar.json"
scan_interval: 21600
value_template: >-
{% set today = now().month ~ '/' ~ now().day %}
{% set birthday = value_json.json_calendars.birthday[ today ] %}
{% if birthday | trim == "" %}
{% set birthday = "Nothing" %}
{% endif %}
{{ birthday }}
- sensor:
name: "Holiday"
unique_id: "490f80c3-7bde-47c0-a6fa-c2ed6d742926"
command: "cat /config/package/json/calendar.json"
scan_interval: 21600
value_template: >-
{% set today = now().month ~ '/' ~ now().day %}
{% set holiday = value_json.json_calendars.holiday[ today ] %}
{% if holiday | trim == "" %}
{% set holiday = "Nothing" %}
{% endif %}
{{ holiday }}
- sensor:
name: "Events"
unique_id: "716b7f41-ac6d-4df2-b01a-31b2ccf9e138"
command: "cat /config/package/json/calendar.json"
scan_interval: 21600
value_template: >-
{% set today = now().month ~ '/' ~ now().day %}
{% set events = value_json.json_calendars.events[ today ] %}
{% if events | trim == "" %}
{% set events = "Nothing" %}
{% endif %}
{{ events }}
They working. I can see the input from json file in the sensor when using them in UI.
Only when I restart HA I see those errors in the log:
2023-07-11 07:58:26.766 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute '7/11' when rendering '{% set today = now().month ~ '/' ~ now().day %} {% set birthday = value_json.json_calendars.birthday[ today ] %}
{% if birthday | trim == "" %}
{% set birthday = "Nothing" %}
{% endif %}
{{ birthday }}'
2023-07-11 07:58:26.804 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute '7/11' when rendering '{% set today = now().month ~ '/' ~ now().day %} {% set holiday = value_json.json_calendars.holiday[ today ] %}
{% if holiday | trim == "" %}
{% set holiday = "Nothing" %}
{% endif %}
{{ holiday }}'
2023-07-11 07:58:26.849 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute '7/11' when rendering '{% set today = now().month ~ '/' ~ now().day %} {% set events = value_json.json_calendars.events[ today ] %}
{% if events | trim == "" %}
{% set events = "Nothing" %}
{% endif %}
{{ events }}'
How can I solve this?
Thanks for helping!