Motion light in bedroom


1) Give a description of the problem
Dont turn light on with motion until i’m out of bed

2) What is the expected behaviour?
During day mode, i’d like the light to turn on 100% when motion is detected and off after there hasn’t been motion for 2 minutes. Day mode currently gets changed at sunrise. The caveat is I don’t want motion to trigger the light to turn on if I’m still in bed and happen to move and trigger the motion sensor. I need to account for me being in bed or out of bed. When the system is in evening mode, motion should trigger the light to light to turn on 20%, and off after 20 minutes of no motion.

3) What is happening/not happening?
I cant figure out how to account for me being in bed or not. I dont want to flood the room with light if I happen to move in my sleep and the system is in day mode. Perhaps motion wont be turned on in day mode until the smart dimmer is physically turned on at the wall, or a google assistant command triggers a routine that slowly illuminates the light.

4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full

Motion Based Light EXCEPT when Manually turned On

Only you can answer this question, because only you are in tune with your morning habits… There are literally hundreds of ways of detecting such events, but it is up to you which would work best for your lifestyle.

A few examples:

  • First motion in the kitchen after 6am = Daytime (won’t work if you have indoor pets)
  • Refrigerator opened between 6am and 9am = Daytime (won’t work if partner does this also)
  • When TV comes on after 6am = Daytime (won’t work if partner does this also)
  • Telling Alexa, Good Morning = Daytime
  • Auto timer set to fire 8 hours after you go to bed = Daytime
  • When Android is unplugged from charger after 6am = Daytime
  • Button next to bed is pressed = Daytime
    etc etc…

For the record, my favorite method is to tell Alexa Good Morning, which flips a Simulated Switch, which triggers a piston, which does a whole lot of cool stuff. (including telling my SmartHome that I am now awake)


Understood. What I don’t understand is how to account for that. In my particular instance. I don’t want the motion sensor to start turning the light on for the day until i tell my google home good morning for instance which would slowly turn the light on or of i turned the light on by pressing the dimmer on the wall. How do I account for that? I’m thinking that would be done with a boolean variable called activatemotionsensor for instance. this variable should be set to false when the system goes into nite mode. the variable should be set to true if i manually turn the switch on in the morning, or if i tell the google home good morning, which would slowly start to turn the light on. After either of those things happen, and the variable is true. The light should turn on with motion and off with no motion.


Your original piston can be something like:

IF Sensor's motion changes to active
    IF {@awake} is true
        Do normal daytime ON stuff
    END IF

IF Sensor's motion stays inactive for 2 minutes
    IF {@awake} is true
        Do normal daytime OFF stuff
    END IF

This resolves all the daytime action, but you’d still need to implement nighttime activity when {@awake} is false. (or just use an independent piston / Routine etc to do any fancy stuff)

Pro Tip:

Personally, I think it is worth the effort to try to “teach” your SmartHome when you are asleep or awake. (and keep that data in a @global variable) Once that element is added to your SmartHome, then a lot of other pistons can become smarter, and do things differently, depending on whether you are awake or not.


Thanks. How can I set the awake variable with a physical interaction through either the switch or google home command? Furthermore, while I am testing, troubleshooting, is there a way to view the current value of the variable?


A separate (very small) piston:

IF Switch changes to ON
    Then Set variable @awake = true

IF Switch changes to OFF
    Then Set variable @awake = false

Up top in the define section, I leave my variables (no value set).
(When I need to set a variable, I do it in the body of the piston)

If you go this route, you will always see the previous data in the variable up top.

This last bit is referring to local variables… The first bit was about globals.


Sorry, not following. i don’t understand where i can check the value of awake. I manually turned on my light. How can I awake sure awake=true?


Perfect example! At the moment, the variable is NOT set.
Once you turn on Dimmer 1’s switch, you will see “true” added to the end of line 17.

One small observation though… You are currently writing to a local variable… I was recommending writing to a global variable, so that other pistons can see if you are awake or not.

Let me know if you need help creating a global…


interesting, because i turned the light on and its currently on.


Not sure why there are no trigger's in your left margin…

Perhaps try turning Dimmer 1 off… Waiting 5 seconds… and then turning it back on.

If your piston is not executing, then please turn on Trace and set logging level to Full.
(step-by-step here)


Sorry, I had the piston paused. Now i can see True. However, When i change smartthings to Night, the variable isnt setting to false. Thoughts?


System variables do not make good triggers
Here is how I use Location mode as a trigger:


… which spits out:


PS. Once you are happy with your testing, I would recommend using a global variable, (instead of a local)… If you decide to keep it local, then other pistons will remain clueless as to whether you are sleeping or awake.