An expression is a piece of code which retrieves the current state or setting of a device. For example, you could create an expression to fetch the current ‘on/off’ state of a light switch or the current temperature of your thermostat. The value returned by an expression may be Boolean (True/False) or an integer (numerical value) depending on the capability of the target device.
The following image shows an expression called ‘My Thermostat Expression’ which captures the current temperature from a physical thermostat device:
You can then use the result of this call in a meshbot trigger to determine whether or not an action runs. For example, the following meshbot turns on a lounge fan if the temperature captured by the ‘My Thermostat Expression’ hits 64 F:
You can use the value of an expression:
As a trigger node (left-side of the trigger). This simply uses the current value of the device referenced in the expression as the criteria for the trigger.
E.g. – if ‘Device Expression Value’ = ‘Value X’ then turn the trigger true.
As a comparison data-point in the right-side of the trigger. This lets you compare the value of the device referenced in your expression with values from a different dewvice in the left side of your trigger.
E.g. – if ‘Water Leak Sensor’ > ‘Water Leak Temperature’ ≠ ‘Device Expression Value’ then turn the trigger true.
Create an expression
In this example, we will create an expression that fetches the ‘On/Off’ status of a light switch. We will then show how to select the expression in a meshbot trigger.
- Click ‘Automation’ > ‘Advanced Scripting’ > ‘Expressions’ > ‘Add New Expression’:
- Type a name for your expression. This is the name that appears in your meshbot trigger if you select ‘Expression’.
- Best practice is to name the expression after the device capability whose state you want to monitor. For example, ‘Dimmer Light Luminance’, ‘Thermostat Temperature’ or ‘Kitchen Door Lock Status’.
- Important – Type ‘return’ at the start of the text field. You must always enter this command as a prefix in order for the expression to save correctly.
- Next, choose the device and device capability whose status you want to monitor then click ‘Add Device Reference’ to create your expression:
- This will automatically populate the text field with the code for your expression. Click ‘Create’ to save your expression:
- After saving’, your expression will be listed in the ‘Expressions’ area as shown below:
- You can now select your expression by name in a meshbot trigger. You can use the values it returns as a simple trigger node or as a point of comparison with the value/status of another device: