Expressions are used in smart rules “Equation” and “Formula”.
Extra functions can be used on Modbus devices to read/write values from/to Modbus registers.
+, -, *, /
(20.5 + 9.5) / 2
AND, OR, !, =, >, <
(!IsRaining OR (Wind>30))
IF(logical_expression, value_if_true, value_if_false)
Returns one value if a logical expression is ‘TRUE’ and another if it is ‘FALSE’.
LINEAR(input, value1_input, value1_output, value2_input, value2_output)
LINEAR(250, 0, 0, 50, 500)
LINEAR(5, 0, 400, 10, 3000)
(5V input from CO2 sensor (0V=400ppm, 10V=3000ppm) results in 1700ppm)
Returns linearly adjusted value.
SWITCH(expression, case1, value1, [case2, ...], [value2, ...], default_value)
Tests an expression against a list of cases and returns the corresponding value of the first matching case, with a default value if nothing else is met.
Returns the smaller of the two values.
Returns the larger of the two values.
<< (Left Bit Shift)
8 << 2
>> (Right Bit Shift)
32 >> 2
& (Bitwise and)
3 & 1
| (Bitwise or)
2 | 1 (3)
Expressions can also interpret hexadecimal numbers. Prefix 0x is required and the rest is not case sensitive.
- C – Coil
- SC – Single Coil
- D – Discrete input
- H – Holding register
- SH – Single holding register
- A – Analog input
The ‘S’ register types are only for write functions and should be used for devices which do not support writing to multiple registers at once.
- Int16 (-32,768 to 32,767)
- Uint16 (0 to 65,535)
- Int32 (-2,147,483,648 to 2,147,483,647)
- Uint32 (0 to 4,294,967,295)
- Bool – (-inf, 0> = false, (0, inf) = true
MODBUSR (modbus read)
MODBUSR(register_type, register_address, data_type) Example: MODBUSR(H, 20, Int16)/100
Returns value of holding register on address 20 in int16 format and divides it by 100.
MODBUSW (modbus write)
MODBUSW(register_type, register_address, data_type, value_to_write) Example: MODBUSW(H, 20, Int16, Te/100)
Writes the temperature of the sensor divided by 100 int int16 format to holding register 20.
MODBUSWNE (modbus write not equal)
Writes to the register only if the current value is different. Reads the value, checks if equal and writes to the register if not. Useful for saving EEPROM memory.
MODBUSWNE(register_type, register_address, data_type, value_to_write) Example: MODBUSWNE(H, 20, Int16, Te/100)
First reads the value from holding register on address 20 in int16 format, compares it to the temperature sensor temperature divided by 100 and only if the values are different writes the temperature of the sensor divided by 100 int int16 format to holding register 20.