Home Elements Boards Recipes

CALC Abstract Element

The CalcElement is implementing the common functionality for the Elements that create one output value from multiple input values. This Element is not intended to be used directly. Use the AND, OR and ADD Elements.

Web UI for the Elements

The standard card for these elements is used showing the current calculated output value.

Up to 8 input values can be used for calculation.

When no input value is given the output value is 0 by default.

Element Configuration

The Calc Element is used as a base class where the following properties are available for configuration:

type – (internal) This property controls how the input values are scanned and can be modified by the derived elements. The logical elements set this to datatype-boolean to enable scanning of true and false values. The datatype-numeric and is used by the AddElement for scanning numbers.

value[n] – The input values of the element are given using the value array notation. n must be in the range of 0 to 7.

invert – The boolean calculations result is inverted when this property is set to true.

onValue – These actions are emitted when the output value has changed.

From the base element implementation the following properties are available for configuration:

title – Caption text for the element. Used by the element specific cards on the dash boards.

description – A line of text that gives a short description of the device used in the web UI.

room – The location of the device.

loglevel – This property holds the element specific log level. The default value is LOGGER_LEVEL_ERR == 1.

startup – This property can be used to start the element using a different initialization phase. Possible values are “sys”, “net”, “time”. See The Startup sequence.

State

The following properties are available with the current values at runtime

active – Is set to true when the element is active.

value – The current output value is reported in the state.

Example State

{
  "add/duration": {
    "active":"true",
    "value":"13"
  }
}

Implementation details

This base Element implementation implements the common functionality and eases implementation of the calculation elements.

The derived elements must set the datatype property as required and need to implement the calc() method.

This method is called when any input value has be set to calc the new output value.

The common state implementation returns the current output value.

Internally all possible input values are stored in _inStringValues Strings after some input validation:

The number of max. 8 values can be changed by the CALCELEMENT_MAX_INPUTS definition.

See Also

Tags

Element