#needing assistance with a HVAC automation

1 messages · Page 1 of 1 (latest)

fleet cosmos
#

Hi all, im needing some help with creating an automation.
I want to make one that is dynamic for all of my HVAC units.

currently i have a dashboard with the thermostat cards on it for each unit, and that works as expected. I want to make an automation that triggers when i press the power button on the card and if it sends a command to turn off the HVAC, it will then trigger the automation.

I have tried to use chatGPT but its not triggering the automation. I also want it to by dynamic so that it covers all the HVAC units and it determines the unit it needs to act on based on the unit the card is tied to.

Below is the output from chatGPT, which makes sense to me logically, but does not work.
I just need some assistance mainly on the trigger part. the rest i can manage.

`alias: HVAC Auto Fan Mode After Turn Off Command
triggers:

  • event_type: call_service
    event_data:
    domain: climate
    service: turn_off
    trigger: event
    actions:
  • variables:
    hvac_id: "{{ trigger.event.data.service_data.entity_id }}"
  • delay: "00:01:00"
  • data:
    entity_id: "{{ hvac_id }}"
    fan_mode: "4"
    action: climate.set_fan_mode
  • data:
    entity_id: "{{ hvac_id }}"
    hvac_mode: fan_only
    action: climate.set_hvac_mode
  • delay: "00:30:00"
  • data:
    entity_id: "{{ hvac_id }}"
    action: climate.turn_off
    mode: parallel`
verbal jewel
#

I think the climate card is probably not calling climate.turn_off, but more likely climate.set_hvac_mode

#

e,g,

event_type: call_service
data:
  domain: climate
  service: set_hvac_mode
  service_data:
    entity_id: climate.generic_thermostat
    hvac_mode: "off"
origin: LOCAL
time_fired: "2025-03-22T16:26:27.466760+00:00"
context:
  id: 01JPZATQ8ARQ2YNFRF2YQWNC1V
  parent_id: null
  user_id: c77b9345cebd42b197f444f86c9d600b
#

You can confirm this with the events viewer in developer-tools.

#

You could workaround this by using a state trigger instead, but then you'd have to explicitly add all your climate entities to the trigger list.

#

Or you could continue to use an event trigger, but you can't capture the hvac_mode in the trigger, so you'd have to trigger on any change of set_hvac_mode, and then write a condition that restricts the automation to only run when the hvac mode is off.

fleet cosmos
#

