18 if (!condition->check(
x...))
34 if (condition->check(
x...))
48 bool check(Ts...
x)
override {
return !this->condition_->check(
x...); }
60 result += condition->check(
x...);
73 bool check(Ts...
x)
override {
return this->f_(
x...); }
76 std::function<bool(Ts...)>
f_;
83 TEMPLATABLE_VALUE(uint32_t, time);
85 void loop()
override { this->check_internal(); }
88 bool cond = this->condition_->check();
90 this->last_inactive_ =
millis();
95 if (!this->check_internal())
97 return millis() - this->last_inactive_ >= this->time_.value(
x...);
102 uint32_t last_inactive_{0};
107 explicit StartupTrigger(
float setup_priority) : setup_priority_(setup_priority) {}
108 void setup()
override { this->trigger(); }
127 void loop()
override { this->trigger(); }
131 #ifdef ESPHOME_PROJECT_NAME 135 uint32_t hash =
fnv1_hash(ESPHOME_PROJECT_NAME);
137 char previous_version[30];
138 char current_version[30] = ESPHOME_PROJECT_VERSION_30;
139 if (pref.
load(&previous_version)) {
140 int cmp = strcmp(previous_version, current_version);
142 this->trigger(previous_version);
145 pref.
save(¤t_version);
158 void play_complex(Ts...
x)
override {
160 this->num_running_++;
161 this->set_timeout(this->delay_.value(
x...), f);
168 void stop()
override { this->cancel_timeout(
""); }
175 void play(Ts...
x)
override { this->f_(
x...); }
178 std::function<void(Ts...)>
f_;
186 this->then_.add_actions(actions);
191 this->else_.add_actions(actions);
196 this->num_running_++;
197 bool res = this->condition_->check(
x...);
199 if (this->then_.empty()) {
200 this->play_next_(
x...);
201 }
else if (this->num_running_ > 0) {
202 this->then_.play(
x...);
205 if (this->else_.empty()) {
206 this->play_next_(
x...);
207 }
else if (this->num_running_ > 0) {
208 this->else_.play(
x...);
232 this->then_.add_actions(actions);
234 if (this->num_running_ > 0 && this->condition_->check_tuple(this->var_)) {
236 if (this->num_running_ > 0) {
237 this->then_.play_tuple(this->var_);
241 this->play_next_tuple_(this->var_);
247 this->num_running_++;
249 this->var_ = std::make_tuple(
x...);
251 if (!this->condition_->check_tuple(this->var_)) {
254 this->play_next_tuple_(this->var_);
258 if (this->num_running_ > 0) {
259 this->then_.play_tuple(this->var_);
266 void stop()
override { this->then_.stop(); }
271 std::tuple<Ts...> var_{};
279 this->then_.add_actions(actions);
282 if (iteration >= this->count_.value(x...)) {
283 this->play_next_tuple_(this->var_);
285 this->then_.play(iteration, x...);
291 this->num_running_++;
292 this->var_ = std::make_tuple(
x...);
293 if (this->count_.value(
x...) > 0) {
294 this->then_.play(0,
x...);
296 this->play_next_tuple_(this->var_);
303 void stop()
override { this->then_.stop(); }
316 void play_complex(Ts...
x)
override {
317 this->num_running_++;
319 if (this->condition_->check(
x...)) {
320 if (this->num_running_ > 0) {
321 this->play_next_(
x...);
325 this->var_ = std::make_tuple(
x...);
327 if (this->timeout_value_.has_value()) {
329 this->set_timeout(
"timeout", this->timeout_value_.value(
x...), f);
336 if (this->num_running_ == 0)
339 if (!this->condition_->check_tuple(this->var_)) {
343 this->cancel_timeout(
"timeout");
345 this->play_next_tuple_(this->var_);
353 void stop()
override { this->cancel_timeout(
"timeout"); }
357 std::tuple<Ts...> var_{};
365 if (!this->component_->is_ready())
367 this->component_->update();
379 if (!this->component_->is_ready())
381 this->component_->stop_poller();
393 void play(Ts...
x)
override {
394 if (!this->component_->is_ready()) {
399 this->component_->set_update_interval(update_interval.
value());
401 this->component_->start_poller();
value_type const & value() const
SuspendComponentAction(PollingComponent *component)
ForCondition(Condition<> *condition)
const float DATA
For components that import data from directly connected sensors like DHT.
void play(Ts... x) override
float get_setup_priority() const override
TEMPLATABLE_VALUE(uint32_t, count) void add_then(const std
NotCondition(Condition< Ts... > *condition)
Condition< Ts... > * condition_
void play(Ts... x) override
Condition< Ts... > * condition_
void play_complex(Ts... x) override
ActionList< Ts... > else_
Condition< Ts... > * condition_
float get_setup_priority() const override
IfAction(Condition< Ts... > *condition)
ActionList< Ts... > then_
bool check(Ts... x) override
This class simplifies creating components that periodically check a state.
void on_shutdown() override
void add_then(const std::vector< Action< Ts... > *> &actions)
std::function< void(Ts...)> f_
void play(Ts... x) override
float get_setup_priority() const override
void play(Ts... x) override
uint32_t IRAM_ATTR HOT millis()
std::vector< Condition< Ts... > * > conditions_
ResumeComponentAction(PollingComponent *component)
float get_setup_priority() const override
ActionList< uint32_t, Ts... > then_
void play(Ts... x) override
WhileAction(Condition< Ts... > *condition)
Base class for all automation conditions.
std::vector< Condition< Ts... > * > conditions_
ESPPreferences * global_preferences
LambdaAction(std::function< void(Ts...)> &&f)
bool check(Ts... x) override
PollingComponent * component_
void add_else(const std::vector< Action< Ts... > *> &actions)
ActionList< Ts... > then_
const float PROCESSOR
For components that use data from sensors like displays.
PollingComponent * component_
bool check(Ts... x) override
TEMPLATABLE_VALUE(uint32_t, delay) void play_complex(Ts... x) override
AndCondition(const std::vector< Condition< Ts... > *> &conditions)
bool check(Ts... x) override
PollingComponent * component_
ShutdownTrigger(float setup_priority)
LambdaCondition(std::function< bool(Ts...)> &&f)
TEMPLATABLE_VALUE(uint32_t, timeout_value) void play_complex(Ts... x) override
void play_complex(Ts... x) override
void add_then(const std::vector< Action< Ts... > *> &actions)
float get_setup_priority() const override
void play_complex(Ts... x) override
XorCondition(const std::vector< Condition< Ts... > *> &conditions)
void play(Ts... x) override
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
StartupTrigger(float setup_priority)
TEMPLATABLE_VALUE(uint32_t, update_interval) void play(Ts... x) override
void play(Ts... x) override
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
uint32_t fnv1_hash(const std::string &str)
Calculate a FNV-1 hash of str.
void play(Ts... x) override
bool check(Ts... x) override
Implementation of SPI Controller mode.
WaitUntilAction(Condition< Ts... > *condition)
float get_setup_priority() const override
Condition< Ts... > * condition_
UpdateComponentAction(PollingComponent *component)
virtual bool sync()=0
Commit pending writes to flash.
float get_setup_priority() const override
OrCondition(const std::vector< Condition< Ts... > *> &conditions)
bool check(Ts... x) override
std::vector< Condition< Ts... > * > conditions_
void IRAM_ATTR HOT delay(uint32_t ms)
std::function< bool(Ts...)> f_