Since 0.115 (afaik) some of my template sensors has stopped updating.
This example below is very odd as it updates when it switches to “night”.
When I manually trigger an update of template sensors from the config page it updates to the correct value, same goes if I run it through dev tools.
So something related to how template sensors are triggered in 0.115, or possible even 0.114 I’m not 100% sure.
Until we can find the root cause of this, is there any simple workaround to have this particular sensor updating every 1 minute?
day:
friendly_name: Period of the Day
value_template: >-
{% if now().strftime('%T') > strptime('22:30:00', '%T') or now().strftime('%T') < strptime('05:00:00', '%T') %}
night
{% else %}
{% if now().strftime('%T') >= strptime('05:00:00', '%T') and now().strftime('%T') < strptime('08:30:00', '%T') %}
morning
{% elif now().strftime('%T') > strptime('12:00:00', '%T')
and (
(states.sun.sun.attributes.elevation | float < 11 and states.sensor.average_house_luminance.state | int < 50)
or
(states.sun.sun.attributes.elevation | float < 8 and states.sensor.dark_sky_cloud_coverage.state | int > 50)
or
states.sun.sun.attributes.elevation | float < 4
) %}
evening
{% else %}
day
{% endif %}
{% endif %}
Thank you for your reply @finity, funny thing is I rewrote the template yesterday evening so it used sensor.time instead of now() and that made it work again!
Here’s my working version of it.
{% if strptime(states('sensor.time'), '%T') > strptime('22:30', '%T') or strptime(states('sensor.time'), '%T') < strptime('05:00', '%T') %}
night
{% else %}
{% if strptime(states('sensor.time'), '%T') >= strptime('05:00', '%T') and strptime(states('sensor.time'), '%T') < strptime('08:30', '%T') %}
morning
{% elif strptime(states('sensor.time'), '%T') > strptime('12:00', '%T')
and (
(states.sun.sun.attributes.elevation | float < 11 and states.sensor.average_house_luminance.state | int < 50)
or
(states.sun.sun.attributes.elevation | float < 8 and states.sensor.dark_sky_cloud_coverage.state | int > 50)
or
states.sun.sun.attributes.elevation | float < 4
) %}
evening
{% else %}
day
{% endif %}
{% endif %}
Maybe the cleanest version would be setting a variable like you did and then use that in the code instead of getting the object each time it’s needed.