Examples: programming with variables

Use the Programming view to program the Control4 system using configuration, properties, variables, delays and agents. 

Variables provide other programming options not available using commands, conditionals or loops. 

There are three types of variables you can use:

  • Room Variables—Provide you with additional programming options not available in the Room object programming. Use Room object programming as a preference to room variables whenever possible. See “Example: Using room variables.”
  • Custom Variables—Let you define additional programming options using:
  • Boolean—Provides a True/False option. For example, the light is on or off. If the light is on, it is True; if the light is off, it is False.
  • Device—Provides a list of device options.
  • Number—Provides a value option. For example, the light level is 70 percent.
  • String—Provides the option to enter a string.  

To program using a custom variable, in the Agent view select Variable and click New to set up a new variable. 

Example: Use one keypad button to toggle between turning on the Theater Dimmer and the Theater Switch

  • Container Variables—Provides the ability to connect two or more devices together by using the device variables. A variable is a representation of information about the controlled devices, for example, a power state or current level of the device. It works much like a Media Scenes agent (see “Using and Programming with Agents ” for details). Container variables are available in the Agent view by selecting Variables. 

Note: Container variables are provided only for backward capability in Release 1.3 and later. Issues with various implementations have been found. The use of Container variables for future implementations is not recommended. Where possible, replace existing implementations with alternate programming. 

The sections below provide examples you can follow when you use variables.