perfect. that was what i needed (with a little chat gpt help afterwards to help with some of my mis understandings 🙂

many thanks for the assist @verbal jewel

fleet cosmos
#

ok, i have come back seeking assistance on this...

Perhaps you might be able to help @verbal jewel

I am trying to put in a condition so that it only activates if the previous stat was "cool" when i change the mode in dev tools, i get the following

event_type: state_changed data: entity_id: climate.study_ac old_state: entity_id: climate.study_ac state: cool

And this is the updated automation

`
alias: HVAC Auto Fan Mode After Turn Off Command
description: ""
triggers:

  • event_type: call_service
    event_data:
    domain: climate
    service: set_hvac_mode
    service_data:
    hvac_mode: "off"
    trigger: event
    conditions:
  • condition: template
    value_template: "{{ trigger.event.data.old_state.state == "cool" }}"
    actions:
  • variables:
    hvac_id: "{{ trigger.event.data.service_data.entity_id }}"
  • delay:
    hours: 0
    minutes: 0
    seconds: 15
  • data:
    entity_id: "{{ hvac_id }}"
    hvac_mode: fan_only
    action: climate.set_hvac_mode
  • delay:
    hours: 0
    minutes: 0
    seconds: 30
  • data:
    entity_id: "{{ hvac_id }}"
    fan_mode: 4
    action: climate.set_fan_mode
  • delay:
    hours: 0
    minutes: 1
    seconds: 0
  • data:
    entity_id: "{{ hvac_id }}"
    hvac_mode: "off"
    action: climate.set_hvac_mode
    mode: parallel
    `

but evidently i have something wrong with the condition, as i keep getting this error

Error: In 'template' condition: UndefinedError: 'dict object' has no attribute 'old_state'

topaz agate
#

Yeah I think you can't do that because the trigger is the call_service event and not the state of the climate entity. The call_service event has no old_state.

#

Try {{ is_state(trigger.event.data.service_data.entity_id, 'cool') }}

fleet cosmos
#

ok. 1 moment. i will do that now.

#

wouldnt that look for the current state though? with 'is_state'

#

i am new to HASS automations, so, just trying to wrap my head around the more complex side of it

topaz agate
#

Oh that's true.

fleet cosmos
#

yeah, i would need something like 'previous_state'

#

which is published in the dev tools section. Im just not sure how to harness it.

topaz agate
#

What other data do you have in the trigger to play with? Able to paste in what the trigger data looks like?

fleet cosmos
#

1 mometn

#

`
event_type: state_changed
data:
entity_id: climate.study_ac
old_state:
entity_id: climate.study_ac
state: cool
attributes:
hvac_modes:
- heat_cool
- cool
- dry
- heat
- fan_only
- "off"
min_temp: 16
max_temp: 31
target_temp_step: 1
fan_modes:
- AUTO
- QUIET
- "1"
- "2"
- "3"
- "4"
swing_modes:
- AUTO
- "1"
- "2"
- "3"
- "4"
- "5"
- SWING
current_temperature: 34
temperature: 25
fan_mode: "1"
hvac_action: fan
swing_mode: SWING
friendly_name: Study_AC Study_AC
supported_features: 425
last_changed: "2025-03-25T09:55:08.578565+00:00"
last_reported: "2025-03-25T09:55:08.578565+00:00"
last_updated: "2025-03-25T09:55:08.578565+00:00"
context:
id: 01JQ6BMBECPMCPVJEZ6QTRXRM8
parent_id: null
user_id: 07ba87e71eeb409c89617ee4185d3c71
new_state:
entity_id: climate.study_ac
state: "off"
attributes:
hvac_modes:
- heat_cool
- cool
- dry
- heat
- fan_only
- "off"
min_temp: 16
max_temp: 31
target_temp_step: 1
fan_modes:
- AUTO
- QUIET
- "1"
- "2"
- "3"
- "4"
swing_modes:
- AUTO
- "1"
- "2"
- "3"
- "4"
- "5"
- SWING
current_temperature: 34
temperature: 25
fan_mode: "1"
hvac_action: "off"
swing_mode: SWING
friendly_name: Study_AC Study_AC
supported_features: 425
last_changed: "2025-03-25T09:56:16.648315+00:00"
last_reported: "2025-03-25T09:56:16.648315+00:00"
last_updated: "2025-03-25T09:56:16.648315+00:00"
context:
id: 01JQ6BPE14D7J9TRYHYTAESRPG
parent_id: null
user_id: 07ba87e71eeb409c89617ee4185d3c71

`

topaz agate
#

This is for a state_changed event, but you are triggering on a call_service event.

fleet cosmos
#

ahh ok, let me see if i can listen for that in dev tools

#

event_type: call_service data: domain: climate service: set_hvac_mode service_data: hvac_mode: "off" entity_id: climate.study_ac origin: LOCAL time_fired: "2025-03-25T11:09:29.954702+00:00" context: id: 01JQ6FWGF2NC9GHTE1KC0EDYEZ parent_id: null user_id: 07ba87e71eeb409c89617ee4185d3c71

#

ok, i see the difference there.

#

ok, so perhaps i need to refactor the automation to look for a 'state_change' on the new state, rather than the 'call_service'

topaz agate
#

Yup. But the idea of your previous setup was that you wanted to avoid having to define one automation per climate entity right?

#

Actually, why not define one automation per climate entity? How many climates do you have to handle?

fleet cosmos
#

i have 4 split systems currently throughout the house, and another 3 waiting to be installed

topaz agate
#

That's not that many. If your concern is replicating the logic consistently across 7 climate entities, then look into using blueprints.

#

Those let you keep the logic constant but generate any number of automations by subbing in different target entities and variables. And if you wanna update the logic, just edit the blueprint and reload Automations in Dev Tools > YAML to update all automations that use the blueprint as source.

fleet cosmos
#

but, wouldnt that need me to still have 7 automations? 1 fr each unit?

topaz agate
#

Yep

fleet cosmos
#

i have not made a bluebrint before, but that is my understanding

topaz agate
#

That's what I do. One blueprint generating 6 automations, one for each of my climate entities.

fleet cosmos
#

whilst I appreciate that would work, and i could do that, it does not seem overly efficient. Im not saying your way is wrong (i mean, your way is working... and mine currently is not 🤣 ) however having it as a dynamic thing does seem alot more efficient way of going about it.

#

but, if all else fails, i will resort to that. as i know that would work. just trying to keep it 'clean' so to speak

topaz agate
#

Yup. Your approach of triggering on the call_service events is quite elegant, I would not have thought of that. But because the automation is not aware of the climate's previous state, there may be a limit to how you can implement your condition based on the previous state.

#

In order to do that, I think you need to trigger on the state change of the climate entity. But that would require one automation per climate entity.

fleet cosmos
#

yes. I will poke around and see if i can use the state_changed as the trigger.

#

could it not extract the entity_id from the state change info?

event_type: state_changed data: entity_id: climate.study_ac new_state: entity_id: climate.study_ac state: "off"

topaz agate
#

But that being said, there are clever Jinja ninjas hanging about, they may have a good idea.

fleet cosmos
#

something like

entity = {{ trigger.data.entity_id }}

or something like that

topaz agate
#

If you don't want to target the specific climate entity to look at it's state change, I think you'd need to listen for all state changes and then filter for those involving climate entities. That could involve a lot of unnecessary triggering of this automation.

fleet cosmos
#

hmm.. would that not be countered by listening specifically for climate state_changes?

topaz agate
#

Is there a way to do so?

#

Tbh I have not used event triggers before

fleet cosmos
#

im not sure.. looking at the dev tools, there is nothing that specifically indicates the climate section, other than the entity_id, which is climate.hvac-unit

#

i think this will need a more substantial expert than i 🤣

topaz agate
#

The docs say that you can use some templating in the event_data option. So maybe you can specify that the state_changed event needs to involve an entity whose id contains climate.