How to override motion sensor light?


#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.


#47

Well, line 17 in your screenshot may not be exactly line 17 inside your piston. (but it’s the only visual reference I have) The true/false should be right after “boolean lightStatus” at the top.

If there is nothing displayed after that, then your piston has not run even once successfully. (remember the TEST button does nothing in this piston. You have to actually walk in front of Motion Sensor 2 and/or toggle White Bulb 1’s switch for your piston to do anything)


#48

If you’re referring to /* false */ at the end of line 12? If so, that explains why it’s not turning off the light after 2 minutes.


#49

So the question is, why is line 27 not executed after the light turns on?


#50

I would start by manually turning Kitchen Lights switch off… leaving the room for 5 minutes (so the motion changes to inactive)… and then walk in front of the Kitchen Sensor.

Hopefully, the light comes on.

Then walk back to your computer, and the variable should be /* true */ for the next two minutes.


#51

If I manually turned off the light, the variable value does turn to true. However, when I walked back into the room and motion sensor detected me, the variable value turns to false again. Is this normal behavior?