17 void setup()
override;
29 source->add_on_state_callback([
this](
bool state) {
38 this->
set_value(
static_cast<int64_t
>(
static_cast<uint64_t
>(this->
value_) +
static_cast<uint64_t
>(amount)));
A counter held as a 64-bit integer. The published sensor state is a float, so it is exact only up to ...
void set_value(int64_t value)
void increment(int64_t amount=1)
overflow on addition of signed numbers is undefined - use the well defined unsigned version
float get_setup_priority() const override
CounterSensor(bool restore, int64_t initial_value)
The counter starts at initial_value unless a stored value is restored.
ESPPreferenceObject pref_
void count_true_from(T *source)
Increment by one each time the given binary sensor changes to true.
void dump_config() override
void count_updates_from(sensor::Sensor *source)
Increment by one each time the given sensor publishes a state.
Base-class for all sensors.
void add_on_state_callback(F &&callback)
Add a callback that will be called every time a filtered value arrives.
float state
This member variable stores the last state that has passed through all filters.
constexpr float DATA
For components that import data from directly connected sensors like DHT.