Sensors API

Sensor handling in Kervi is split in two parts. The first part is sensor device drivers that handles physical access to sensor hardware. The second part is the Sensor class that reads a sensor device and triggers events, store readings to DB.

class kervi.sensors.Sensor(sensor_id, name, device=None, **kwargs)

Sensor is a class that exposes a sensor device as a KerviValue. The Sensor class polls the associated sensor device and updates it self when the value of the sensor device change.

It is possible to link to other KerviValues and dashboards.

Some sensor devices are multi dimensional and each dimension are reached by a numeric index of the sensor it self.

  • sensor_id (str) – Id of the sensor. This id is never displayed it is used to reference the sensor in code.

  • name (str) – Name of the sensor.

  • device (SensorDeviceDriver) – The sensor device that should be monitored. Could be one of the sensors from the kervi device library or a sensor device driver that inherits from kervi.hal.SensorDeviceDriver

Keyword Arguments
  • polling_interval (float) – Polling interval in seconds. Zero disables polling.

add_value_event(event_value, func, event_type=None, parameters=None, **kwargs)

Add a function that is called when the value reach or pass the event_value.

  • event_value (float, string, boolean or a tuple of these types.) –

    A single value or range specified as a tuple.

    If it is a range the function specified in func is called when the value enters the range.

  • func – Function or lambda expression to be called. This function will receive the dynamcic value as a parameter.

  • event_type (str) – String with the value “warning” of “error” or None (default). If warning or error is specified the value or range are shown in UI.


Abstract method that is called when the entire application is loaded.

property delta

Enter how much a the value should change before it triggers changes events and updates links. :type: float

property device

The device that is linked to this sensor class. It may be a hardware device from the kervi device library or a class that inherits from kervi.hal.SensorDeviceDriver

property display_unit

Display unit of value.



Links the sensor to a dashboard.

  • dashboard_id (str) – Id of the dashboard to link to. Enter a * if the sensor should be linked to all dashboards.

  • panel_id (str) – Id of the panel to link to. This is the id of a panel you have added your self to a dashboard or one of the system panels sys-header, header or footer

Keyword Arguments
  • link_to_header (str) – Link this input to header of the panel.

  • label_icon (str) – Icon that should be displayed together with label. All Font Awesome icons are valid just enter the name of the icon without fa-

  • label (str) – Label text, default value is the name of the sensor.

  • flat (bool) – Flat look and feel.

  • inline (bool) – Display value, sparkline and label in its actual size otherwise it occupys the entire with of the panel

  • type (str) – One of the following values radial_gauge, vertical_gauge, horizontal_gauge, chart or value.

  • show_sparkline (bool) – Show a sparkline next to the value.

  • icon (bool) – Icon to show. All Font Awesome icons are valid just enter the name of the icon without fa-.

  • show_value (bool) – Show the numeric value and unit.

  • label (str) – Label to show default is the name of the sensor.

property log_values

Set to true if the values should be logged to DB. If false Kervi will hold a small cache in memory for the last reading to be used in sparklines and real time charts.

property max

Maximum value.



property min

Minimum value.



property polling_interval

The polling interval of the sensor in seconds.



property reading_interval

The polling interval of the sensor in seconds.



property unit

Metric Unit of value.