Can pistons be scheduled when mode changes?


1) Give a description of the problem
Trying to understand if its possible to make a piston run when a mode changes.

2) What is the expected behavior?
The intent is to have a light go on when I am “home” after sunset, even if I arrive home after sunset.

3) What is happening/not happening?
I beleive the piston will only run once and not run again when the mode changes from “Away” to “Home”

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)*


BTW, this is my first piston … you can ignore that it is currently set for Tuesday … I was just testing with that time … (I know how to test for Sunset) … also probably dont need the test for power = 0 (that a diff question)



Do you set your hub to “Home” and some other mode when you’re not? Or do you use a presence sensor that should be incorporated into this piston to determine that? If the former, all you need is:

[select Virtual Device from the drop down] Location Mode is Home
[select Virtual Device from the drop down] Time is between Sunset and (when you want automation to stop)

With outlet/switch/device
Turn On

optional - if you want it to automatically turn the light off if you leave or if time progresses beyond the later limit
Turn off

If you save this piston, you should see an orange lightning bolt for BOTH IF conditions (like you see in row 18 of the piston in your original post. This means the pistons is ‘subscribed’ to each condition and will execute when there are changes.

It will execute each time your location mode changes (home, away, night, etc.)

It will execute at Sunset (the light will turn on if you’re home, for example), and at the end of the time window you select. At the end of the time window, if you choose to have the piston turn the light off, it will switch off whether you’re home or not since the condition is being home AND time being between sunset and xxx.


Hi michicago -

Thank you, very helpful. I think I’m beginning to understand the subscribing events etc. Yes, I have separate logic to set the mode (various states) … So with the changes shown below my assumption is that the light will go on if I’m home AND its between sunset+15 and 10pm … and light will go off at 10pm OR I am not home (or any other mode) … If that’s correct, does this mean that if I leave, they go off and when I come back, if its still between those hours (and days) then the lights will come back on? Seems yes since new events (mode changes) happened.

Thanks for your help!!


Looks good! You can simplify the latter 2 IF statements though, since the code will only hit the ELSE portion if either of your first conditions are false, all you need is:

Location mode is Home - Evening
And time is xxx
With Outlet 1
Turn on
With Outlet 1
Turn off


Thanks @michicago … but I think we still need the checks … so that during the week (not F, S, S) the lights will turn off after 10 … also … if we turn the lights on manually during the week … we would want them to turn off if we are no longer at home…

Did I get that right?


If either of your conditions evaluate false, the ELSE code will run.

I think the checks are redundant but you can leave them there if you prefer.