# 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.

Examples:  ## Mathematical expressions

### +, -, *, /

``(20.5 + 9.5) / 2    ``(15)``

## Logical expressions

### AND, OR, !, =, !=, >, <

``(!IsRaining OR (Wind>30))MultiValueSwitchState != 2 (Not equal to 2)``

## 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

Returns linearly adjusted value – linear interpolation.

LINEAR(input, value1_input, value1_output, value2_input, value2_output)

``Example 1:`` LINEAR(250,  0,0,  50,500)   ``(Result is 25°C)``Example 2: LINEAR(Co2,  400,0,  1200,1)          (If value from Co2 sensor is 400ppm, output for air recovery will be 0%. If Co2 is 1200, output will be 100%. And if e.g. Co2=800, output will be 50%)``

### SWITCH

``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.

Example  Configuration ReadState ... SWITCH(MODBUSR(H, 168, UInt16),   0, 0,   0x02, 1,   0x04, 2,   0x08, 3,   0x10, 4,   0x40, 5, 0x800, 6,   0)
WriteState ... MODBUSWNE(H, 168, UInt16, SWITCH(Mu,   0, 0,   1, 0x02,   2, 0x04,   3, 0x08,   4, 0x10,  5, 0x40,   6, 0x800,  0)

Result ### MIN

``MIN(value1, value2)``

Returns the smaller of the two values.

### MAX

``MAX(value1, value)``

Returns the larger of the two values.

### ROUND

``ROUND(value1)    ``

Returns the rounded value.

`Example 1:`` ROUND(2.01) ``(Result is 2)`

`Example 2:`` ROUND(2.49) ``(Result is 2)`

`Example 3:`` ROUND(2.5) ``(Result is 3)`

`Example 4:`` ROUND(2.99) ``(Result is 3)`

Supported since Core version 2018.1.9562

### DEW POINT

``DEWPOINT(temperature, relativeHumidity)Returns the dew point temperature given the current temperature and relative humidity. Dew point is calculated according to this equation:http://bmcnoldy.rsmas.miami.edu/Humidity.html.``

`Example 1:`` DEWPOINT(20, 50) ``(Result is ~9.26)`

`Example 2:`` DEWPOINT(0, 100) ``(Result is 0)`

Supported since Core version 2018.1.9623

## Bit operations

### <<   (LEFT BIT SHIFT)

``8 << 2   ``(32)``

### >> (RIGHT BIT SHIFT)

``32 >> 2   ``(8)``

### & (BITWISE AND)

``3 & 1   ``(1)``

### | (BITWISE OR)

`2 | 1 (3)`

``0xA0A0   (41120)``
``0xa0a0   (41120)``