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. (Update: Since iOS 15, Exit shortcut is now called Stopp running shortcut) 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.
Hey!
To begin with, thanks for being so responsive to previous posts made these people!
I’ve got a bit of another issue, not involving your explicit shortcut/automation, but still the Hue motion sensor.
I have grown tired of Smartthings app unresponsiveness on my Apple devices. So I thought I’d give Homekit a try. Now to the problem. My hue motion sensor is setup as the standard automation where “if motion is detected then turn on Lamp” and then an added “if no motion turn off”. The thing is that it’s very sporadic when it actually turns the light on or not. And I’ve found that it works 100% of the time when I unlock my iPad (which is my HomeKit hub), vs having its screen off.
Is this a problem connected to having an iPad as the only hub?
Additional info:
– iPad Pro (2018) running latest iPad OS.
– 1 Hue Hub, latest firmware
– Lights I use here are IKEA Tradfri
– Distance to sensor and the lights is approx 5-6m.
– The sensor indicates motion in the Home app, but the action to turn on the lights isn’t always triggered.
Thanks in advance,
/Fredrick
Hi Fredrick!
I’m glad you found the site.
I must admit that I haven’t tried using the iPad as the HomeKit Hub even though we have a few of them here at home. However, I have read quite a few threads online where people have had some issues with reliability when going that route. Going only by what I’ve read, it seems like the AppleTV and HomePod work more consistently.
Personally, I like to hardwire anything I can (as far as networking equipment are concerned), and that’s why I’ve always recommended using an AppleTV connected by ethernet as the HomeKit Hub.
However, reading about your setup, I’m wondering if you’ve connected the IKEA Trådfri lights directly to the Hue Bridge or do you use a IKEA Trådfri Gateway for the Trådfri lights?
Have you setup the automation within the Hue app or the Home app?
Thanks for a quick response!
Yeah, I like things hardwired too for a more stable experience. But since im just testing to see wether it’s worth making the switch from ST or not.
I’m using the Trådfri lights connected to the Trådfri hub, and then synced to HK. Originally I had them connected to the Hue bridge, but the lights didn’t show up in HK for some reason. Is it possible to have the Trådfri lights connected to Hue somehow?
The automation is set in Homekit, since the Trådfri lights aren’t connected to hue.
Of course, for testing purposes it’s always best to try with what you’ve got available. The default suggestion is to turn the router, bridges, gateways and HomeKit hub off, then turn them on again… first the router, then bridges and gateways, and finally the HomeKit hub. But I’m pretty sure you’ve already done that. So in your case, it seems likely that it is the use of an iPad as the HomeKit Hub that is causing the problem.
The only other thing I can think of, is how the Motion Sensor is set up. When using it with HomeKit, it should not be configured in the Hue app, but only added to the Hue app. You can check this by opening the Hue app, go to settings and then Accessory setup. It should say “Not configured” under the Motion Sensor. This is so that there aren’t two systems trying to use it, which could create conflicts.
As both the Hue and Trådfri system are using Zigbee, it is (as you noticed) possible to add Trådfri lights to the Hue hub. However, if you do so, you will only be able to control them within the Hue app. They will not show up in HomeKit. I’m not completely sure if this is limited by Hue or HomeKit.
Yes, I’ve tried all the basic things like switching everything off and setting it up in the right order etc. And I more or less come to the conclusion that it must be the iPad as a hub that’s the problem. Since the automations and everything works 100% of the time if I unlock my iPad and have it ”active”. And when it’s in idle it works very sporadic instead.
I have the sensor set as ”Not configured” and still the same results.
It’s a bummer they don’t recognize the Trådfri lights as ”trusted” enough to let it show up in HK through the Hue hub. Since they apparently work through IKEA’s hub.
I think the solution for me is to get an Apple TV or on of the speakers to work as a hub. And I think I might in the near future setup a HomeBridge solution aswell.
I’ll be back when I stumble across issues in that matter! 😉
Thanks for your support Stefan!
I’m pretty sure getting a different HomeKit Hub will solve the problem.
About Hue and Trådfri, it’s the same the other way around. You can connect Hue lights to the Trådfri Gateway, but they won’t either show up in HomeKit. So there’s clearly a limitation that does not allow devices from one party to be connected via a bridge/gateway of another party to be connected to HomeKit. I assume it has to do with requirements that all devices need to be tested and certified to work with a certain bridge/gateway.
I’m definitely no HomeBridge expert, but I’ve been using it (I went with HOOBS) for some months, and had no problems so far. I especially like the ability to use dummy switches for more advanced automations.
Will be interesting to hear how it all works out 😃
Hi Stefan, thanks for the great article! I managed to use your first shortcut so my hallway light comes on (to 99% when it’s bright, and 29* when it’s dark.) upon detecting motion.
However, I chose 99% and 29% as they are unique values, and I wanted the absense of motion to turn off the lights only when the lights were triggered by motion in the first place (i.e. if the lights come on because I set a particular scene, they will not turn off despite absence of motion. However, I was not able to get the 2nd shortcut working. Can you advise if I did something wrong with my 2nd shortcut below?
Home Automation: A Sensor Stops Detecting Motion
If Light Brightness is 99%
Repeat 30 times
Wait 3 seconds
If Motion Detected
Exit shortcut with result
End If
End Repeat
Set Light to OFF
Otherwise
If Light Brightness is 29%
Repeat 30 times
Wait 3 seconds
If Motion Detected
Exit shortcut with result
End If
End Repeat
Set Light to OFF
End If
End If
Hi Dave! I’m glad you liked it 🙂
First, I want to say that your code and logic is perfect. There is nothing wrong with it. Second, I had something very close to this working last year. However, I did some testing now, and it’s not working anymore. So clearly there is a bug, but the bug is not yours. I even tried “If brightness between 100% and 0%…” and that didn’t work either.
However, I managed to create a workaround. If you start by checking the brightness value of the light, formatting the number and then setting it to a variable and then using the variable for the if statement, it works. To check the brightness value, you’ll use “Get the state of Home” action.
The full code should be like this:
Get LightName Brightness
Get numbers from Brightness
Format Numbers to 0 decimal places
Set variable BrightnessLevel to Formatted Number
If BrightnessLevel is 99 (no % here)
Repeat 30 times
Wait 3 seconds
If Motion Detected
Exit shortcut with result
End If
End Repeat
Set Light to OFF
Otherwise
If BrightnessLevel is 29 (no % here)
Repeat 30 times
Wait 3 seconds
If Motion Detected
Exit shortcut with result
End If
End Repeat
Set Light to OFF
End If
End If
This worked for me. Let me know if it works for you as well.
Thanks Stefan for the quick and helpful response. Your diagnosis was spot on! After your post I did some tests and “If brightness” is not working at all.
Your recommended workaround is working perfectly for me. Thanks again for finding a workaround and for your super helpful articles on this page!
Thank you Dave for your feedback and kind words. And thank you for coming back to tell how it worked out. I’m inspired by your idea and the bug you encountered to write a post about it 🙂 I hope that’s ok.
I just wanted you to know that it seems like the bug has been fixed in the latest update from Apple.
It’s still not (or got broken again).
I haven’t had any problems lately… Are you running the beta?
Hello
Firstly love this site very helpful.
However I’m having issues with the automation for turning lights off.
It works perfectly when I do 30 repeat and 3 seconds but if I want to do it for longer it doesn’t work. I’ve read through your posts and it mentions I should be able to get up to 10-12 mins. I have followed your instructions to the letter so I don’t understand what’s wrong 🙁
Thanks
Hi Luke,
I’m glad you like the site.
I must admit, I had never myself checked the time limit of a shortcut. When I wrote 10-12 minutes, it was what I had read. However, tonight I took the time to test what the limits are.
I used the shortcut that dims the lights after 90 seconds, and then 30 seconds later turns them off (the more advanced motion sensor shortcut I’ve posted) as a base.
When I used 200 * 3 seconds (10 minutes) for the first part, it did not finish successfully. However, when I used 180 * seconds (9 minutes) for the first part, it finished both the first part and the 10 3* seconds second part. However, when I timed how long it took for the shortcut to run, it actually took about 10 minutes… so there is a little bit of overhead for checking if motion has been detected for 190 times (180+10). In other words, it seems like the hard limit is 10 minutes (at least for me, when I use the Apple TV 4K as the HomeKit hub) for the whole shortcut to run.
I hope this helps, and I’m sorry I mislead you with the 10-12 minutes. It would be great to know if you get it working with 180 * 3 seconds and if you have any other troubles.
Thanks for your reply 🙂
I have tried this and even shorter times but nothing over the 90 seconds works.
I am using an iPad that is always connected as a hub though! Do you think that could be it?
Thanks again
And you’re always adding to the number of loops (repeats), and not the wait time? So for instance if you have it repeat 80 times and wait 3 seconds each time (that would be 4 minutes), it will not finish? Are you running iOS 14 on the iPad? Maybe using the iPad as the hub might be the problem then.
Yes that’s correct.
Anyway I’ve purchased a HomePod mini to check…. I’ve plugged it in and the automations work perfectly now.
I’m using the latest iPad Pro with up to date software but Seems the iPads have limitations with automations. The most I could get out of it was 90 seconds.
Thanks for your help
Ok, good to hear that it works with the HomePod mini. If you ever do a test to see how long shortcuts you’re able to run with it, I would be very interested to hear 🙂
In your “turning the lights” off automation, the last step “At this point we add the Control Home action to turn off the lights” is not an option in my shortcuts. The + sign pulls up scripting options, but “Home Control” is not there.
Hi Sven,
This is the Control Home action I’m talking about. If it doesn’t show up directly, you’ll find it by searching.

Hello Stefan, thanks a lot for your guide, I hope it will finaly make my sensor work correctly.
Just a two question. First is about 30x 3 sec. What is the logic behind it? Does it mean that the sensor is looking for a movement for these three seconds? or is it just that after three seconds sensor triggers and if it see movement it will end? Let’s say that I have a sensor in my kitchen and I don’t want to turn off my lights so I wave with my hand to restart the sequence. Do I have to wave for 3 seconds, or be waveing exactly when 3 seconds ends, or can I wave anytime and it doesn’t matter. And second question. Sometimes happend that instead of turning the lights off it just dimmed to like 10%. If I moved it went back to 100% but then again 10%. I had to manualy turn it on and off to make it work again. Thank you and sorry for my english (not my first language)
Hi Petr,
I’m glad that you like the guide 🙂
First about the logic for using 30 x 3 seconds. Every time the motion sensor detects motion, it will be set to the state “motion is detected”. This state remains about 5 seconds after the motion has stopped. After that it will trigger the “no motion detected” state, and then go back to the default state. As we check every 3 seconds if motion has been detected, we are certain to catch it. If we would use a wait value of 10 seconds, there would be a chance that we would miss it.
About the rather interesting behavior where the lights go to 10% instead of turning off. Double check that the last control action before “End If” is set to turn the light off. Also check that you don’t have more than one automation turning the lights off.
Also, you might like this version as well 😉 http://homekitautomationtips.com/how-to-use-a-motion-sensor-to-turn-your-lights-off-with-homekit-but-giving-you-a-warning-first-more-advanced-version/
And you should absolutely not apologize for your English! It’s great! English isn’t my first language either.
Hi Stefan,
Your automations are amazing and thank you for post them.
But I have 2 problems:
1) when I set the first automation for light on it works anyway also with others lux parameters (I put 30 lux)
2) about light off automation it doesn’t work….I don’t understand why it is perfect but it works only when I play the automation in the command (when I do the shortcut I mean)
I use fibaro HomeKit sensor and one hue Philips light for make the automation
Can you help me please?
Thank you
Hi Fede,
I don’t have any experience with the Fibaro HomeKit sensor, but I assume it works the same way as the Hue Motion Sensor I’m using. First thing I would do is double-check that the automation is supposed to run when the sensor stops detecting motion. You could set it to turn off the lights directly just to confirm that the action is triggered. Since it works when you run the shortcut manually, it seems like your shortcut is correct.
Hi Stefan,
Thank you for reply.
Yes your command worked before, but now no. Fibaro is egual at hue motion.
Yes it work if I set fibaro for normal light off when there aren’t movements….so I don’t understand why your command doesn’t work.
Have you others idea for resolve that? Maybe I must re instal the sensor ?
Help me please
What are you using as your HomeKit Hub? HomePod, AppleTV or an iPad? Is it updated to the latest firmware?
Hi Stefan,
Sorry for delay.
I have Apple TV iPad HomePod ho pod mini and for homebridge I have raspberry….so much hub so I don’t know what is the problem. All with latest firmware yes.
I repeat this SC worked before but now it doesn’t work…I don’t know why
😢😢😢
Sorry for the delay Fede. I’m wondering in case you’re running the beta of tvOS, etc?
Hi Stefan,
No beta tvOS, only iPadOS beta
I wonder if that could be part of the problem. I’ve been trying to find out what could cause this, and I noticed that people running the beta has had problem with shortcuts using if-statements.
The problem is beta iPadOS and use ipad like an hub in app home.
I deleted it and now the automation works, yeah!!!!!!!!!!
I’m much happy now 😊
Thank you for you help Stefan, please share others automations or SC automations so I can take inspirations 😊
Great! I’m really happy you got it working! And yes, I’ll post some more automations with shortcuts in the near future 🙂
Hey, really love your shortcut cut since yesterday it stopped working after I updated to iOS 15 for iPhone, HomePod and Apple TV. Do you have any idea ?
Hi Andreas,
I’m updating everything myself right now. I’ve get back to you as soon that I’ve solved it. I got feedback earlier that this was happening with the beta as well, but I hoped Apple would have solved it for the real version.
Andreas, I can confirm that it stopped working for me as well as soon as I updated the AppleTV to tvOS 15. However, it was only the shortcut that turns on the lights that stopped working, the shortcut turning off the lights had no problem.
I tried deleting the automation and then redo it. It now works, but only if I omit the part where I check how bright the room is. As it is in this automation, you might as well take away the shortcut for turning on the lights, and only use a normal automation (since the checking for the room brightness seems broken right now), and just use simple automation to turn lights on.
I’m using a slightly more advanced shortcut at home, where it checks the time of day and in case we’ve gone to bed. In that case, it only turns the lights on to 1% in the kitchen. This part worked without a problem.
So in short, it seems like using the lux meter in the motion sensor as a conditional is broken in iOS 15 / tvOS 15. Hopefully Apple will get it fixed.
Thanks! Hope Apple will fix the Lux thing as this is soo good.
I’ve found a workaround. You cannot use the lux directly in the if statement, but if you follow this, it will work:
Use the Get the state of Home action, and choose the light sensor and current Light Level. Then use the Get numbers from Input action and use the previous Current Light Level as input. Then use Set Variable, use a name (LuxLevel) which you set to Numbers from the previous action.
Now you can use the variable in the if statement, and this will work. This workaround also works for using lamps brightness levels in if statements. It’s a bit cumbersome, but at least you can get the same functionality.
Could you post a screenshot – not very good in rebuilding this without screenshot 😅
Of course! 😊

