17 if (!condition->check(
x...))
33 if (condition->check(
x...))
47 bool check(Ts...
x)
override {
return !this->condition_->check(
x...); }
59 result += condition->check(
x...);
72 bool check(Ts...
x)
override {
return this->f_(
x...); }
75 std::function<bool(Ts...)>
f_;
82 TEMPLATABLE_VALUE(uint32_t, time);
84 void loop()
override { this->check_internal(); }
87 bool cond = this->condition_->check();
89 this->last_inactive_ =
millis();
94 if (!this->check_internal())
96 return millis() - this->last_inactive_ >= this->time_.value(
x...);
101 uint32_t last_inactive_{0};
106 explicit StartupTrigger(
float setup_priority) : setup_priority_(setup_priority) {}
107 void setup()
override { this->trigger(); }
126 void loop()
override { this->trigger(); }
130 #ifdef ESPHOME_PROJECT_NAME 134 uint32_t hash =
fnv1_hash(ESPHOME_PROJECT_NAME);
136 char previous_version[30];
137 char current_version[30] = ESPHOME_PROJECT_VERSION_30;
138 if (pref.
load(&previous_version)) {
139 int cmp = strcmp(previous_version, current_version);
141 this->trigger(previous_version);
144 pref.
save(¤t_version);
157 void play_complex(Ts...
x)
override {
159 this->num_running_++;
160 this->set_timeout(this->delay_.value(
x...), f);
167 void stop()
override { this->cancel_timeout(
""); }
174 void play(Ts...
x)
override { this->f_(
x...); }
177 std::function<void(Ts...)>
f_;
185 this->then_.add_actions(actions);
190 this->else_.add_actions(actions);
195 this->num_running_++;
196 bool res = this->condition_->check(
x...);
198 if (this->then_.empty()) {
199 this->play_next_(
x...);
200 }
else if (this->num_running_ > 0) {
201 this->then_.play(
x...);
204 if (this->else_.empty()) {
205 this->play_next_(
x...);
206 }
else if (this->num_running_ > 0) {
207 this->else_.play(
x...);
231 this->then_.add_actions(actions);
233 if (this->num_running_ > 0 && this->condition_->check_tuple(this->var_)) {
235 if (this->num_running_ > 0) {
236 this->then_.play_tuple(this->var_);
240 this->play_next_tuple_(this->var_);
246 this->num_running_++;
248 this->var_ = std::make_tuple(
x...);
250 if (!this->condition_->check_tuple(this->var_)) {
253 this->play_next_tuple_(this->var_);
257 if (this->num_running_ > 0) {
258 this->then_.play_tuple(this->var_);
265 void stop()
override { this->then_.stop(); }
270 std::tuple<Ts...> var_{};
278 this->then_.add_actions(actions);
281 if (iteration >= this->count_.value(x...)) {
282 this->play_next_tuple_(this->var_);
284 this->then_.play(iteration, x...);
290 this->num_running_++;
291 this->var_ = std::make_tuple(
x...);
292 if (this->count_.value(
x...) > 0) {
293 this->then_.play(0,
x...);
295 this->play_next_tuple_(this->var_);
302 void stop()
override { this->then_.stop(); }
315 void play_complex(Ts...
x)
override {
316 this->num_running_++;
318 if (this->condition_->check(
x...)) {
319 if (this->num_running_ > 0) {
320 this->play_next_(
x...);
324 this->var_ = std::make_tuple(
x...);
326 if (this->timeout_value_.has_value()) {
328 this->set_timeout(
"timeout", this->timeout_value_.value(
x...), f);
335 if (this->num_running_ == 0)
338 if (!this->condition_->check_tuple(this->var_)) {
342 this->cancel_timeout(
"timeout");
344 this->play_next_tuple_(this->var_);
352 void stop()
override { this->cancel_timeout(
"timeout"); }
356 std::tuple<Ts...> var_{};
364 if (!this->component_->is_ready())
366 this->component_->update();
378 if (!this->component_->is_ready())
380 this->component_->stop_poller();
392 void play(Ts...
x)
override {
393 if (!this->component_->is_ready()) {
398 this->component_->set_update_interval(update_interval.
value());
400 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_