I’ve been using Homey for quite a while now. While it doesn’t offer all the flexibility and customization options that some other platforms might, it provides an excellent way to create flows and centrally manage all your smart home devices, even across multiple vendors and standards.
Recently, I added a new device to my office: a smart ceiling light from Govee. My plan was to automate the lighting in my office to make it, well, a bit more nerdy. The idea was (and still is) simple:
I placed a motion sensor (in this case, an IKEA VALLHORN) in the room. The goal: when motion is detected, turn the light on. When no motion is detected, turn the light off.
What can I say? It wasn’t that easy.
Unfortunately, sitting at my desk triggered frequent “no motion” events for the IKEA sensor, causing the light to turn on and off during work sessions. This was especially annoying during calls when I sat still for long periods.

The Delay
Next Idea: Add a delay and a check again if the motion alarm is still off after 5 mins:

Can you guess what happened? Yes, each time the sensor’s motion alarm turned off, it waited five minutes and then checked again. If I happened to move during that exact time window, it worked. But solving this by adding multiple checks (one after four minute, another after one minutes) didn’t help. Homey runs all those actions in parallel. So even if I moved in one of the flows, another one that started 30 seconds later might still turn off the light.
The Variable
To prevent multiple flows to run at the same time and do the same thing, I added another idea: The Variable!
Now, whenever a test starts, the flow first checks if a variable called TestInProgress is set to true. If it is, the flow just ends. If not, it sets the variable to true and enters the first delay. After each delay, it checks again for motion. If motion is detected, the variable is reset to false and the flow ends. If I don’t move, or if I’ve left the room, the light turns off and the variable is reset to false as well.

The (Not-Yet-)End Result
What I’ve ended up with is something much more complex than initially expected: five delays, each shorter than the last, with checks that allow the script to exit early if motion is detected.
The next step will be to use Homey’s JavaScript functionality to simplify things (at least in my head it sounds simpler):
- Add a new variable
LastTriggerTimethat records the last time motion was detected. - Once the flow is triggered due to no motion, check if another instance is already running. If not, wait a few minutes.
- After waiting, only turn off the light if
LastTriggerTimeis older than the current time minus ten minutes.
Let’s see how that goes!

Leave a Reply