Sensor does not update automaticallly


I have an issue, i try to make a light switch off after a before set time.
I am using a code snipet found on the forum as weel as an automation to make it happen, my issue is that the remaining time which i use as a trigger does not update automatically, but does update when i move the slider around, what am I missing ?

  - platform: time_date
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'
  - platform: template
        friendly_name: 'Time Remaining'
          - input_number.onoffminuteur
          - sensor.time
          - switch.chambre
        value_template: >
          {% if is_state('switch.chambre', 'on') %}
            {{ [ (states('input_number.onoffminuteur')|int - (as_timestamp(now()) - as_timestamp(states.switch.chambre.last_changed))/60)|round(0) ,0 ] | max }}
          {% else %}
          {% endif %}
        unit_of_measurement: "min"

    name: onoffminuteur
    initial: 60
    min: 1
    max: 190
    mode: slider

  - alias: 'eteint chambre'
      - platform: numeric_state
        entity_id : sensor.timerchambre
        below: 1
      service: switch.turn_off
        - switch.chambre

I can’t see any error nor updates on logs

You can’t use now() anymore as HA wont update that as it used to. There are mentions to it in the recent changelogs, but if you really want to continue updating on a per second/minute basis you will need to use the service homeassistant.update for the sensor, and use a time trigger automation to update it.

It never did.

However, that will change in version 0.117 when the presence of now() in a template will ensure the template is evaluated at least once every minute.


Remove the entire entity_id section. It was deprecated in 0.115 and is ignored by Home Assistant.

Add this line to your template as the first line):

{% set x = states('sensor.time') %}

It will cause the template to be evaluated every minute.

After you upgrade to 0.117, you can remove it because now() will ensure the template is evaluated once every minute.

1 Like

OK to be specific, you used to be able to specify sensor.time as an entity for a template sensor, now you cannot. Now you need to use the automation to update it.

That is not true.

the part that was removed was the “entity_id:” part to force the sensor to update if it couldn’t find any entities to update on (like when you use now() ). You could always use sensor.time in the template and it would work fine and update every minute. That hasn’t changed. You can still use sensor.time in the template and it will still update at least once a minute.

Apparently after 117 is released you won’t need to use it since it will update on now(). But…you can still use sensor.time even then.

My point is sensor.time has always been, is now, and always will be for the foreseeable future, valid.