if PowerHome formula function
Description
Evaluates a condition and returns a value based on that condition.
Syntax
if ( boolean, truevalue, falsevalue )
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
Return value
The data type of truevalue or falsevalue. Returns truevalue if boolean is TRUE and falsevalue if it is FALSE. Returns NULL if an error occurs.
Usage
The IF function is one of the basic building blocks of PowerHome macros, allowing modification in program flow, parameter testing to determine if they fail, meet, or exceed expectations, and appropriate message display.

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.
IF Jump

IF Goto

Message Construction
Used in conjunction with Message Commands/Functions, the IF produces messages that match appropriate conditions...
If Messages

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" IF Global
See also Examples below.

Examples
The following examples demonstrate typical syntax/usage for this function.
• if([LOCAL4]>100,100,[LOCAL4]) --> Trim LOCAL4 value to max of 100.
• if({CURWINDCHILL}>50,"1","5") --> Used in a macro JUMP command would cause a skip down 1 line if CURWINDCHILL was >50.
• if(Now()<08:00:00,"1","4") --> Used in a macro JUMP command would cause a skip down 1 line if the time was earlier than 8AM.
•  if({SMS}=1 and {OVRTMP}=1,"ph_sendsmtpemail("smtp.mail.yahoo.com",465,"toname@yahoo.com,loginname,pwtext", "2225551212@txt.att.net","Temp Alert","Freezer Temp out of range at {TEMP-FREEZER_V} degrees.") --> If SMS and OvrTemp flags are set then send text message to phone to give alert.