I have a couple of issues with templating. I keep writing templates that work absolutely fine when looked at via the gui… but then return nothing when in my config. Example below… returns zero when in config as a template sensor… same template when viewed on the templates page in the gui works. What am I missing in my YAML?
- platform: template
sensors:
occupied_count:
friendly_name: "Number of Occupied Rooms"
value_template: >
{{ states | selectattr('entity_id','in', ['binary_sensor.kitchen_occupied','binary_sensor.living_room_occupied','binary_sensor.conservatory_occupied', 'binary_sensor.upstairs_hall_occupied', 'binary_sensor.bathroom_occupied','binary_sensor.bedroom_occupied'] ) |selectattr('state','eq','on') | list | count }}
This template should work fine. You are listing all the entity_id’s in the templates so you shouldn’t need to add the entity_id attribute to the sensor itself and the breaking changes shouldn’t affect you.
Are you saying that it doesn’t count or doesn’t return an answer? Doesn’t count would mean it’s always zero, doesn’t return an answer would be no state whatsoever or some cryptic ‘unknown’.
As a side note, this will also only update and perform a count when one of said sensors changes states. It will not be a live tracking at all times kind of sensor. If you want it to update every minute or so, you can add sensor.time or sun.sun as the entity_id and it will update minutely.
My template sensor for counting all movement sensors which state is ‘on’ worked until I updated to HA 0.97.2. Now it reports ‘Unknown’ whenever at least one sensor is ‘on’.