Turn off light if contact sensor is open for longer than 10 sec


#1

1) Give a description of the problem
I want to create a piston to only turn off a light if a contact sensor is in the “open” state for longer than 10 seconds when it goes back to the “closed” state

2) What is the expected behaviour?
If I leave the door opened for more than ten seconds, when I close it, the light should turn off. If I leave the door open for less than 10 seconds, do not turn off the light.

3) What is happening/not happening?
If I leave it open for more than 10 seconds, the light isn’t turning off.

Please help me!


#2

You hard coded false up on line 2.

I would leave this (no value set), and then in the body of the piston, determine when to set it true and when to set it false.


#3

Thank you. That helped and I ended up doing this


#4

Looking much better, but two quick observations:

(1) I would ditch the “Turn on” inside the ELSE block.
(the light will already be on from line 27)

(2) I would also move line 43 (Set variable to false) to line 27.5, (right before the WAIT), so it resets itself each time the door opens.


#5

Thank you!