Piston executed even when subscription changes to not subscribed state


#1

1) Give a description of the problem
Following piston gets executed even when Presence Sensor changes to NOT present. Piston is subscribed to be triggered only when Presence Sensor changes to present.

This is just a fast-made example so the logic may not be consistent.

2) What is the expected behavior?
Piston is not executed when Presence Sensor changes to NOT present.

How could this be done in an elegant way? I know that I can put the last action to every if clause but that would be just copy and paste programming.

3) What is happening/not happening?
Piston is executed when Presence Sensor changes to NOT present.

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


#2

This is the problem with else statement. In order to know if the presence changes to present a piston will subscribe to any change of the presence sensor. According to your logic, if the presence sensor changes to active, then do the first part, if it changes to anything else, it will execute the else. To be safe when triggering on conditions like this, keep the top level a simple if with no else and then put all your other logic within the if statement. Something like this:

If presence changes to present
Then
   If other conditions
       Do stuff
   Else different condition
       Do different stuff 
   Endif
Endif