Oh thank you for that… I didn’t know that was the case.
How to override motion sensor light?
I did just notice one more thing that may occasionally cause issues.
I would change this block:
To this instead:
IF X's motion stays inactive for 2 min <-- Trigger
Then
IF lightStatus is true <-- Condition
Then
Turn off Bulb
END IF
END IF
The reason I placed another IF inside the first IF is because we only want to check that variable after the two minutes have passed. In other words, we shouldn’t worry about what the variable is at the beginning of the 2 minutes. We only want the variable checked after the timer has expired.
@WCmore generally, I try to avoid nesting if’s like the plague. Could you not just use a only when {lightstatu} is true restriction here instead?
To be honest, I am not 100% sure @Gopack2.
(I tend to avoid restrictions like the plague, LOL)
I can say with confidence though that a conditional IF inside a trigger IF works beautifully, and will only check the status of the condition after the trigger event happens.
I agree. I have a piston using up to four conditional IF’s inside a trigger ‘IF’ without issue. Works every time - and only when it should (as per the driving trigger).
This mirrors a scenario that’s about to happen for me. My wife requested a light go on in a vestibule whenever someone opens a door in that area. Makes sense, except that the light going on at 2am wakes whoever else is asleep… and some of us see very well in the dark.
So I ordered a trio of zigbee buttons, one to be mounted on the wall in each of the rooms that lead to the vestibule. I will press the button, and it will disable the light from going on.
This thread has given me some thoughts on how to do it. I’m tempted to leave the motion/light in Smart Lighting so it operates locally (I think), and have the press of one of these buttons do a few things.
The buttons should be set up for momentary operation.
Pressing one of them at any time turns on a simulated switch.
The simulated switch state is part of the Smart Lighting, which has an available condition that says “if switch _____ is (on/off)”. So that sim switch would normally be off, and the motion sensor would trigger the light on. If I press the button, it turns on the sim switch… and the light would not go on with motion.
A piston would be triggered by that sim switch being turned on. Its job would be to count five minutes, and then turn the sim switch back off. So the light once again gets turned on by motion.
As long as the buttons are out of sight of the motion sensor, you could skip the SimSwitch entirely. Maybe something like this:
Piston 1 (new piston)
IF
Any of Buttons A, B or C changes to on
Then
Set @override = true <-- Global Boolean Variable
END IF
Piston 2 (slight modification of your ‘Motion Sensor’ piston)
IF
Vestibule's motion changes to active
and
@override is false <-- NEW LINE
Then
Turn on light (as normal)
END IF
IF
Vestibule's motion stays inactive for X minutes
Then
Turn off light (as normal)
Set @override = false <-- NEW LINE
END IF
The only time the above code would fail is if someone pressed the button, but then avoided the motion sensor. (Although it would be easy to code in an extra line to account for this, or it will fix itself as soon as someone walks by)
This is what I have right now and it’s not working. I manually switched the light to be on but the light still turns off after no motion detected.
I don’t know how what @WCmore suggested works line 35 (he is the pro so, go with his way)
The only thing is, I believe when a piston is triggered, if you have defined variable, even if it changed the last time piston ran, it will go back to original status you defined.
if you say
variable = TRUE
Execute this that
and then
piston do this do that
Set variable to FALSE
it will remain false UNTIL the piston is executed again.
So try not assigning anything on line 17
I apologize for the confusion. I should know better than to try to help two people in the same thread simultaneously.
Instead of re-creating the wheel, here is a great piston that does exactly what you want @2Charlie
@MCmore, thanks for the link. I’ll check it out. However, in the mean time, I think the logic in the IF statement from line 32 to 44 is incorrect. So, maybe something like this?
So I followed this post here and I saw this edit.
Does this mean we have to interact with the SmartThings app if we need to turn off the light?
If I am not mistaken, it can be done via the app, thru Alexa, or by turning off the wall switch.
(you might want to ask specifics on that page though. @bangali is always helpful)
Just a small note.
The 1st piston on that page is for a dumb switch and smart bulb combo
The 2nd piston on that page is for a smart switch and dumb bulb combo
I use a slightly modified version of the 2nd piston (smart switch with dumb bulbs) and you are correct about the ability to turn the light off with Alexa, the ST app or the wall switch.
At this point my code above is not working. The kitchen light does turn on when detect motion but did not turn off after 2 minutes.
Okay, a couple of basic questions since I’m new.
- The execution is from top to bottom, correct?
- If the condition is met, does it quit or continue executing until the end of the code?
- Is the value of the variable only last for through the current execution?
Hi @2Charlie
1 - Yes but…
2 - Depends.
If your code after condition stops everything then it could stop. (cancel all depending tasks etc)
But normally it will go al the way to the end.
3 - Depends.
if you defined a variable, everytime piston runs it will go back to that…
lets say:
local variables:
variable {teststatus} = false
(piston does lots of things here and at the end you say)
set variable {teststatus} = true
END
unless this piston runs AGAIN, your variable will always remain TRUE
Global variables :
You define them outside of the piston. So, running the piston by it self will never change the value of a global variable. Only what ever YOU say in the piston will.
Just to clarify a tiny bit… If the variable is not defined at the very top, but is written to in the code somewhere, it will remain indefinitely until it is overwritten.
For example, if you run this piston once, the SMS will error (null variable). A moment later, the variable will be set correctly. If you wait a year and then run the piston again, the variable you set a year ago will come thru your SMS message
execute
Send SMS = {variable}
Set variable = "some data"
end execute
No. When the piston runs again, it keeps the old data in the variable until the moment your code writes new data to it
What you describe happens only if you force in a variable in the top ‘define’ section.