sensor.battery

class platypush.backend.sensor.battery.SensorBatteryBackend(**kwargs)[source]

Bases: SensorBackend

This backend listens for battery full/connect/disconnect/below/above threshold events. The sensor events triggered by this backend will include any of the following fields:

  • battery_percent

  • battery_power_plugged

Requires:

  • psutil (pip install psutil) for CPU load and stats.

Triggers:

__init__(**kwargs)[source]
Parameters:
  • plugin (str) – If set, then this plugin instance, referenced by plugin id, will be polled through get_plugin(). Example: 'gpio.sensor.bme280' or 'gpio.sensor.envirophat'.

  • plugin_args (dict) – If plugin is set and its get_measurement() method accepts optional arguments, then you can pass those arguments through plugin_args.

  • thresholds – Thresholds can be either a scalar value or a dictionary (e.g. {"temperature": 20.0}). Sensor threshold events will be fired when measurements get above or below these values. Set it as a scalar if your get_measurement() code returns a scalar, as a dictionary if it returns a dictionary of values. For instance, if your sensor code returns both humidity and temperature in a format like {'humidity':60.0, 'temperature': 25.0}, you’ll want to set up a threshold on temperature with a syntax like {'temperature':20.0} to trigger events when the temperature goes above/below 20 degrees.

  • tolerance (dict or float) –

    If set, then the sensor change events will be triggered only if the difference between the new value and the previous value is higher than the specified tolerance. Example:

    {
        "temperature": 0.01,  # Tolerance on the 2nd decimal digit
        "humidity": 0.1       # Tolerance on the 1st decimal digit
    }
    

  • poll_seconds (float) – If set, the thread will wait for the specified number of seconds between a read and the next one.

  • enabled_sensors (dict (in the form name -> [True/False]), set or list) – If get_measurement() returns data in dict form, then enabled_sensors selects which keys should be taken into account when monitoring for new events (e.g. “temperature” or “humidity”).

get_measurement()[source]

Wrapper around plugin.get_measurement() that can filter events on specified enabled sensors data or on specified tolerance values. It can be overridden by derived classes.