Template sensor not updating after 0.81.0

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.

In the release notes:

  • 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.

1 Like

Having the same problem.
This template sensor have been working for over a year but after upgrading to 0.81 the result is Unknown.

  • platform: template
    sensors:
    template_brandvarnare_mellanvaning_hallen_battery_level:
    friendly_name: ‘Batteri’
    icon_template: mdi:battery
    unit_of_measurement: ‘%’
    value_template: ‘{{ states.zwave.brandvarnare_mellanvaning_hallen.attributes.battery_level }}’

Any suggestions?

Just added the entity_id row and it worked!

  • platform: template
    sensors:
    template_vattensensor_koket_diskbank_battery_level:
    friendly_name: “Batteri”
    icon_template: mdi:battery
    entity_id: zwave.vattensensor_koket_diskbank
    unit_of_measurement: ‘%’
    value_template: “{{ states.zwave.vattensensor_koket_diskbank.attributes.battery_level }}”

I actually did read the change log, but didn’t interpret it that way, which was obviously wrong :slight_smile:

I followed the tip with the “Time & Date” component and added the sensor.time to “entity_id” and now it works again. Thanks!

If anyone need a fix this worked for me:

 - platform: template
    sensors:
      day_interval:
        friendly_name: "Tid"
        entity_id: sensor.time
        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 %}

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?

Thanks in advance.

1 Like

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.

Yes my log was flooded with errors so I went through everything and added entity id’s. All good now.

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’.


I have added the entity_id: sensor.time and waiting rule to trigger and work.

Do you also have sensor.time in your environment?

1 Like

Yes I have sensor.time and it should trigger tomorrow as tomorrow is day for my weekly garbage pickup.

As today was weekly garbage day, it worked perfectly. Thank you.

1 Like