entity_id
is deprecated in 0.115 so it’s already being ignored in that Template Sensor (and reports a warning in the log to remove all instances of entity_id
).
As opposed to all versions prior to 0.115, Home Assistant now knows that states.sensor
means every sensor in your system and will assign a listener to each and every sensor. That means if any one of those sensors changes state, it will cause the template to be evaluated.
So it will work without entity_id
but, compared to previous versions, the template is evaluated far more often. Some people have reported decreased performance notably when their system has many entities and they use states
in their template (listeners are assigned to all entities). In previous versions, only 5 listeners were assigned to your Template Sensor, one for each of the 5 entities listed in entity_id
. In 0.115 it will assign listeners to however many sensors you have defined in your system.
The way your template is designed, it dynamically selects sensors based on certain criteria. If you don’t need this capability and can live with hard-coding the desired sensor entities in the template, then everything is simplified and listeners will be assigned exclusively to the listed entities.
On the other hand, if you want them to be dynamically selected and to minimize the number of listeners, here’s one possible approach. Create an automation with two triggers (when Home Assistant starts and when groups are reloaded), that dynamically creates a group containing sensors (the service call is group.set
) with the following attributes:
'attributes.unit_of_measurement', '==', '°C'
'attributes.sensor type', '==', 'LYWSDCGQ'
Let’s say this group is called group.my_sensors
. The associated Template Sensor can be reduced to this:
sensor_fault:
friendly_name: "Sensor Fault"
value_template: >-
{{ expand('group.my_sensors')
| selectattr('attributes.last mean of', '<', 5)
| list | count > 0 }}
This approach:
- Preserves the dynamic nature of selecting only certain types of sensors (i.e you don’t have to 'hard-do. The group is updated every time Home Assistant is restarted or when you execute Reload Groups.
- Minimizes the number of listeners to only the entities contained within
group.my_sensors
.