Using motion sensors to turn your lights on and off is both comfortable and can help you save energy. This works best for areas in the home where you pass through, or rooms where you are not perfectly still for a longer period of time. We’ve got a small kitchen that is mostly used for preparing food. There is no table or chairs where we would sit still for a long time. So the kitchen is an ideal candidate for using a motion sensor to control the lights for us. Entrances and hallways are also perfect areas for motion sensors.
In this example I’m going to be using the Hue Motion Sensor, which comes with the added benefit of also including a temperature sensor and a light sensor. In the example below, I’m actually using the light sensor to check if there is sufficient natural light in the room, before turning on the lights. In this example we’re only automating the under-cabinet lights, but you could easily add other kitchen lights to the same shortcut.
In iOS 14, Apple fixed the default behavior for the turn off after x minutes function. It now behaves in the expected manner that every time the motion sensor senses motion, the delay to turn off is reset. This means that if you’re going to do a simple turn on and turn off automation, you no longer need to use a shortcut to do so. However, there are still many situations where you want to turn on lights using shortcuts triggered by motion sensors, and in these cases the solution below is still useful.
We need to create two automations: one to turn the lights on, and another to turn them off. The function to turn them off after a specific period of time does not work exactly as one might think. It will not turn off after a specific time from when it has stopped seeing motion, but rather after a specific time from when it first saw motion. This is why we need a second automation to turn them off.
The automation for turning the lights off is triggered by the absence of movement. It will then wait one and a half minute, checking every 3 seconds for motion, before finally turning off. If it detects motion, it will cancel the automation to turn off the lights.
Turning the lights on
We’ll start by opening either the Home or Shortcuts app. We then choose Automation (at the bottom) and press the plus sign (+) in the top right corner. Select Create Home Automation. Then select A Sensor Detects Something, and pick the sensor in the room we want to control the lights in. On the next screen select Detects Motion. The Time and People settings are optional. If you want different automations for times of day, you can select at what time this automation should work. For us, HomeKit knows if my wife or myself is at home, so we have the People setting set to When somebody is home. We then go to the next page. Now, if you’re using a motion sensor that doesn’t have a light sensor, at this point you can only choose the light and turn them on to whichever brightness level you want. If you’re using a Hue Motion Sensor, you should scroll down to Advanced and select Convert To Shortcut.
The shortcut for turning on the lights is very simple. We’ll start by adding an If statement. We’ll choose the light sensor as Input, Current Light Level as Name, and is less than as Condition. I’ve chosen 80 lux as the parameter for now, but I haven’t tested enough to know which would be the best value. We can remove Otherwise and add a Control Home action where we choose the light and the suitable brightness level and color. I’m using 100% brightness. The shortcut then ends with End If.
Turning the lights off
We’ll now start on the automation for turning off the lamps. We’ll start by creating a new Home Automation (just as we did for turning the light on). We then select A Sensor Detects Something, and choose the motion sensor that is in the same room as the lights. This time we pick Stops Detecting Motion, and again you may change the time for what time of day this automation is running. On the next page we scroll to the bottom and select Convert To Shortcut under Advanced.
The shortcut starts with an If statement, where the lamp we turned on in the first automation now is the Input, and Is On is the condition. You can however only check if a specific light is on, while you can turn on a group of lights. This is why there’s a discrepancy in the names in the this example.
Otherwise can be removed, and we will add a Repeat action next. Choose 30 times. We’ll then add a Wait action, which we’ll set to 3 seconds. Another If statement is added, where we check in case the motion sensor has detected motion. If so, we’ll Exit shortcut with Result. You do not need to choose any result. Remove the Otherwise. End If and End Repeat follow. At this point we add the Control Home action to turn off the lights, and the last End If follows that.
In case you have to use more than one motion sensor to cover the whole room, you’ll need to create one automation per sensor for turning the lights on. You’ll also need to create one automation per motion sensor to turn them off. You have to change the shortcut to something like this:
If Light Is ON
Repeat 30 times
Wait 3 seconds
If Hue motion sensor 1 Motion Is Detected
Exit shortcut with Result
If Hue motion sensor 2 Motion Is Detected
Exit shortcut with Result
Set Light (OFF)
This means that the shortcut will check each motion sensor for motion, and exit the shortcut if any of them detects motion.
You might have to experiment with how long the shortcut for turning the lights off should run, however, if the shortcut’s runtime is too long, the shortcut risks getting terminated.
If you’re looking for a slightly more advanced version of the “turn off lights” automation, where the lights will give you a warning by dimming a little bit before turning off, have a look at this post.