Following Problem:
My AC sucks at controlling itself when the target temperature is reached so I created an automation that switches between cooling and fan mode depending on the difference between target and actual temperature. That works perfectly fine. But sometimes I want to run the AC just in fan mode independend of the temperature so I have to disable that automation.
I first created a second automation that disabled the first one when the AC went from off to fan mode and vice versa but that doesnt react when I manually switch the AC to fan mode when it is already running.
So my question:
Is there a way to distinguish where a command was issued? As in: can an automation see if the last change to the AC mode was triggered by another automation or a manual command?
@koying if I get it correct that lets me see if the current run of the automation was triggered by user or automation. But I need to see the last thing that changed the state of the AC, independent of the current automation run…
My automation changes the AC state depending on temperature and runs everytime the temperature changes. And I need that automation to be able to see if the last(!) change of the ac settings was triggered by a user or an(other) automation…
I didn’t try it myself, but from that thread (that your read, right ), I understand that context.user_id is not none means that the state was changed through the UI, so not through an automation.
@koying ok I tried it and it didnt work. But that makes sense: The trigger for the automation is the temperature change, but I dont care what triggered that - I need to know what triggered the last change of the AC setting which is not a trigger for this automation but a result of it… Not sure if that’s understandable…
Maybe it helps if i go into more detail
I only want the AC to change from “fan” to “cool” when the current mode is “fan” and that was not set manually by any means.
There are at least three scenarios I can think of:
I started the AC in fan mode - then I dont want this automation to do anything
I started the AC in cool mode - then I want it to switch between fan and cooling depending on temperature
I started the AC in cool mode but then later switched it to fan mode - in that case I want the automation to stop automatic switching
I will post the current version of the automation (with the added template) here, maybe that helps a little bit…
OK I think I got it working… so far it survived all my tests
I added an input_boolean helper and two triggers to the automation, one for entering fan mode, one for leaving it. When it enters fan mode i check if there is a user_id and set the helper if that’s the case. When it leaves fan mode for whatever reason it disables the helper.
Then I just check the helper before switching to cooling mode…
Tons of if-conditions and I am not sure if there would have been a more elegant solution, but at least it seems to work for now
The reason I want it all in one automation is that I need this for every room independently - and the list of automations is already very long. So I try to keep things that logically belong together in one automation.
Also I wouldnt condemn “if” use in general… sometimes it is just needed to make automations possible unless you want to create an extra automation for every possible outcome.