Crixus Blog

A wild Lucas appeared

Automating My Office Light: Why Sitting Still is Harder Than It Looks

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.

My idea of the perfect setup

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 LastTriggerTime that 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 LastTriggerTime is older than the current time minus ten minutes.

Let’s see how that goes!

One response to “Automating My Office Light: Why Sitting Still is Harder Than It Looks”

  1. aisajib Avatar

    I’ve been using Philips Hue with Apple Home(Kit) for many years and have had a pleasant experience setting these up these kinds of automation. I can do it via both Philips Hue app and Apple Home app (the latter is more user-friendly). The downside is HomeKit-enabled accessories don’t come cheap!

    I got a motion sensor from Philips, too, but I ended up not really using it. The idea was it would turn on the lights during certain hours at night if I get down from the bed. It worked, but my getting down and my family’s coming and going was too erratic to establish any pattern lol 😛

Leave a Reply

Discover more from Crixus Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading