Derivative Sensor
The derivative sensor is a helper sensor that can compute the time derivative (rate of
change) of the values from another sensor. It publishes d(value)/dt — the difference
between the current and the previous reading divided by the elapsed time — expressed in a
configurable time unit. This can for example be useful to derive a speed (in m/s) from a
distance sensor (in m).
This component can be considered the counterpart of the Integration Sensor.
Like the Integration Sensor, the sensor to differentiate is declared with the sensor key.
# Example configuration entrysensor: - platform: derivative sensor: my_distance name: "Speed"
# The sensor to differentiate, here a distance sensor in m - platform: vl53l1x # ... id: my_distance name: "Distance"Configuration Variables
Section titled “Configuration Variables”-
sensor (Required, ID): The ID of the sensor to differentiate.
-
time_unit (Optional, string): The time unit of the resulting rate, one of
ms,s,min,hord. Defaults tos. -
state_class (Optional, string): Defaults to
measurement. Set it to""to publish without a state class. -
All other options from Sensor.
device_class is not inherited, because a rate measures something different from its
source (a distance becomes a speed, an energy becomes a power); set it explicitly when needed.
The following properties are inherited from the source sensor unless set explicitly:
-
unit_of_measurement: The source sensor’s unit per the configured
time_unit. This is the reverse of the Integration Sensor: a known rate unit with thetime_unitappended is reduced to that rate —kWhwithtime_unit: hproduceskW,AhproducesA, andWhproducesW. For any other unit thetime_unitis appended, so a distance sensor inmwithtime_unit: sproduces a speed inm/s. -
accuracy_decimals: The same as the source sensor.
-
icon: The source sensor’s icon.
Behaviour
Section titled “Behaviour”-
The first valid reading after each startup only establishes the baseline; nothing is published for it. The baseline is not persisted, so this happens again after every reboot.
-
A
NaNreading publishes nothing and discards the baseline. The next valid reading only re-establishes the baseline and publishes nothing, so a gap between samples never produces a bogus spike. -
Readings that arrive within the same component call share a timestamp. The later one publishes nothing, and its change is counted against the next reading.