29 void play(Ts...
x)
override { this->sensor_->publish_state(this->state_.value(
x...)); }
39 template<
typename V>
void set_min(V min) { this->min_ = min; }
40 template<
typename V>
void set_max(V max) { this->max_ = max; }
45 if (this->rtc_.load(&initial_state)) {
46 this->previous_in_range_ = initial_state;
49 this->parent_->add_on_state_callback([
this](
float state) { this->on_state_(state); });
55 if (std::isnan(state))
58 float local_min = this->min_.value(state);
59 float local_max = this->max_.value(state);
62 if (std::isnan(local_min) && std::isnan(local_max)) {
63 in_range = this->previous_in_range_;
64 }
else if (std::isnan(local_min)) {
65 in_range = state <= local_max;
66 }
else if (std::isnan(local_max)) {
67 in_range = state >= local_min;
69 in_range = local_min <= state && state <= local_max;
72 if (in_range != this->previous_in_range_ && in_range) {
76 this->previous_in_range_ = in_range;
77 this->rtc_.save(&in_range);
82 bool previous_in_range_{
false};
91 void set_min(
float min) { this->min_ = min; }
92 void set_max(
float max) { this->max_ = max; }
94 const float state = this->parent_->state;
95 if (std::isnan(this->min_)) {
96 return state <= this->max_;
97 }
else if (std::isnan(this->max_)) {
98 return state >= this->min_;
100 return this->min_ <= state && state <= this->max_;
TEMPLATABLE_VALUE(float, state) void play(Ts... x) override
void add_on_state_callback(std::function< void(float)> &&callback)
Add a callback that will be called every time a filtered value arrives.
void on_state_(float state)
void add_on_raw_state_callback(std::function< void(float)> &&callback)
Add a callback that will be called every time the sensor sends a raw value.
ValueRangeTrigger(Sensor *parent)
SensorInRangeCondition(Sensor *parent)
bool check(Ts... x) override
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
float get_setup_priority() const override
SensorRawStateTrigger(Sensor *parent)
Base class for all automation conditions.
ESPPreferences * global_preferences
SensorPublishAction(Sensor *sensor)
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
SensorStateTrigger(Sensor *parent)
Implementation of SPI Controller mode.
Base-class for all sensors.
esphome::sensor::Sensor * sensor