Question about template sensors after 0.81.0 update

I noticed in the release notes the following comment

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.

So would this be the correct change?
Add - entity_id: zwave.fibaro_motion_backyard

  - platform: template
    sensors:
      fibaro_motion_backyard_battery: # Fibaro Motion Battery Level #
        friendly_name: Fibaro Motion Backyard Battery
        entity_id: zwave.fibaro_motion_backyard  #<---Added entity_id
        device_class: battery
        value_template: >
          {% if states.zwave.fibaro_motion_backyard.state and states.zwave.fibaro_motion_backyard.attributes.battery_level is defined %}
            {{ states.zwave.fibaro_motion_backyard.attributes.battery_level | float }}
          {% else %}
            0.0
          {% endif %}
        unit_of_measurement: "%"

If you see a warning about your template sensor in the log, you should add the entity.

Looks like the warning shows when using sensor attributes in the sensor.

1 Like

Is the zwave entity the correct entity to add?
Looks like I likely didn’t need to change it because the entity is clearly listed in the template but it can’t hurt to add either way right?

Not sure, but i think it doesn’t eat bread. :slightly_smiling_face:

1 Like

Thanks, had to look that one up.

http://languagehat.com/it-doesnt-eat-bread/

That’s what I’ve seen too and really it makes no sense to me that it does this… anyway, I just added them and the errors went away.

I just updated to 0.81.0 (HassIO) and got the same log entry for the below two sensors. Since these relate to a group of entities (and I’m no good at templates) how would I fix them?

sensor:
  - platform: template    # determine if today is selected as a watering day for program 1
    sensors:
      retic_program1_watering_day:
        value_template:  >
          {% set sensor_names = [ 'monday', 'tuesday', 'wednesday','thursday','friday','saturday','sunday'] %}
          {% set today_name = sensor_names[now().weekday()] %}
          {% set entity_id = 'input_boolean.retic_program1_'+today_name %}
          {{ is_state(entity_id, 'on') }}

      retic_program2_watering_day:
        value_template:  >
          {% set sensor_names = [ 'monday', 'tuesday', 'wednesday','thursday','friday','saturday','sunday'] %}
          {% set today_name = sensor_names[now().weekday()] %}
          {% set entity_id = 'input_boolean.retic_program2_'+today_name %}
          {{ is_state(entity_id, 'on') }}

Based on your code here it looks like you are just setting based on the day of the week from 7 different input_booleans. So if you are getting the warning that the code can’t figure out the correct entities then you can just list them. It will fire when any of them update but the sensor will only update from the correct input boolean so they may fire for update but not change value. For example if the input boolean for monday changes on any day other than monday it will update but not change.

entity_id: input_boolean.retic_program1_monday, input_boolean.retic_program1_tuesday, input_boolean.retic_program1_wednesday, input_boolean.retic_program1_thursday, input_boolean.retic_program1_friday, input_boolean.retic_program1_saturday, input_boolean.retic_program1_sunday

I am not sure if there is a fancy way to wildcard the list, my search reveals there is not but I might be missing something.

that seems to have stopped the log entries so hopefully it works, thank you!

1 Like