23 bool check(
const Ts &...
x)
override {
25 if (!condition->check(
x...))
41 bool check(
const Ts &...
x)
override {
43 if (condition->check(
x...))
68 bool check(
const Ts &...
x)
override {
71 result += condition->check(
x...);
84 bool check(
const Ts &...
x)
override {
return this->
f_(x...); }
87 std::function<bool(Ts...)>
f_;
96 bool check(
const Ts &...
x)
override {
return this->
f_(x...); }
160#ifdef ESPHOME_PROJECT_NAME
166 char previous_version[30];
167 char current_version[30] = ESPHOME_PROJECT_VERSION_30;
168 if (pref.
load(&previous_version)) {
169 int cmp = strcmp(previous_version, current_version);
171 this->
trigger(previous_version);
174 pref.
save(¤t_version);
199 if constexpr (
sizeof...(Ts) == 0) {
200 App.scheduler.set_timer_common_(
201 this, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::NUMERIC_ID_INTERNAL,
nullptr,
203 [
this]() { this->play_next_(); },
204 false, this->num_running_ > 1);
210 auto f = [
this,
x...]()
mutable { this->
play_next_(x...); };
211 App.scheduler.set_timer_common_(
this, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::NUMERIC_ID_INTERNAL,
213 this->delay_.value(
x...), std::move(
f),
214 false, this->num_running_ > 1);
219 void play(
const Ts &...
x)
override {
229 void play(
const Ts &...
x)
override { this->
f_(x...); }
232 std::function<void(Ts...)>
f_;
242 void play(
const Ts &...
x)
override { this->
f_(x...); }
270 void play(
const Ts &...
x)
override;
286 this->
else_.add_actions(actions);
293 if (!this->
then_.
empty() && this->num_running_ > 0) {
297 }
else if constexpr (HasElse) {
298 if (!this->
else_.empty() && this->num_running_ > 0) {
299 this->
else_.play(x...);
306 void play(
const Ts &...
x)
override {
311 if constexpr (HasElse) {
349 void play(
const Ts &...
x)
override {
361 if (this->parent_->num_running_ > 0 && this->parent_->condition_->check(
x...)) {
363 this->parent_->then_.play(
x...);
366 this->parent_->play_next_(
x...);
379 void play(
const uint32_t &iteration,
const Ts &...
x)
override;
398 if (this->count_.value(
x...) > 0) {
405 void play(
const Ts &...
x)
override {
416 uint32_t next_iteration = iteration + 1;
417 if (next_iteration >= this->parent_->count_.value(
x...)) {
418 this->parent_->play_next_(
x...);
420 this->parent_->then_.play(next_iteration,
x...);
437 void setup()
override {
459 auto timeout = this->timeout_value_.optional_value(
x...);
460 this->
var_queue_.emplace_back(now, timeout, std::make_tuple(
x...));
485 void play(
const Ts &...
x)
override {
493 this->
var_queue_.remove_if([&](
auto &queued) {
494 auto start = std::get<uint32_t>(queued);
495 auto timeout = std::get<optional<uint32_t>>(queued);
496 auto &var = std::get<std::tuple<Ts...>>(queued);
499 auto expired = timeout && (now - start) >= *timeout;
515 std::list<std::tuple<uint32_t, optional<uint32_t>, std::tuple<Ts...>>>
var_queue_{};
522 void play(
const Ts &...
x)
override {
536 void play(
const Ts &...
x)
override {
551 void play(
const Ts &...
x)
override {
555 optional<uint32_t> update_interval = this->update_interval_.optional_value(
x...);
556 if (update_interval.has_value()) {
void play_next_(const Ts &...x)
virtual void play(const Ts &...x)=0
void play_next_tuple_(const std::tuple< Ts... > &tuple, std::index_sequence< S... >)
virtual void play_complex(const Ts &...x)
void add_action(Action< Ts... > *action)
void add_actions(const std::initializer_list< Action< Ts... > * > &actions)
void play(const Ts &...x) ESPHOME_ALWAYS_INLINE
AndCondition(std::initializer_list< Condition< Ts... > * > conditions)
bool check(const Ts &...x) override
std::array< Condition< Ts... > *, N > conditions_
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
virtual void setup()
Where the component's initialization should happen.
void enable_loop()
Enable this component's loop.
void disable_loop()
Disable this component's loop.
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") bool cancel_timeout(const std boo cancel_timeout)(const char *name)
Cancel a timeout function.
ESPDEPRECATED("set_retry is deprecated and will be removed in 2026.8.0. Use set_timeout or set_interval instead.", "2026.2.0") void set_retry(const std uint32_t uint8_t std::function< RetryResult(uint8_t)> && f
Base class for all automation conditions.
bool check_tuple(const std::tuple< Ts... > &tuple)
Call check with a tuple of values as parameter.
virtual bool check(const Ts &...x)=0
Check whether this condition passes. This condition check must be instant, and not cause any delays.
Simple continuation action that calls play_next_ on a parent action.
void play(const Ts &...x) override
Action< Ts... > * parent_
ContinuationAction(Action< Ts... > *parent)
void play(const Ts &...x) override
TEMPLATABLE_VALUE(uint32_t, delay) void play_complex(const Ts &...x) override
float get_setup_priority() const override
bool check_internal_(uint32_t now)
ForCondition(Condition<> *condition)
float get_setup_priority() const override
bool check(const Ts &...x) override
TEMPLATABLE_VALUE(uint32_t, time)
ActionList< Ts... > then_
Condition< Ts... > * condition_
void play(const Ts &...x) override
void add_then(const std::initializer_list< Action< Ts... > * > &actions)
void play_complex(const Ts &...x) override
std::conditional_t< HasElse, ActionList< Ts... >, NoElse > else_
IfAction(Condition< Ts... > *condition)
void add_else(const std::initializer_list< Action< Ts... > * > &actions)
LambdaAction(std::function< void(Ts...)> &&f)
void play(const Ts &...x) override
std::function< void(Ts...)> f_
bool check(const Ts &...x) override
LambdaCondition(std::function< bool(Ts...)> &&f)
std::function< bool(Ts...)> f_
float get_setup_priority() const override
Condition< Ts... > * condition_
bool check(const Ts &...x) override
NotCondition(Condition< Ts... > *condition)
OrCondition(std::initializer_list< Condition< Ts... > * > conditions)
bool check(const Ts &...x) override
std::array< Condition< Ts... > *, N > conditions_
This class simplifies creating components that periodically check a state.
void set_update_interval(uint32_t update_interval)
Manually set the update interval in ms for this polling object.
float get_setup_priority() const override
ActionList< uint32_t, Ts... > then_
TEMPLATABLE_VALUE(uint32_t, count) void add_then(const std
void play_complex(const Ts &...x) override
void play(const Ts &...x) override
Loop continuation for RepeatAction that increments iteration and repeats or continues.
RepeatLoopContinuation(RepeatAction< Ts... > *parent)
RepeatAction< Ts... > * parent_
void play(const uint32_t &iteration, const Ts &...x) override
ResumeComponentAction(PollingComponent *component)
TEMPLATABLE_VALUE(uint32_t, update_interval) void play(const Ts &...x) override
PollingComponent * component_
ShutdownTrigger(float setup_priority)
float get_setup_priority() const override
void on_shutdown() override
float get_setup_priority() const override
StartupTrigger(float setup_priority)
Optimized lambda action for stateless lambdas (no capture).
void play(const Ts &...x) override
StatelessLambdaAction(void(*f)(Ts...))
Optimized lambda condition for stateless lambdas (no capture).
bool check(const Ts &...x) override
StatelessLambdaCondition(bool(*f)(Ts...))
SuspendComponentAction(PollingComponent *component)
void play(const Ts &...x) override
PollingComponent * component_
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
void play(const Ts &...x) override
PollingComponent * component_
UpdateComponentAction(PollingComponent *component)
Wait until a condition is true to continue execution.
WaitUntilAction(Condition< Ts... > *condition)
TEMPLATABLE_VALUE(uint32_t, timeout_value) void setup() override
void play_complex(const Ts &...x) override
void play(const Ts &...x) override
bool process_queue_(uint32_t now)
Condition< Ts... > * condition_
std::list< std::tuple< uint32_t, optional< uint32_t >, std::tuple< Ts... > > > var_queue_
float get_setup_priority() const override
void add_then(const std::initializer_list< Action< Ts... > * > &actions)
WhileAction(Condition< Ts... > *condition)
void play(const Ts &...x) override
void play_complex(const Ts &...x) override
Condition< Ts... > * condition_
ActionList< Ts... > then_
Loop continuation for WhileAction that checks condition and repeats or continues.
WhileLoopContinuation(WhileAction< Ts... > *parent)
void play(const Ts &...x) override
WhileAction< Ts... > * parent_
std::array< Condition< Ts... > *, N > conditions_
bool check(const Ts &...x) override
XorCondition(std::initializer_list< Condition< Ts... > * > conditions)
const Component * component
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
constexpr float DATA
For components that import data from directly connected sensors like DHT.
constexpr float PROCESSOR
For components that use data from sensors like displays.
Providing packet encoding functions for exchanging data with a remote host.
ESPPreferences * global_preferences
uint32_t fnv1_hash(const char *str)
Calculate a FNV-1 hash of str.
void init_array_from(std::array< T, N > &dest, std::initializer_list< T > src)
Initialize a std::array from an initializer_list.
void HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.
ESPPreferenceObject make_preference(size_t, uint32_t, bool)
bool sync()
Commit pending writes to flash.