Creating a variable is actually an unnecessary step, you could just use the Magic Variable thingy, but I think this makes it even easier to understand. Hope it helps 🙂
Big thanks!!!
Hi dear Stefan,
Pity but with iOS beta 15.2 the shortcut for light turning off the light doesn’t work.
Have you some suggestions for to help me please?
I have always problems 🤣 sorry
Hi Fede,
The iOS 15.2 beta isn’t out yet, do you mean the iOS 15.1 beta 2 for developers?
Have you checked my answer to the comment just above this with the screen shot?
Yes sorry for mistake, 15.1 beta 2. Now I tried to make the sc again and all is ok.
I want ask you one think: is there a solution for put light on for example in the night (specific %) in the afternoon in the morning? Make a Sc about lux but set light on in different % for different part of the day….morning evening night.
I hope my English is good for make you understand ihih
Thank you
No problem. Yes, you can absolutely build a shortcut like this, and I can help you with it if you give me some specifics.
Do you want to use both time of day and lux as conditionals? For instance:
Between 0:00 – 5:59 (night)
>> If lux is less than 80
>>>> Turn on lamp to 20%
Between 6:00 – 9:59 (morning)
>> If lux is less than100
>>>> Turn on lamp to 70%
Between 10:00 – 17:59
>> If lux is less than 300
>>>> Turn on lamp to 100%
Between 18:00 – 23:59
>> If lux is less than 200
>>>> Turn on lamp to 50%
Something like this? If you let me know, I’ll create a screenshot of it for you 😉
The solution will use partly this technique: https://homekitautomationtips.com/the-power-of-the-format-date-function-and-how-to-use-it-for-shortcuts-using-time-of-day-or-sunrise-sunset-part-1/
Hi Stefan, thank you for all your time and availability.
Yes I’d like that when the sensor see the movement and the lux is less than ?% the light on…but in the morning the light on at 9% , in the afternoon light on at 35% and the evening light on at 25% and in the night at 9%
Can you make the SC like your example? And I will change the lux and % light for my use 🙂
I’d like also ask you if this long sc would be fast or you think is slowly for active ?
Thank you
Hi Fede,
Sorry for the delay. Here’s the base of the shortcut. I hope you getting it working nicely. A friendly tip: the Home app has been quite unstable for me since the iOS 15 update, so I suggest “saving” the shortcut as you’re making it by pressing next up in the top right corner, and then go back into it to continue.
A few comments on this shortcut. The best way to do this is to do the different time conditionals nested, but it gets a bit harder to follow when you do it that way. Instead, I added the Stop running shortcut action in a few places, so the conditionals before that is True, and the lamps have turned on, it can terminate the shortcut at that point. And this should be very quick to activate. The shortcut is not “heavy” as far as how much computing is needed.
Let me know if you get it to work, or in case you’ve got any other questions about it 🙂
Hi Stefan,
Sorry for delay.
Your SC is amazing and it works 🙂
Sometimes it isn’t much fast but it’s ok, maybe the problem is that you use Philips sensor and it have hub while I’m using fibaro sensor that use HomePod hub and it is different.
If I have others questions or request I will let you know
Thank youuuuu so much
Great 😀 Actually, my automations running shortcuts have all become a bit slower since iOS 15… I hope they will get back to their normal with future updates. And yes, if you’ve got any questions, just ask and I’ll do my best to help 🙂
Hey Stefan,
Yes I have another question ihihi
can I put in the same SC that you suggested also the SC that you posted about light off after tot seconds (or continue the light on if it says movement)? Or I need to make another Automation?
Thank you
Or I need only to put
-wait 30 seconds
-Get hue color lamp off
In this SC that you suggested
You need to have two shortcuts. One for turning on the lights when the motion sensor detects motion, and a second for turning off the lights when the motion sensor detects that motion has stopped. You use the one I posted for you for when motion has been detected, and the one at the top in the post for when it stops detecting motion.
Hi Stefan,
Im trying a Sc with only “TimeNow between” but it doesn’t work if I put between 1730 and 200 (17.30 and 2:00) and another TimeNow between 201 and 800 (2.00 and 8.00)
Have you a solution of the why it doesn’t work?
I can’t add the photo about SC sorry, I don’t know why ihih
Hi Fede,
Yes, that is expected behavior. As far as the shortcut is concerned, you are only comparing two numbers, not time values. If between 1730 and 200 is really the same as If between 200 and 1730 as far as the shortcut is concerned. You need to split it up into two If-statements:
If TimeNow is between 1730 and 2359
>> If LuxNow is less than X
>>>> Set lamps to X
>> EndIf
EndIf
If TimeNow is between 0 and 200
>> If LuxNow is less than X
>>>> Set lamps to X
>> EndIf
EndIf
I wrote about it at the end of this post under the headline Common mistakes.
Hope this helps.
Hi friend 🙂 I hope I can call you so after much messages 🤣
With so much time the SC doesn’t work….so the only problem is put 4 number with 4 number and 3 number with 3 number
So is better if between 17.30 and 23.59 if between 0 and 200 and if between 201 and 810…..
If I would put 10.00 and 1.00 The correct SC is between 10.00 and 0059, if between 0 and 100 right ?
I hope it’s correct and I understood ihihi
You are correct. If you want to check between 10:00 in the morning and 01:00 at night, you need to divide it into two conditionals:
if between 1000 and 2359
and
if between 0 and 100.
You don’t need to put 4 digit numbers together and 3 digit numbers together. If you wanted to check between 08:00 in the morning and 15:00 in the afternoon, you would just put:
if between 800 and 1500.
The only case where you need to be careful is when you go past midnight, and that’s when you need to divide it into two if-statements.
I hope this helped 🙂
Hi Stephan,
First of all, thank you for all the helpful examples and shortcuts you have been posting.
I have used the example as you showed it in the original article, and in most cases it works as intended.
My question is whether there is a way to stop the shortcut of looking for No Motion if I manually turned on a light (or through a scene).
What I mean is, if I go in a room then Motion is detected hence, lights turn on.
If I sit at my desk then the 3×30 starts running and turns off the lights. Is there a way that if I manually turn on the light and/or enable a scene to delay the No Motion shortcut even further?
Thank you.
Hi Andreas,
Thank you for your comment and your great question. Unfortunately, what you’re asking for doesn’t work directly in HomeKit. However, I’ve solved the problem by using an extra smart plug 🙂 If you happen to have an extra smart plug (or are able to buy one), you can use that as the enable / disable switch for the motion sensor.
The smart plug needs to be plugged into power, but nothing is plugged into it. You could name it “Disable motion sensor” and add it to the scene that you will trigger when you want the motion sensor to be disabled.
You then just add the following to the top of the shortcut that runs when no motion is detected:
If “Disable motion sensor” (the smart plug) Is On
>> Stop running shortcut
End If
By doing this, the shortcut will start by checking in case that smart plug is turned on (which you’ve done in the scene), and if so, stop the shortcut and leave the lights on.
It’s a bit sad that you need to get an extra smart plug for this, but at the moment it’s the only way to solve it. I used to have 3 or 4 smart plugs just for these kind of things, but has since started using a Raspberry Pi running Hoobs (Homebridge) so that I can use virtual dummy switches to do just this.
If you need help setting it up, just let me know and I can run you through it step by step.
Hi Stefan,
I’m back. I finally found time to tried your suggestion but it doesn’t seem to work.
What I’ve done is: (for this I used a door sensors rather than a plug or a dummy switch)
If door contact sensor state is open >
Stop Running Shortcut >
And then it had an end if here but it did work, so I move the rest of the shortcut above the end if which became
If Light A is On >
Repeat 30 times >
Wait 3 seconds >
If Motion sensor Motion is detected >
Stop running shortcut >
End if >
End repeat >
Set lights to off >
End if >
End if >
I’ve messed it up somewhere because it doesn’t turn the lights off if the door sensor stated is closed and No Motion is detected.
Can you spot the issue?
Thank you in advance
Andreas
Hi Andreas,
So, if the contact sensor’s state is open the light should stay on, and if the state is closed the shortcut should test for 90 seconds if motion is detected, and if no motion detected during that time, the lights turn off.
The flaw in your shortcut is that by moving the End if, the lights will never turn off. As you step through the beginning of the shortcut:
If door contact sensor state is open
>> Stop Running Shortcut
The shortcut will never get past this since the whole logic is inside If door contact sensor state is open, and if that is true the first thing it does is stopping the shortcut. However, if you use the Otherwise after Stop Running Shortcut, it will work.
(By the way, I’m using the “>” character to show indentation, just to make it more readable.)
If door contact sensor state is open
>> Stop running shortcut
Otherwise (if the contact sensor is not open)
>> If Light A is On
>>>> Repeat 30 times
>>>>>> Wait 3 seconds
>>>>>> If Motion sensor Motion is detected
>>>>>>>> Stop Running shortcut
>>>>>> End if (linked to If Motion sensor Motion is detected)
>>>> End repeat
>>>> Set lights to Off
>> End if (linked to If Light A is On)
End if (linked to If door contact sensor state is open / Otherwise)
This should work. If you have any problems with it, please let me know 🙂
Ah make sense!
Thank you! Made the changes. Will test and let you know!
So if i have 2 lights (A and B) in a room and door is must open . My motion sensor is usually detected motion for every 1 min
(Automation 1) :When i walk in the Room > light A is turn on for 90s
(Automation 2) :
If i’m still in there for next 90s => light B turn on and keep A on
If I’m not => all light turn off
Can you help to check (Automation 2) below
If door contact sensor state is close
>> Stop running shortcut
Otherwise
>> If Light A is On
>>>> Repeat 3 times
>>>>>> Wait 30 seconds (just don’t know if reverse the repeat and wait working?)
>>>>>> If Motion sensor Motion is detected
>>>>>>>>Turn on Light B
>>>>>>>> Stop Running shortcut
>>>>>> End if
>>>> End repeat
>>>> Set lights A+B to Off
>> End if
Hi Daniel,
So, I made a simple pseudo-shortcut to see if I understood correctly what you want to do. This would all be in one single automation. Does it look right?
If motion is detected:
>> Turn on light A
>> Wait 90 seconds
If door is closed, stop running shortcut
During the next 90 seconds,
>> if light A is on and motion is detected
>>>> turn on light B
>>>> stop running shortcut
if time runs out
>> turn off lights A and B
And yes, there is a difference in the wait loop if you check every 3 seconds or every 30 seconds. If motion is sporadic and not constant, the motion sensor state will go between three different statuses: motion detected, motion stopped and no motion (they might have slightly different names). If a single motion is detected, the status will change from no motion to motion detected. If no further motion is detected, it will go to motion stopped after about 4 – 5 seconds, and then after another 4 – 5 seconds it will go back to the default status: no motion. By checking the status every 3 seconds, we are able to catch these when they happen. If you only check every 30 seconds, there’s a possibility that the whole cycle (no motion -> motion detected -> motion stopped -> no motion) happens while your shortcut is taking the 30 second wait.
Hi Stefan,
Thanks for your quick reply. but seems i can’t combine in one short cut i have to separated into 2 automotions
For “During the next 90 seconds”
If i choose repeat 30 for 3s => motion detected when i walked in and turn on light A , at first 3 second => motion detected still there and light B turn on
So i only have 1 choice that to turn on light B for the 2nd motion detected is know the exact period and put in
Repeat 1
Wait (period , e.g: 60-65s)
Do you have any idea to check at the 2nd detection (without know the period) then light B turn on
Ah i can do it now .
Just still use during 90s by after waiting first90s
repeat 30
wait 3
> turn on B
>endif/end repeat
turn off A
Thanks alots, work like a charm now
Yes! That’s exactly how I would do it 🙂
Just one thing to remember if you want to lengthen the wait time. The total shortcut runtime can’t be over 10 minutes if you use a AppleTV or HomePod as a HomeKit Hub, and even shorter in case you use an iPad as the hub.
Thank you for your reply and sorry for spelling your name wrong :/
I’ve got a few Meross plugs lying around so I can try what you have suggested but I am also using homebridge for SwitchBot Bots, so maybe the dummy switches route might be easier.
Thank you again!
No problem 😉
If you’ve already got Homebridge running, then dummy switches are definitely the way to go. And there’s so many uses for them 😁 I’m actually writing a new blog post about how to use dummy switches (or extra smart plugs) for different things.
It might be a good idea to create a new room in HomeKit (I’ve called min Automations) for the dummy switches, so you don’t crowd your real rooms with them.
Hi friend Stefan 😊
I can’t wait to see you post about dummy.
So will be good to do a dummy for to stop the motion sensor, for example:
Call dummy “lights on block” and I put the action disable motion sensor (int he room that I want) ———> all this for block the motion sensor and not have time 3×30
After it I must disable the dummy and the action comes back at origin
Does it right? If it’s ok I will do immediately 😊
Ah I have also another question, saw that there is a possibility to have Timer dummy I’d like to ask you some examples for to use Timer dummy for the house. It’s the same use for light on and after 3 minutes put light off?
Hi Fede,
Yes, you have a dummy switch called “Lights on block”, which you turn on when you don’t want to override the sensor. However, you need to add to an if-statement to the shortcut that turns the lights on with the sensor and an if-statement to the shortcut that turns the lights off with the sensor.
You would start both shortcuts with this:
If Lights on block Is On
>> Stop Shortcut
End If
This way it starts by checking if you have disabled the motion sensor, and in that case just stops the shortcut.
Now, depending on how you do this, you could build in a timer function for the “Lights on block”, so it goes back to normal even if you forget to turn it off. If you are using a dummy switch in Homebridge or Hoobs, you are able to set a Time value for how long the Dummy switch will wait before turning off. This number is set in milliseconds. So depending on your use case, it might be useful to put it to auto turn off the “Lights on block” after a few hours, in case you forgot to turn it off yourself.
If you’re not using a dummy switch in Homebridge or Hoobs, but rather using a smart plug to do the same thing (when the smart plug is turned on, the motion sensor is turned off), you are not able to do the exact same thing. But if control the smart plug from a button (like a Hue Dimmer Switch), you can set an auto turn off timer that way.
Am I correct in thinking that the Timer dummy you’re talk about it the Timer function on the dummy switch to turn it off? In that case, yes it can be used as a timer to turn lights off. You can even set it to be “Resettable”, which means that when you turn the Dummy switch on, it starts the countdown to turn off. But, if you turn it on again (even though it is already on), it will reset the timer.
I’m actually using this as a “belt and suspenders” solution for the kitchen lights that are usually completely operated by the motion sensor. I’ve noticed that after the iOS/tvOS 15 update, every now and then the turning off the lights when no motion has been detected doesn’t work. So, I’m using a dummy on a timer, which resets every time the motion is detected, which turns off the lights when the dummy is turned off. The timer on the dummy switch is set to 5 minutes. So, in the rare case when the normal shortcut to turn off the lights after 2 minutes with no motion doesn’t work, the dummy switch with the timer turns them off a few minutes later.
Sorry for the long answer.
Hi Stefan,
Don’t worry your reply it’s very good for explain everything, thank you.
You told me that both shortcut for light on and for light off, but I use your shortcuts for make it.
One shortcut for lights based on the light sensor and one shortcut for light off when motion sensor see no motion; so I think I need put your
“If Lights on block Is On
>> Stop Shortcut
End If”
Only in the light off shortcut right?
However I use in the bathroom one hue switch so I can do that when I push the button light on I put also the action for dummy “lights on block” ON and when push the button for lights off the action for dummy “lights on block” OFF
What do you think? It’s it correct?
Thank you
It depends. If you only want to prevent lights from turning off, it’s enough to put it in the one shortcut. However, if you want to use it to disable the motion sensor completely, you need to put it into both shortcuts. I want to have the ability to use only natural light in the kitchen on a sunny day and keep the motion sensor from turning the lights on, and that’s why I’ve put it in both shortcuts.
Hi bro Stefan,
I don’t know if you tried this shortcut that you done for help me with the new iOS 16 beta.
I had to redo everything cause it doesn’t work anymore.
But I have this problem, it’s working now but at every time in day it turns on 10% light ….I settled it only for 0 and 959 but in every time of the day it turns on 10% light.
It’s also weird that the first shortcut that we done it works only if I open it and I force the automation, and it works very good and not set 10% light…..the oddities of life ahahah
Have you some advices for me for help me please ?
Thank you bro
Ooooooooook I wrong to put the info in the current data and now everything work 🙂
Sorry for bother and I can’t wait to see others good ideas from you for HomeKit.
Thank you and have a nice weekend
Thank you for this article, helped me set up my kitchen light properly
Hi Paul, and thank you for your comment! Have you checked out the more advanced version, where the lights dim a bit before turning off?
Is this still needed with iOS 16.2? I tried with the default “turn off after n minutes” but this doesn’t work if the light was switched on manually with a Hue Button.
I guess it depends. As you noticed there are cases when the default doesn’t work. I also know that many people want to be able to customize this function, and doing it within a shortcut gives you that freedom. For instance, you can use a Hue Button to set the lights to toggle between 100% and 95% brightness and then set the shortcut to not turn off the lights if the lights are at 95% brightness (a sort of override). Perhaps you want different behavior depending on the time of day, or if it’s the weekend. And many use the more advanced version I posted about, where the lights first dim down giving you a warning, and then 30 seconds or 60 seconds after that turn off in case no motion has been detected.