Interpolation and thresholds
LINEAR linear interpolation and HYSTERESIS threshold filtering functions for mapping and conditioning input values in TapHome scripts.
LINEAR
Returns linearly adjusted value – linear interpolation.
LINEAR(input, value1_input, value1_output, value2_input, value2_output, [type])Parameters - input… input value - value1_input… value at the input at the lower limit - value1_output… value at the output at the lower limit - value2_input… value at the input at the upper limit - value2_output… value at the output at the upper limit - [type]… optional parameter. Defines what the result should be when the input value is out of range value1_input ↔︎ value2_input: - without parameter (same as with parameter BOUNDS)… If the input value is outside the defined range, the output value will be one of the extremes (minimum or maximum) - INFINITE… If the input value is outside the defined range, the result is an extrapolated value - STRICT… If the input value is outside the defined range, the output value will be NaN (not a number)
Examples
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%)Examples for different [type] attributes: - input = 11 - value1_input = 0, value1_output = 400 - value2_input = 10, value2_output = 2000 - result for different [type] parameters: - BOUNDS (default value) = 2000 - INFINITE = 2160 - STRICT = NaN
HYSTERESIS
Hysteresis can be used to filter signals so that the output reacts less rapidly than it otherwise would by taking recent system history into account. For example, a thermostat controlling a heater may switch the heater on when the temperature drops below A, but not turn it off until the temperature rises above B.
Returns 0 or 1.
HYSTERESIS(value, upper_bound, lower_bound, upper_output, lower_output, last_value)Example: maintain a temperature of 20 °C within 2 ºC hysteresis range. Turn the heater on when the temperature drops to below 18 °C and off when the temperature exceeds 22 °C).
heater := HYSTERESIS(temperature, 22, 18, 0, 1, heater);