Review of piston that waits for sensor change before continuing


#1

1) Give a description of the problem
I have a piston that, when triggered, waits to lock the door until the door is closed. After the door is closed, it waits until the door is locked then runs another piston that texts me the status of all the doors and door lock.

Is this the proper way to set up a command that waits for the status change of a sensor (e.g. contact changing to closed or lock changing to locked)?

**4) Post a Green Snapshot of the piston!


#2

Just to clarify that this piston works, but I’m wondering if this is the ‘proper’ way to do it.


#3

Anyone?


#4

I don’t have locks controlled by webCoRE so haven’t really thought about the best way to do this.
If it works 100% of the time without delays or any errors in the logs then I would say it’s the best way of doing it. :wink:


#5

I don’t think I’d have 1 second loops in there. I’ve gone to Lowe’s without closing my door, so the piston would just loop and loop and never continue. Why not just use separate IF blocks and execute the next step if the last one changes something?

IF door changes to closed
AND location is away
THEN lock door

IF door locks
THEN send message “Door locked.”


#6

@Equis, that’s a good idea - i didn’t think of attempting that. That’s a good point on the infinite loop problem; I suppose I could build some code to account for the runtime of the loop, but probably cleaner to set up some IFs.


#7

So i set up a test piston using IF statements - but the problem is that the IF gets evaluated once when the routine runs instead of waiting to run based on an event.


#8

Make sure you have at least one IF from the triggers section. Then you can qualify that with conditions. IF something changes (trigger) AND something else is some state (condition)…


#9

This is what I have: