How to get the hvac_action of several climate entities?

For an automation i have to pull the hvac_action-states of all climate entities to find out if one is heating. How could i solve it?

I could use something like:

{{ is_state_attr("climate.badezimmer_1","hvac_action", "heating") or is_state_attr("climate.gaestewc_heizung","hvac_action", "heating") ...}}

Is there any smarter way without hardcoding every Entity in the expression?

Welcome Patrick!

Paste the following code into Developer Tools —> Template and play with it:


{% set hot = states.climate
|selectattr('attributes.hvac_action', 'eq', 'heating')
|map(attribute='entity_id') |list |count |int(0) %}
{{ hot > 0 }}

2 Likes

Thank you!

Hi there, many thanks for this!

I did some optimization and I thought to share it here for posterity.

This returns true as soon as the first climate sensor action is in “heating”, instead of having to check them all

{{ (states.climate
  |selectattr('attributes.hvac_action', 'eq', 'heating')
  |map(attribute='entity_id')|select|first
) is defined }}