template:
- trigger:
- platform: time_pattern
hours: 0
minutes: 0
- platform: homeassistant
event: start
- platform: event
event_type: event_template_reloaded
binary_sensor:
- unique_id: zomertijd_binary
name: Zomertijd
picture: /local/season/summer.png
state: >
{{now().timetuple().tm_isdst == 1}}
- unique_id: wintertijd_binary
name: Wintertijd
picture: /local/season/winter.png
state: >
{{now().timetuple().tm_isdst == 0}}
- unique_id: christmas_time
name: Christmas time
state: >
{% set today = now().day %}
{% set month = now().month %}
{{month == 12 and today >= 24 or month == 1 and today <= 2}}
icon: >
mdi:{{iif(is_state('binary_sensor.christmas_time','on'),'string-lights','pine-tree')}}
sensor:
- unique_id: utc_offset
name: Utc offset
state: >
{{now().utcoffset().total_seconds()/3600}}
icon: >
{% set offset = now().utcoffset().total_seconds()/3600 %}
mdi:numeric-{{offset|int|abs}}
# many more sensors here
only the binary_templates show up as unknown, all other sensors, and sensors using another set of triggers before this are correct.
I moved all of these from being perfectly functional state based template sensors to the trigger based section, and have made sure there are no _2 suffixes, or .template_ variants because of that move
Could be that the sensor hasn’t triggered yet and therefore doesn’t have a value.
Have it past midninght or have you done a restart of HA or the template?
and, even when the state is actually correct, the icon template remains fixed on the pine-tree. See what happens after I flipped the icons to use, reloaded template entities, and a manual update entity:
icon: >
{% set today = now().day %} {% set month = now().month %}
{% if month == 12 and today >= 24 or month == 1 and today <= 2 %} mdi:pine-tree
{% else %} mdi:string-lights
{% endif %}
@Mariusthvdb
Sorry for resurrecting this old thread.
Did you get new insights on this? I also have issues with the template reload event and binary sensors.
What I figured out is that the template value is simply restored by the template reloaded event, in stead of processing the template state logic. So always the state before reloading.
This is super annoying if you try to debug a template, as changes made to the sensor state logic simply don’t have any effect when reloading the templates. Only other triggers ( e.g. the restart) will process the new state logic,
I think this is perfect default behavior, unless I explicitly add the template reloaded event as a trigger.