Template sensor which counts multiple climate states

Hi guys,

after wasting hours of research at google and in this beautiful board i have to open up a new topic.

So i am trying to create a template sensor which counts my air conditioners based on their state. But i want the sensor not only to count e.g. if a climate is heating. I want the sensor to count if any of the climates is heating or cooling or drying and so on…

This is my code for counting all lights, based on the state “on”. So how the hell do i simply add more states to trigger the counting template sensor?

{{ states.light
   | rejectattr('attributes.entity_id', 'defined')
   | selectattr('state', 'eq', 'on')
   | list | count }}

Seems like a stupid and easy question, but not for me… :face_with_peeking_eye:

Thanks in advance.

   | selectattr('state', 'in', ['heating','cooling','drying'])

https://jinja.palletsprojects.com/en/latest/templates/#jinja-tests.in

Obviously, make sure you put the real backend states in the list, not the “translated” state that might show in the front end. Mine is heat or off, for example.

1 Like

Thank you for the quick reply. Works as expected.