Sensors

A sensor is used to store data received from the xpl network inside the database, this data can then be used to generate charts and display the evolution of some data.

The data stored in the database is linked to a certain Domogik datatype <package_development/plugins/data_types/index>. This datatype is used to interpret the data and to display the correct unit.

A sensor can have different types:
  • absolute: store the value as its received
  • incremental: store the difference between the last received and the last-1 received value
  • calculated: a calculated value, see the specific section below
Some examples of sensors:
  • Temperature sensor
  • Energy sensor (KwH)
  • Power sensor (Watt)
  • boolean input sensor
  • ...

Calculated sensors

A calculated sensor is a sensor where the stored value is calculated. as an example lets use a power sensor that transmits the number of KWh used, and we want to calculate the cost for the electricity of that interval.

If we then create a calculated sensor with the below formula we can store the price for the power consumption during that time.

def calculate(value):
    result = value * 0,11
    return result
The above function wil return the value to store, note this function can contain any python code you want, but there are some rules to follow:
  • the function name is always ‘calculate’
  • it has one input parameter named ‘value’
  • it has one return parameter, a float