Expressions

Expressions

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.

Mathematical expressions

+, -, *, /

(20.5 + 9.5) / 2    (15)

Logical expressions

AND, OR, !, =, >, <

(!IsRaining OR (Wind>30))

Functions

IF

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

LINEAR(input, value1_input, value1_output, value2_input, value2_output)
Example 1: LINEAR(250, 0, 0, 50, 500)   (25°C)
Example 2: LINEAR(5, 400, 0, 3000, 10)
          (5V input from CO2 sensor (0V=400ppm, 10V=3000ppm) results in 1700ppm)

Returns linearly adjusted value.

Bit operations

<<   (Left Bit Shift)

8 << 2   (32)

>> (Right Bit Shift)

32 >> 2   (8)

& (Bitwise and)

3 & 1   (1)

| (Bitwise or)

2 | 1 (3)

Hexadecimal numbers

Expressions can also interpret hexadecimal numbers. Prefix 0x is required and the rest is not case sensitive.

0x0A   (10)
0xA0A0   (41120)
0xa0a0   (41120)

Modbus expressions

Register types

  • C – Coil
  • D – Discrete input
  • H – Holding register
  • A – Analog input

Data types

  • 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
  • BigEndianInt16
  • LittleEndianInt16
  • BigEndianUint16
  • LittleEndianUint16
  • BigEndianInt32
  • LittleEndianInt32
  • BigEndianUint32
  • LittleEndianUint32

MODBUSR (modbus read)

MODBUSR(register_type, register_address, data_type)

MODBUSW (modbus write)

MODBUSW(register_type, register_address, data_type, value_to_write)

MODBUSWNE (modbus write not equal)

Writes to the register only if the current value is different. Reads the value, checks if equal and writes if not.

MODBUSWNE(register_type, register_address, data_type, value_to_write)