Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Analog Kid

macrumors G3
Original poster
Mar 4, 2003
9,503
12,877
I'm looking for ways to set up basic state machines in my HomeKit automations, but I can't see how to do that.

Two simple examples-- though I'd like to be able to build more sophisticated non-binary states as well:


When I go to bed, I trigger a scene to shut off all the lights and adjust the thermostats. When I wake up, I trigger another scene. When I walk into the bathroom, I'd like the lights to turn on. If I've triggered the go-to-bed scene but before I trigger the wake-up scene, I'd like to lights to come on at minimum brightness. At other times I'd like them on at full brightness. I don't want to base it on time, I want to base it on state.


When I walk into a room, the lights should go on and turn off 5 minutes after not detecting motion-- unless I press the wall switch in which case they should remain on until manually turned off.


Is there anyway to do these things?
 
look at the eve app, it allows you to place conditions on triggers so "when motion sensor triggers, and it's between these times" or "and if _____ light is on" or "if light is under 50%"

it works for all homekit devices, you don't even need an eve device in your system. It syncs up with the regular home app, and the automations will run on any home hub,

When I walk into a room, the lights should go on and turn off 5 minutes after not detecting motion-- unless I press the wall switch in which case they should remain on until manually turned off.

The way I do this is have the motion sensor the light to a state that it wouldn't get into normally, Like 98%, your eyes won't be able to see much if any difference in the room. And then add a condition the "no motion, turn off light" so that it only triggers if the light is at 98%.
for your "unless I press the wall switch" you would just need to be able to run the dimmer to full, and then the "off" event won't happen.

also the "5 minutes after" is problematic, the home app will allow you to turn on a light with a motion sensor, and have it turn off automatically after 5 minutes, but that timer starts when the light comes on, and never gets renewed unless the motion sensor trips again. For the motion sensor to turn on again, it has to turn off first, which it won't do if you're moving in front of it.
And then after the light times out, it also won't come back on again until the motion sensor goes from off to on. Which is problematic if you've been constantly moving in the room.

The best way to do this, is using the timeout feature in the motion sensor, (how long it continues to say "motion" after it's stopped seeing motion) and have the light turn off based on when the motion sensor turns off.


I've been doing home automation for quite a while, and having the same light be both manual and automatic and doing it smoothly is fairly tricky, especially in a "programming" environment that is as basic as homekit. I've been using a program called homeseer for around 20 years, it has full on scripting, and it's hard to do.
 
  • Like
Reactions: Analog Kid
look at the eve app, it allows you to place conditions on triggers so "when motion sensor triggers, and it's between these times" or "and if _____ light is on" or "if light is under 50%"

it works for all homekit devices, you don't even need an eve device in your system. It syncs up with the regular home app, and the automations will run on any home hub,



The way I do this is have the motion sensor the light to a state that it wouldn't get into normally, Like 98%, your eyes won't be able to see much if any difference in the room. And then add a condition the "no motion, turn off light" so that it only triggers if the light is at 98%.
for your "unless I press the wall switch" you would just need to be able to run the dimmer to full, and then the "off" event won't happen.

also the "5 minutes after" is problematic, the home app will allow you to turn on a light with a motion sensor, and have it turn off automatically after 5 minutes, but that timer starts when the light comes on, and never gets renewed unless the motion sensor trips again. For the motion sensor to turn on again, it has to turn off first, which it won't do if you're moving in front of it.
And then after the light times out, it also won't come back on again until the motion sensor goes from off to on. Which is problematic if you've been constantly moving in the room.

The best way to do this, is using the timeout feature in the motion sensor, (how long it continues to say "motion" after it's stopped seeing motion) and have the light turn off based on when the motion sensor turns off.


I've been doing home automation for quite a while, and having the same light be both manual and automatic and doing it smoothly is fairly tricky, especially in a "programming" environment that is as basic as homekit. I've been using a program called homeseer for around 20 years, it has full on scripting, and it's hard to do.
Thanks, this is all really helpful. Before HomeKit, I was using Indigo which is scriptable in Python. It would be nice to see HomeKit adopt something similar. I’d also considered trying to set up a Raspberry Pi as a psuedosensor that could keep state, but that would take some research.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.