Determine if device was turned on/off by user or system


I currently control the lightning in the apartment based on presence in the room (motion sensors etc…). However, I need to implement some kind of temporary override behavior such that If I manually change the lightning, (using the app, homekit or physically flipping switch) i want the system to stop automation of the device for x amount of time. I have not seen any easy way of implementing this, how did you do it?

Typical use case is when I want to take a power nap in the living room or watch a movie.

I use counters for the automation of the lights.
So, if sensor sees movement switch on lights and start counter for x minutes
If counter is empty turn of lights.
This way if there is more movement the counter will be reset to x minutes and the lights stay on.

If i switch the switch:
Turn of the flow for the lights and stop the counter.

When I turn of the lights by the switch (or when we go to sleep or we go out)
Turn on the flow for the lights and start the timer for a few seconds.

AK auto - auto (in terms of time and motion, intensity…)
AK mode 100, 50 25 sleep, sylence media - manual mode (turn on manual mode or tv*, auto off…)
AK mode z off - turn all modes off, after x sec. turn on mode auto (or if the zone is inactive for x min. turn off all, turn on auto)

1 Like

What is this? An app?

Want to explain some more what this is?


did you understand?

I understand, but it unfortunately it does not answer my question in how one could determine if a user or flow caused a light to be switched on/off.

I am not looking for how to implement different modes or how to use virtual devices.

What I have come up with so far is creating two flows that will listen for state changes on the light (on/off) and then set a variable (wasAutomated = false).

Then for every flow that changes the state of that light(other light automations based on presence) set wasAutomated = true. Since these flows also will trigger the flow mentioned above, If I then can make sure that the flow that was triggered by automation is ran after the flow that will react to both user and automation events, I can know that the wasAutomated variable will hold the value that I am looking for.

However, since this is kind of hairy logic, I don’t know if I even managed to explain it nicely, I was looking for a better way to do it.

Oh my… trying to get it. Is a flow chart drawing (by hand if you like) an idea, to clarify?

I am going to see if I can implement it, and will report back how it goes. Also found this The order of cards executed in flows which essentially tries to solve the same thing.

I managed to implement it - now I am able to determine if there was a user or a flow that turned on/off a device, and then, if the system was manually overridden or not. It gets quite hairy and ugly, so I am very open for improvements. Here goes:

The overall idea is the following: We start a timer whenever the device was turned on/off. This flow will run regardless of the system was turning on/off the device, or if the device was turned on/off manually by a user. All the automated flows needs to stop this timer to mark that the system turned on/off the device. If the timer finishes we know that a user turned on/off the device. When we know that a user turned on/off the device we can start another timer that determines for how long we want to keep the device manually overridden, before the device goes back to automated state.

Flows that run regardless of user/system turning on/off device:

Automated flows that will try to stop the timer:

When timer runs out, we know that a user turned on/off the device. We can therefore safely disable the flows that we don’t want to run when the device is overridden, and start the new timer that determines for how long the system is overridden.

When our timer runs out we can enable the automated flows again:

I very much welcome improvements! 6 flows and 2 timers is way too much for implementing this functionality for one single device. Wish me good luck implementing this for all my lights :laughing:

I’m completely lost here, sorry :wink:

Why not create a flow that disables the automation flow and enables it after x amount of time? Or toggle it manually when starting/finishing.
I am using one simple flow to disable automatic room ventilation for one hour when i use my sauna.

I think there is an cleaner approach by reversing the logic. You know when you automatically start something in advance, al the other activity is manual.

First create the flow you use for automated light control. You can call this flow in any situation you want to have automation. So instead of turning the light on or off directly from Homey, call the flow: “Automated turn on” or “Automated turn off”.

Automated on: If this flow was started
And: Timer “Disable auto on” is not running
Then: Start timer “Automated control” for 2 seconds, and turn on light

Automated off: If this flow was started
And “Disable auto off” is not running
Then start timer “Automated control” for 2 seconds, and turn off light

Then in the flow that listens for the light:

If the light is turned on
And timer “Automated control” is not running
Then: Start timer “Disable auto off” for x time and stop timer “Disable auto on”

If the light is turned off
And the timer “ Automated control” is not running
Then: Start timer “ Disable auto on” for x time and stop timer “Disable auto off”

There are also variations to this approach you can use by setting variables in the flows that listen for the lights, so you can see if the last action was manual or automatic.

Notice I reversed the timer checks for on and off: manual on overrides auto off, manual off overrides auto on.

1 Like