Motion Based Light EXCEPT when Manually turned On



This piston will turn on a light with motion and off after 5 minutes of no motion. But if user switches the light on it will not be turned off by motion, instead user will need to turn if off from the ST app. If motion turned on the light and you want it to stay on till you turn it off, just switch the light off and on. The isBetween check sets the light level to 100% when between 4am to 11pm otherwise to 10% only when turned on by motion. note that while i use a light in this example it could be any device controlled by motion.


EDIT: edited the description to clarify that when you need to take the light out of the stay on mode, you turn off the light from the ST app.

EDIT2: added the following version as well which can be found in the thread below for use with smart switch and dumb bulb. the first version works with dumb switch and smart bulb combo. this has the additional option of not controlling the lights unless it was turned on by this piston.

Help: Auto light ON with motion EXCEPT when TV is ON
How to override motion sensor light?
Physical turn on switch to override all other conditions in piston
Disable Motion Sensor
Turn ON & OFF using alexa/GH
Fan turns on when it shouldn't!
Door turns on light but motion turns it off
Improve motion light piston to consider physical interaction
How to override motion sensor light?
Garage Lighting Automation
Need help with Overriding Piston
Please Help With creating My First Piston!
Garage Lighting Automation
Conditions evaluating incorrectly
Leviton Switch how was it turned off?
Light Control – two questions (variable evaluates incorrectly; “switch physically”?
New Guy, A Bit Overwhelmed
Deck string lights won't stay on outside of this piston
Ignore new motion on physical switch off
Open door and set light level
Light wont turn off
How to override motion sensor light?
Light motion piston stops
Bypass my motion sensor
Light on and off with door sensor
How TCP is set to NEVER - when WAIT is not working in your piston
Help with Garage Door Auto Close
How to add Except with manual switch
Motion Light on/off EXCEPT when switched on
Turn off light only when light wasnt on beforehand
Are you a Newbie, this is your post
New to WebCore, need help on / auto off
How to make a piston fire only if switch is not already on
How to turn off a piston for a short time that activates a light on motion
Timer with motipnsensor
Need help with Overriding Piston
Need help with Overriding Piston

Interesting, I do something similar but reverse. I will have to get it posted.

I do like the simplicity of the bulb event watching to toggle programatic mode.


thank you. i am a big fan of simplicity. :slight_smile:


Was thinking of how to incorporate manual intervention for my motion triggered bulbs and like how you have used the variable to distinct between that and a manual turn on. Thanks man!


you are welcome.


Thanks for this - I will likely use it in reverse.


you are welcome. share as an example when you ready. :slight_smile:


Okay - so I’m tryig to figure this out until I gave up and came here. Your example is exactly what I was intending to do, but when I was doing it manually ,I can’t find the set variable action. soo…

Where in g-d’s green H-E-double hockey sticks do you add an action to set variable? I cannot find it for the life of me in Actions.


looking for this?


URGH! sorry - that “location” thing threw me off. I was like, no i am not interacting with Location.

Okay okay - time to fire this thing up now. seriously, my only reason for even trying web/CoRE is to solve this problem that I just couldn’t with the ST ide. will probably end up moving other stuff here as well.



great - got it working like a charm … now, what’s the cleanest way to do something like this:

set lamp to 80% from sunset minus 30 minutes through 9pm, and 20% from 9pm to sunrise + 30 minutes?

I really like the isbetween that’s already there, but trying to figure out if we can tweak it without replicating the logic. I’m guessing either precalculate it at the top, or perhaps just copy the do section?


If you have modes that line up, you could tie it to them:

But I’m also curious how to modify the original expression.


ehh, no reason to be sorry … we all go through this.

thats how we all started. :slight_smile:


add another condition to the if statement:

isBetween($now, addMinutes($sunrise, 30), addMinutes($sunset, -30)) is false

then with the light do this

turn on
set level to (isBetween($now, addMinutes($sunset, -30), time("21:00")) ? 80 : 20)

this assumes that you dont want the light turning on between sunrise + 30 and sunset - 30


I’m probably missing something, but doesn’t this all fall apart the minute a user manually turns on a light?

When a user turns on a light it stays on until he turns it off.
When a user turns off the light there literally no longer power available to the light. The only way to get the light back on is to manually turn it on - and now we’re back to the beginning.

What am I missing?


use the ST app to turn off the light, not physical switch.

but, the scenario you describe could be handled as well … let me know if you need it.


I’m definitely interested in a solution for that case, yes. Probably just as interested (maybe more) in seeing how it’s done. Thank you!


since you dont really need it and are just interested, heres a way to do it but havent tested it :slight_smile:

note: this will always work with a smart switch and dumb or smart bulb combo. it will also work with a dumb switch / smart bulb but only when the switch is not physically turned off rather the smart bulb is turned off / on thru the ST app when you want it to stay on or exit that mode.



I’ve modified what you wrote for what I need this to do for me, but I want to make sure I did it correctly (I don’t think it’s exactly right yet.) I’d like the sensor to detect movement and stay on…if it doesn’t detect movement, it can turn off in 20 seconds…As far as the light switch being turned on manually, I don’t think I need this, but I didn’t remove that part, I don’t think…anything I need to modify to get this to work for the above scenario?



you are doing good. just add the motion sensor to the first to 2 if statements and it should work for what you need.