WebCore: Nightlight Piston

I have a piston that I can’t quite get working. The goal is to have the floor lamp in my office act as a night light triggered by a motion sensor if I get up in the middle of the night to use the bathroom.

My desire is that the piston turn on my office’s floor lamp bulb (Philips Hue) and set its level to 20% if time is between one hour of sunset and one hour past sunrise, but only if the lamp is off already. If it’s on, I’m probably in there working so I don’t want it changed. The restriction works fine and it doesn’t mess with the light if it’s on already, however, right now it comes on but never goes off and I don’t understand why.

Thanks for any assistance on this.

Jason

This seems similar to the situation below. Maybe the motion keeps flipping active/inactive within 2 minutes and cancelling the piston?

https://community.smartthings.com/t/help-needed-with-my-first-piston/105241/4?u=farlicimo

Why would that cancel the wait? As a C programmer, having the statements in a ‘then’ statement terminate before completion is unexpected.

Jason

The webCoRE default is to cancel tasks on condition change. The motion detector going from active to inactive generates a condition change.

Its an option to cancel or not cancel. Also there are settings for if you cancel on piston state change, condition state change, or both.

In the WITH set TCP (Task Cancellation Policy) to never.

Robin,

Your way is cleaner but I my condition of not adjusting the light if it’s already on complicates it. The if statement will fail the next time through and not reset the timer. What’s the slick workaround of that?

Jason

Okay, I haven’t used variables in that way because I’m unsure of the rules of initialization. But your code implies that the variable is not destroyed or altered between piston runs. I’m sure your code works, I’ll give it a try.

Thanks

I thought that was true, nice to have confirmation. Thank you!

1 Like