Skip to content

Commit 472ea0b

Browse files
hotplotfabaff
authored andcommitted
Update binary_sensor.trend for linear trend detection (home-assistant#3584)
* Update binary_sensor.trend.markdown * Update binary_sensor.trend.markdown * Added max_samples documentation
1 parent cb90c05 commit 472ea0b

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

source/_components/binary_sensor.trend.markdown

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ha_release: 0.28
1313
ha_iot_class: "Local Push"
1414
---
1515

16-
The `trend` platform allows you to create sensors which show the trend of numeric `state` or`state_attributes` from other entities. This sensor requires two updates of the underlying sensor to establish a trend. Thus it can take some time to show an accurate state. It can be useful as part of automations, where you want to base an action on a trend.
16+
The `trend` platform allows you to create sensors which show the trend of numeric `state` or`state_attributes` from other entities. This sensor requires at least two updates of the underlying sensor to establish a trend. Thus it can take some time to show an accurate state. It can be useful as part of automations, where you want to base an action on a trend.
1717

1818
To enable Trend binary sensors in your installation, add the following to your `configuration.yaml` file:
1919

@@ -29,39 +29,54 @@ binary_sensor:
2929
Configuration variables:
3030
3131
- **sensors** array (*Required*): List of your sensors.
32-
- **friendly_name** (*Optional*): Name to use in the Frontend.
33-
- **device_class** (*Optional*): The [type/class](/components/binary_sensor/) of the sensor to set the icon in the frontend.
3432
- **entity_id** (*Required*): The entity that this sensor tracks.
3533
- **attribute** (*Optional*): The attribute of the entity that this sensor tracks. If no attribute is specified then the sensor will track the state.
36-
- **invert** (*Optional*): Invert the result (so `true` means descending rather than ascending)
34+
- **device_class** (*Optional*): The [type/class](/components/binary_sensor/) of the sensor to set the icon in the frontend.
35+
- **friendly_name** (*Optional*): Name to use in the Frontend.
36+
- **invert** (*Optional*): Invert the result (so `true` means descending rather than ascending). Defaults to `False`
37+
- **max_samples** (*Optional*): Limit the maximum number of stored samples. Defaults to `2`.
38+
- **min_gradient** (*Optional*): The minimum rate at which the observed value must be changing for this sensor to switch on. Defaults to `0.0`
39+
- **sample_duration** (*Optional*): The duration **in seconds** to store samples for. Samples older than this value will be discarded. Defaults to `0`
40+
41+
## {% linkable_title Using Multiple Samples %}
42+
43+
If the optional `sample_duration` and `max_samples` parameters are specified then multiple samples can be stored and used to detect long-term trends.
44+
45+
Each time the state changes, a new sample is stored along with the sample time. Samples older than `sample_duration` seconds will be discarded.
46+
47+
A trend line is then fitted to the available samples, and the gradient of this line is compared to `min_gradient` to determine the state of the trend sensor. The gradient is measured in sensor units per second - so if you want to know when the temperature is falling by 2 degrees per hour, use a gradient of (-2) / (60 x 60) = -0.00055
48+
49+
The current number of stored samples is displayed on the States page.
3750

3851
## {% linkable_title Examples %}
3952

4053
In this section you find some real life examples of how to use this sensor.
4154

42-
### {% linkable_title Temperature trend %}
43-
44-
This example indicates `true` if the temperature is rising:
55+
This example indicates `true` if the sun is still rising:
4556

4657
```yaml
4758
binary_sensor:
4859
- platform: trend
4960
sensors:
50-
temperature_up:
51-
friendly_name: 'Temp increasing'
52-
entity_id: sensor.skylight_temperature
53-
device_class: heat
61+
sun_rising:
62+
entity_id: sun.sun
5463
```
5564

56-
And this one indicates `true` if the temperature is falling:
65+
This example creates two sensors to indicate whether the temperature is rising or falling at a rate of at least 3 degrees an hour, and collects samples over a two hour period:
5766

5867
```yaml
5968
binary_sensor:
6069
- platform: trend
6170
sensors:
62-
temperature_down:
63-
friendly_name: 'Temp decreasing'
64-
entity_id: sensor.skylight_temperature
71+
temp_falling:
72+
entity_id: sensor.outside_temperature
73+
sample_duration: 7200
74+
min_gradient: -0.0008
6575
device_class: cold
66-
invert: Yes
76+
77+
temp_rising:
78+
entity_id: sensor.outside_temperature
79+
sample_duration: 7200
80+
min_gradient: 0.0008
81+
device_class: heat
6782
```

0 commit comments

Comments
 (0)