Would this work from top to bottom? Does the Else IF work if the IF is not true?


#1

1) Give a description of the problem
Looking for advice as to whether this piston will work for both cases, the IF and the ELSE IF.

2) What is the expected behavior?
I want the global variable @garagedoorshut to be corrected if it differs from the contact sensor garagedoorfor 60 seconds.

3) What is happening/not happening?
not sure, hard to test .

**4) Post a Green Snapshot of the piston![image|45x37]


#3

Contact sensor 4 is the garage door sensor. Yes.

I have other pistons that send messages and set the global variables when the garage door opens/shuts, but being zigbee, sometimes the message does not make it through to ST, and the global variable does not get updated. This piston is to rectify that problem.


#5

@garagedoorshut is a global variable.
garage door is a contact sensor.

There is obviously room for the global variable to get out of sync with the door sensor. I know this happens. I’m not asking for whether it can or can not happen. I want to know if the piston above will correct the situation when it does happen (because it is).


#7

I dont think I’ve explained myself clearly.

All I want to know is will the ELSE IF statement work in this scenario.

IF condition A
DO this
ELSE IF condition B
DO that.

Can the ELSE IF be evaluated as true, after the IF is evaluated as false.


#9

Thanks for your help, but I just tested it, and it does work, contrary to the advice above. When the global variable is out of sync with the contact sensor, it corrects after a minute of incorrectness.

I guess I’ll open the garage door and see if it works for the second half of the statement.


#10

Yes. It’s functionally the same as having a separate IF block. You can have as many of those as you want (although it gets messy to read if you have too many). But the logic is correct. That is exactly what the Else if command is used for and how it works.


#11

recommend not using an else if block specially when it has a trigger. though it should work sometimes it does not work right when else if is combined with a trigger.


#12

Can you recommend a better way?


#13

just make them 2 separate if statements … that should work fine.