Example: Using custom Boolean variables in an agent
Use the Programming view to create custom variables in an agent using a Boolean value.
In this example, when someone is at the door:
- Program to activate the Media Scene 'Someone is at the door,' and turn on the porch light.
- Program to play a song in the Bedroom and the Theater.
- When the Motion Sensor stops sensing motion at the door, program to turn the music and porch light off.
Prerequisites
The following devices are added and identified in the project:
- Controller
- Porch Light Switch
- Bedroom music
- Theater music
- Motion Sensor
To program using a custom Boolean variable in an agent:
- Start Composer Pro and connect to a Director.
- Click System Design.
- Click Connections. Make sure the connections are correct.
Note: Ensure that the Front Light is connected to the correct Contact Sensor on the controller.
- Click the Network tab, and ensure that the controller and Porch Light have a network address.
Create a new variable
- Click Agents.
- Select Variable. The Variables view appears.
- Click New.
- On the dialog that appears, do the following:
- Click New Variable.
- In the drop-down menu, select Boolean.
- Name the Variable Power State and click OK. The default value is false.
Create a media scene ‘Someone is at the door’
- Select Media Scenes, and click New.
- Name the Media Scene Someone is at the door. Click OK.
Add the bedroom and theater room
- Click Add Room, and add the Theater and the Bedroom (see above).
- Set the volume in the Bedroom to 50, and the volume in the Theater to 75.
- Click Programming.
- In the project tree and the Device Events pane, click to expand Variables, and select Power State.
- In the project tree and in the Device Actions pane, click to expand Variables, and select Power State.
Add the conditionals and commands
- Follow the previous programming steps to create a script with Conditionals.
- Click the Conditionals tab.
- In the Conditionals tab, click Is False, and drag the blue question mark to the Script pane.
- Click the Commands tab.
- In the Commands tab, click Set to True, and drag the green arrow on top of the blue question mark in the Script pane to make it the first subset item of the first conditional.
- In the Device Actions pane, select Light Switch.
- Click the Commands tab.
- In the Commands tab, click On, and drag the green arrow on top of the blue question mark in the Script pane to make it the second subset item of the first conditional.
- In the project tree and in the Device Actions pane, select Media Scenes.
- Click the Commands tab.
- Click Activate in the Commands tab, and drag the green arrow on top of the blue question mark in the Script pane to make it third subset item of the first conditional.
- In the project tree and in the Device Actions pane under Variables, select Power State.
- Click the Conditionals tab.
- In the Conditionals tab, click Is True, and drag the blue question mark to the Script pane.
- Click the Commands tab.
- In the Commands tab, click Set to False, and drag the green arrow on top of the blue question mark in the Script pane to make it the first subset item of the second conditional.
- In the project tree and in the Device Actions pane, select Light Switch.
- Click the Commands tab.
- In the Commands tab, click Off, and drag the green arrow on top of the blue question mark in the Script pane to make it the second subset item of the second conditional.
- In the project tree and in the Device Actions pane, select Media Scenes.
- In the Commands tab, click Deactivate, and drag the green arrow on top of the blue question mark in the Script pane to make it the third subset item of the second conditional.
- In the project tree and in the Device Events pane, select Media Scenes and select the event Someone is at the Door.
- In the project tree and in the Device Actions pane, select the Bedroom object. (Repeat the next four steps for the Theater.)
- Click the Commands tab.
- In the Commands tab, click Select Media.
- In the dialogue that appears, select the album and song that you want to play when Someone is at the Door executes. In this example, Rhapsody’s ‘50s Hits’ is used. Click OK.
- Drag the green arrow to the Script pane.
- Repeat steps 37-41 for the Theater.
- In the project tree and in the Device Events pane, select Motion Sensor under Front, and select the event When the Motion Sensor senses motion.
Add the Boolean Values
- In the project tree and in the Device Actions pane, click to expand Variables, and select Power State.
- In the Conditionals tab, click Is False, and drag the blue question mark to the Script pane (this is the third conditional).
- In the Commands tab, click Set to True, and drag the green arrow on top of the blue question mark to make it the first subset of the third conditional.
- In the project tree and in the Device Events pane, select the event When the Motion Sensor stops sensing motion.
- In the project tree and in the Device Actions pane, click to expand Variables, and select Power State.
- In the Conditionals tab, click Is True, and drag the blue question mark to the Script pane.
- In the Commands tab, click Set to False, and drag the green arrow on top of the blue question mark to make it the second subset of the third conditional.
- Click Execute.
Results: The porch light turns on and plays a song in the bedroom and theater whenever the motion sensor senses motion at the front door.