I have used a template sensor to define time of day by doing the following:
- platform: template
sensors:
day_interval:
friendly_name: "Tid"
value_template: >
{% if now().hour in range(0, 6) %}
Nat
{% elif now().hour in range(6, 7) %}
Morgen
{% elif now().hour in range(7, 18) %}
Dag
{% elif now().hour in range(18, 21) %}
Aften
{% elif now().hour in range(21, 22) %}
AftenTidlig
{% elif now().hour in range(22, 24) %}
AftenSent
{% endif %}
I has been working just fine until last update. I donât get any errors in the logs and I have tried to restart multiple times without any difference.
Template sensors will no longer auto update if we canât find relevant entities in the template. Youâll want to review your template sensors and consider adding relevant entity_id entries or use the new homeassistant.update_entity service.
you need to add a entity_id to the template sensor. See the breaking changes in the blog for the latest update.
the problem is going to be that there is no easily accessible entity to use to update on. i had a similar situation and I created the date_time component and used the sensor.time created from that so that the template sensor will update every minute. Otherwise you have to somehow force an update of the sensor And I donât know how to do that yet. Maybe the instructions are in the template sensor docs for that.
Is it safe to assume that if I donât see any âUnknownâ values when I scan the States list in the Developer Tools, then I must not have any issues where I need to add the entity_id into my template sensor definitions?
I think I remember reading that you will also see an entry in the log to the effect of not being able to find a valid entity to update on or something to that effect.
I didnât see any âunknownâ in my list and also no errors, but the sensor was kind of stuck, so that was the only way I found out something was wrong. But perhaps I overlooked something.
Iâm not sure how this template worked before the update. now() has never been considered a state object so that shouldnât have worked. Thatâs always been a large topic in this forum.
I am also facing similar situation with Hassio version 0.79.3, below is the template that was working fine until I updated from older version of 0.7x but now not updating correctly. Below is section of my sensor code for garden garbage pickup day:
platform: template
sensors:
âŚ..
biweekly_garbage_day_today:
friendly_name: 'Green Garbage Day Today'
value_template: '{% if states.sensor.biweekly_garbage_week_now.state == "True" and now().isoweekday() == states.input_number.biweekly_green_garbage_day_select.state | int %}Yes{% else %}No{% endif %}'
See the value of sensor and template evaluation screen shot showing different values. When I did a restart on HA the value of sensor got updated to âNoâ.