Argument | Description |
boolean | A boolean expression that evaluates to TRUE or FALSE |
truevalue | A value containing the value you want returned if the boolean expression is TRUE |
falsevalue | A value containing the value you want returned if the boolean expression is FALSE |
NOTE: the treuvalue/falsevalue parameters should reflect the data type expected by the function using the Return from the IF.
If a string is expected then the IF values will use quotes (eg, if({OPEN}=1,"Open","Closed"), but numbers, integers, datetime values, etc should be used as appropriate for the target function's use.
If a true or false value is not required, put a zero or a null string in that position, eg. if({DARK}=1,ph_insteon("SOFA",ion,200),"") or if({DARK}=1,ph_insteon("SOFA",ion,200),0)
Program Flow
Used in a JUMP Command line of a macro, the IF function allows branching to different program lines depending on the IF test results. The following tests the time of day in Seq line 10 and if after 7:30AM jumps to the next line to turn the studio lights. Otherwise it jumps down three lines and reschedules an event to call itself again in 15 minutes to test again. Alternatively, the 2nd image shows how a GOTO (rather than a JUMP) could be used for better program code clarity (plus avoiding errors later if the macro is changed and the jumps become inaccurate.)
Program Note: The Goto Command jumps to the named target Label, but if there is no matching Label then the jump is to the Next Line. Thus the faux Label "nextLINE" does go the next code line and provides an easy and clear indication of the program flow.
Message Construction
Used in conjunction with Message Commands/Functions, the IF produces messages that match appropriate conditions...
Value Modification
The IF function is often used to set or modify data. For instance, if the spotlight illuminating the ceiling is On, then set the SKYLIGHT global to a "1", otherwise "0"
See also Examples below.