Programming with conditionals
A conditional is an 'If' statement in Composer Pro that asks a true or false question to the device.
- A 'Break' command used in an 'If' statement should jump to the first statement after the 'If'. See “Programming with Delay, Stop and Break Commands” for details. Note: A 'Break' command in an 'If' statement won't behave as a 'Stop' command, but will move to the next level in the script.
- A break not in a 'While' or 'If' statement should behave like a 'Stop' command (jumps to the first statement after the function).
Example: The example in this section shows how to use conditionals in programming. If a light is off when the doorbell is pressed, the light is programmed to turn on. Conditionals also use When statements (events). When the doorbell is pressed, if the light is off, program the light to turn on.
To program a conditional that turns on the light when the doorbell is pressed and the light is off:
- Make sure that the doorbell and light switch are configured in the project.
- Click Programming.
- In the Device Events pane project tree, select the Doorbell.
- Select the When the Doorbell is pressed event. The event appears at the top of the Script pane.
- In the Device Actions pane, select the Front Door Light. Notice that the light switch actions that can be programmed for this device appear in the Light Switch Actions pane below the Device Actions project tree.
- Click the Conditionals tab, and select Is Off. Composer Pro displays the conditional you chose in the Front Door Light Actions pane: ? If <room>->Front Door Light is off.
- Drag the blue question mark icon to the Script pane.
- Click the Commands tab, and select On.
- Drag the green arrow to the blue question mark in the Script pane to make it a child under the "If" statement (nest the command under the "If" statement).
Tip: If you drag the action to the text, or you drag the action under the text to the open space, it places the action as an equal above the conditional. If you drag the action to the question mark, it becomes a subset of the conditional. Notice the direction of the arrow to place the action as a peer or a subset under the statement.
- Click Execute. With the Front Door Light off, press the doorbell; the light should come on.