I have a heatpump for my HVAC and the wall mounted units in different rooms cannot be in different modes. Meaning, the entire system needs to be “heat”, “cool” or “heat/cool” (aka auto).
I want to build an automation that first just notifies me if someone changes the mode and there’s a conflict. I then want to improve this so that changing mode in one unit will auto change the mode on the other one.
I’ve only done some basic automations in YAML before, and never used the UI. I liek the idea of using the HA automation UI as it’s easier to manage generally speaking.
However, I can’t understand the automation UI to do what I described above.
Here’s example of the state info for one of the thermostats (e.g. climate.attic)
How do I setup automation such that when a state change occurs, check if the new state is not equal to the state of the other thermostat (e.g. climate.main)?
In pseudo code, the logic is essentially this:
If (climate.attic state changed) and (climate.attic new state != climate.main.state)
then notify my iphone and prevent state change
I’d suggest the following (in the Automations UI):
Create a new automation, set the trigger to “state”, Entity: climate.attic
You don’t need to enter anything into “To”, “From” or “For”, those are just filters.
Okay, now the Automation will fire whenever the state of your A/C changes (including “unavailable” - if you don’t want it to fire when it becomes unavailable, add a Condition “Not” - State - climate.attic, climate.main, State: unavailable)
To make it check for the state of the other A/C, you’ll need a template condition:
Value template: {{ states('climate.attic') != states('climate.main') }}
This will equate to true if the two states are not equal
So now we just have to make your phone buzz. I guess you’re using the Home Assistant App on your phone? If so:
Add an action, choose “call service”.
Service: notify.mobile_app_xxx (change to the correct one)
For the data, use: message: This is the message that gets sent!
If one thermostat is the leader and the others are followers, setting the leader’s mode will automatically set the mode of all followers. This is easy and straightforward; it only requires one automation to check the leader’s state.
Your requirement is that all thermostats are peers (i.e. everyone is sometimes a leader and sometimes a follower). Changing the state of any peer will cause it to change the state of all other peers. That arrangement can be tricky because it can lead to a domino effect:
Each peer has an automation that detects changes to its state. When triggered it proceeds to set the state of other peers.
When the other peer’s state is modified, that will trigger the peer’s own automation which will now attempt to set the state of other peers.
One way to prevent this domino effect it is to make the first triggered peer set a “flag” (turn on an input_boolean) which serves to signal to other peers that a round of changes is underway (and they should not start their own round of changes). In other words, each peer’s automation has a condition that checks if the flag is set. If it is, the automation’s action is not executed. After the first peer has finished its round of setting the state of all other peers, it resets the flag (turns off the input_boolean).
Oh yes, I should read your questions better, sorry
So, you should be able to get the previous and current state using the Trigger State Object: https://www.home-assistant.io/docs/automation/templating/#trigger-state-object
(Haven’t tried this):
Add an action:
Action: Call Service
Service: climate.set_hvac_mode (Is this the one that works?)
Now press on the three dots, “Edit YAML”
If there’s any data: in this, remove it.
Add:
Note that you can’t “test” this automation by just executing it in the WebUI, since there won’t be any real trigger data, you’d have to actually trigger it by changing the HVAC mode.
Can I use this just to reference the previous and new state values to evaluate in the condition? I’m finding my test notification keeps getting fired from this automation even though the state isn’t changing to a new value. I think there could be something in the integration for my thermostat that is changing the state to say “cool” to “cool”.
it will trigger when its state changes or when attributes changes. For example, when temperature or current_temperature changes, that will trigger the State Trigger shown above. So it’s not limited to firing when only its state changes from, say, heat to cool.
One technique to constrain a State Trigger is to supply from and to. However, in your case, you’re interested in more than just from: 'heat' and to: 'cool'. Therefore you will probably have to use condition to constrain it to the state changes you want.
Darn, always forget about that, good call! @tmchow, your idea is correct, try adding another template condition: {{trigger.from_state.state != trigger.to_state.state }}