Platform Home Assistant "Trend"

2 minutes of reading
Proconductor: Home Assistant Community
Availability: included in thepersonale HUB Home Assistant
Category: software
Type: platform Home Assistant
Family: component "Binary Sensor” Home Assistant
Implementation difficulties: low

The "Trend" platform, daughter of the component "Binary Sensor"Of Home Assistant, it is useful to implement of binary trend sensors which provide information with respect to the performance of other sensors.

These binary sensors change state from "off"Or"on"When the monitored sensor varies (it grows or decreases: this is what the configuration decides).


The configuration of the "Trend" platform at the file configuration.yaml it's pretty simple.
It is sufficient to insert an entry of this type:

  - platform: trend
        entity_id: sensor.nome_sensore_da_monitorare

The variables available for configuration customization are the following:

entity_id(string, mandatory) The name of theentity.
attribute(string, optional) The attribute of the entity (monitored) to be monitored. If not specified, the "status" will be checked.
(string, optional) The type of entity to show on the frontend.
friendly_name(string, optional) The name of the entity to show at the frontend.
invert(Boolean, optional) Inverts the result. Set to "true"Causes the state of the" Binary Sensor"Created becomes" on "when the monitored sensor decreases the profirst value. Default: false
max_samples(full, optional) Maximum number of records to be collected in the history.
min_gradient(string, optional) The rate of ascent or descent. Explained to follow.
sample_duration(integer, optional) The duration in seconds of the surveys considered valid for the evaluation. Surveys older than this duration are discarded. Default: 0 (unlimited)

Use multiple surveys

While by default the trend sensor thus created simply changes its status when the status of the monitored sensor changes (based on the fact that it increases / decreases and the configuration), via max_samples, sample_duration e min_gradient it is possible to evaluate a "multi-detection" trend.

Each time the status of the monitoto sensor changes, its value is recorded along with its timenameolder than sample_duration they are discarded.

Each trend sensor has a "trend line"; in the case of a "multi-detection" configuration it is adapted to the available samples and the gradient of this line is compared with min_gradient to determine the status of the trend sensor.

In short, the min_gradient it is a customization that allows a very fine adjustment of the trend sensor. The "gradient" is measured in "sensor unit per seconds": for example, if you want the trend sensor to become "on" when the temperature detected by a sensor collapses, say, two degrees per hour, calculate the min_gradient is simple:

(-2) / (sample_duration)


(-2) / (60 × 60) = -0.00055


Let's see how to configure a trend sensor that activates at sunrise:

  - platform: trend
        entity_id: sun.sun
        attribute: elevation

The following sensors, instead, indicate when the temperature collapses or rises at least three degrees in an hour, collecting data for a period of two hours:

  - platform: trend
        entity_id: sensor.temperatura_esterna
        sample_duration: 7200
        min_gradient: -0.0008
        device_class: cold
        entity_id: sensor.temperatura_esterna
        sample_duration: 7200
        min_gradient: 0.0008
        device_class: heat

inDomus telegram channel