ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
derivative_sensor.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <cstdint>
5
8
9namespace esphome::derivative {
10
12 public:
13 void dump_config() override;
14
15 protected:
16 void process_sensor_value_(float value, float ms_per_unit);
17
19 float last_value_{NAN}; // NAN: no baseline yet
20};
21
23template<uint32_t MS_PER_UNIT> class DerivativeSensor final : public DerivativeSensorBase {
24 public:
25 explicit DerivativeSensor(sensor::Sensor *source) {
26 source->add_on_state_callback([this](float state) { this->process_sensor_value_(state, MS_PER_UNIT); });
27 }
28};
29
30} // namespace esphome::derivative
void process_sensor_value_(float value, float ms_per_unit)
MS_PER_UNIT is the configured time unit in milliseconds, a constant rather than a member.
Base-class for all sensors.
Definition sensor.h:48
void add_on_state_callback(F &&callback)
Add a callback that will be called every time a filtered value arrives.
Definition sensor.h:121
float state
This member variable stores the last state that has passed through all filters.
Definition sensor.h:140
uint32_t value
Definition hal.cpp:59
static void uint32_t