I currently have three Template Sensors that use the same technique, for reporting the number of active lights, appliances, and open doors, and all three work perfectly (without listing them in entity_id
).
It’s not “magic” but a regex pattern that Home Assistant uses when it evaluates Template Sensors (and Template Binary Sensors and Template Switches) at startup. It extracts anything that matches the appearance of an entity_id
then creates a listener to monitor that entity’s state-changes. If the pattern fails to match anything (and nothing is explicitly listed in the entity_id:
option) then Home Assistant simply evaluates the template once and never again (until the next restart).
I believe what I failed to take into account was that your smoke sensors report their status with a leading capitalized letter, like Emergency
as opposed to emergency
. That means I’ve supplied the selectattr()
function with the wrong value.
I’ve revised my previous post and changed the function’s value so that it matches for Emergency
and Warning
. Let me know if it makes a difference,