ESPHome 2025.5.0
Loading...
Searching...
No Matches
interval.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome {
7namespace interval {
8
9class IntervalTrigger : public Trigger<>, public PollingComponent {
10 public:
11 void update() override {
12 if (this->started_)
13 this->trigger();
14 }
15
16 void setup() override {
17 if (this->startup_delay_ == 0) {
18 this->started_ = true;
19 } else {
20 this->set_timeout(this->startup_delay_, [this] { this->started_ = true; });
21 }
22 }
23
24 void set_startup_delay(const uint32_t startup_delay) { this->startup_delay_ = startup_delay; }
25
26 float get_setup_priority() const override { return setup_priority::DATA; }
27
28 protected:
29 uint32_t startup_delay_{0};
30 bool started_{false};
31};
32
33} // namespace interval
34} // namespace esphome
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
Definition component.cpp:72
This class simplifies creating components that periodically check a state.
Definition component.h:301
void trigger(Ts... x)
Definition automation.h:96
void set_startup_delay(const uint32_t startup_delay)
Definition interval.h:24
float get_setup_priority() const override
Definition interval.h:26
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:19
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7