How to override motion sensor light?


#27

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)


#28

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.


#29

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


#30

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


#31

@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?


#32

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?


#33

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


#34

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.


#35

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.


#36

Okay, a couple of basic questions since I’m new.

  1. The execution is from top to bottom, correct?
  2. If the condition is met, does it quit or continue executing until the end of the code?
  3. Is the value of the variable only last for through the current execution?

#37

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.


#38

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

#39

So, if the piston runs again then it starts fresh with the initial value, correct?


#40

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.


#41

Another way to say this:

When a variable is set, it is permanent, and will not ever change.

There are three exceptions:

  1. If you manually change the variable (great for testing new code)
  2. If the ‘define’ section is left blank, it will only change if you place code somewhere in your piston, the piston is somehow executed, and the conditions are true for that block. (my preferred method)
  3. If the piston has the variable defined in the top section, each time the piston runs, it will ‘reset’ to that variable. (the only time I hard code in the define section is when I do not change it later in the code)

#42

This is what I have right now and the does not turn off after the motion sensor has changed to inactive.


#43

According to your piston, it should be two minutes after the sensor reports no activity. Depending on your motion sensor, this could be a few minutes longer than 2 minutes. (most sensors report inactivity between 6 seconds and 6 minutes after the last activity)

If you have totally left the room for over 8 minutes (6+2) , and the light is still on, then I would check your variable in the piston to make sure {lightStatus} is true.


#44

How do I check the value of the variable? I removed the variable in the second piston and the light does turn off. So, it’s has something to do with the value for sure. I tried the Test but I wasn’t sure how the debug work.


#45

If you look at your piston on line 17, there should be either true or false at the end.


Without that variable in place, you will no longer be overriding the motion sensor.
(I would go back to using import code ‘tb64’)


The TEST button will do nothing on this piston. Your piston only fires when something happens in your motion sensor and/or White bulb. (notice the lightning bolts in the left largin… Those are your triggers)


#46

Is this after I clicked on the Test button? I do not see anything after the variable or line 17.