What I was trying to impress upon you is that “state not equal off” means the device is in one of its other modes ( fan_only, dry, cool, heat, heat_cool
) but it doesn’t mean it is actively cooling (or heating).
So if your goal is to simply know when it’s “not off for 5 hours” then your template is fine. However, if you want to know when it’s “working for 5 hours”, then the template must be modified to check the value of attributes.hvac_action
and not state
.
The following Template Condition calculates the number of climate
entities that are “not off for 5 hours” and checks if the quantity is greater than 0. The template’s result is a boolean value (true/false).
alias: example
trigger:
- platform: time_pattern
minutes: '/30'
condition:
- condition: template
value_template: >
{% set ns = namespace(qty=0) %}
{% for entity in states.climate | selectattr("state", "ne", "off") | map(attribute="entity_id")
if now() - states[entity].last_changed > timedelta(minutes=5) %}
{% set ns.qty = ns.qty + 1 %}
{% endfor %}
{{ ns.qty > 0 }}
action:
... your actions ...