Template Sensor Stopped Working

Afternoon All,

I’ve got a template sensor that shows the amount of rooms with motion and the amount of lights turned on. Now this used to be dynamic and change when states were changed, however for some reason it’s become static and only shows states on boot.

I’ll be honest I’m not sure what rev I was on when it last worked (as there seems to have been loads recently) but I can confirm it doesn’t work now on the latest build (well it doesn’t change when the states change).

- platform: template
  sensors:
    motion_count:
      value_template: >-
        {{ states.binary_sensor | selectattr('state', 'eq', 'on') | selectattr('attributes.device_class', 'eq', 'motion') | rejectattr('attributes.attribution', 'eq', 'Data provided by Ring.com') | list | count }}
    light_count:
      value_template: >-
        {{ states.light | selectattr('state', 'eq', 'on') | list | count }}

It was a release before 0.81.0 and you didn’t read the release notes before upgrading.

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.

Kind regards

m0wlheld

1 Like

What @m0wlheld said.
This is how you could change your template:

- platform: template
  sensors:
    motion_count:
      entity_id:
        - binary_sensor.abc
        - binary_sensor.def
      value_template: >-
        {{ states.binary_sensor | selectattr('state', 'eq', 'on') | selectattr('attributes.device_class', 'eq', 'motion') | rejectattr('attributes.attribution', 'eq', 'Data provided by Ring.com') | list | count }}
    light_count:
      value_template: >-
        {{ states.light | selectattr('state', 'eq', 'on') | list | count }}

replace abd / def with the sensors that should trigger this template

1 Like

You are correct I didn’t read through all of them. Thank you for the information, much appreciated.

Thank you very much.