Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions source/_integrations/derivative.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ logo: derivative.png
ha_qa_scale: internal
---

The `derivative` platform provides the numerical derivative or numerical differentiation of the values provided by a source sensor. Derivative sensors are updated upon changes of the **source**. Fast sampling source sensors provide better results.
The `derivative` platform creates a sensor that estimates the derivative of the values provided by a source sensor.
Derivative sensors are updated upon changes of the **source**.

## Configuration

Expand Down Expand Up @@ -39,7 +40,7 @@ round:
default: 3
type: integer
unit_prefix:
description: Metric unit to prefix the derivative result. Available units are k, M, G, T.
description: Metric unit to prefix the derivative result ([Wikipedia](https://en.wikipedia.org/wiki/Unit_prefix)]). Available symbols are "n" (1e-9), "µ" (1e-6), "m" (1e-3), "k" (1e3), "M" (1e6), "G" (1e9), "T" (1e12).
required: false
default: None
type: string
Expand All @@ -52,6 +53,27 @@ unit:
description: Unit of Measurement to be used for the derivative.
required: false
type: string
time_window:
description: The time window in which to calculate the derivative. This is useful for sensor that output discrete values. By default the derivative is calculated between two consecutive updates.
default: 0
required: false
type: time
{% endconfiguration %}

If 'unit' is set then 'unit_prefix' and 'unit_time' are ignored.
## Temperature example

For example, you have a temperature sensor `sensor.temperature` that outputs a value every few seconds, but rounds to the nearest half number.
That means that two consecutive output values might be the same (so the derivative is `Δy/Δx=0` because `Δy=0` !)
However, the temperature might actually be changing over time.
In order to capture this, you should use a `time_window`, such that immediate jumps don't result in high derivatives and that after the next sensor update, the derivatives doesn't vanish to zero.
An example config that uses `time_window` is

```yaml
sensor:
- platform: derivative
source: sensor.temperature
name: Temperature change per hour
round: 1
unit_time: h
time_window: "00:30:00" # we look at the change over the last half hour
```