ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4
8
10
11class TextSensorStateTrigger : public Trigger<std::string> {
12 public:
14 parent->add_on_state_callback([this](const std::string &value) { this->trigger(value); });
15 }
16};
17
18class TextSensorStateRawTrigger : public Trigger<std::string> {
19 public:
21 parent->add_on_raw_state_callback([this](const std::string &value) { this->trigger(value); });
22 }
23};
24
25template<typename... Ts> class TextSensorStateCondition : public Condition<Ts...> {
26 public:
27 explicit TextSensorStateCondition(TextSensor *parent) : parent_(parent) {}
28
30
31 bool check(const Ts &...x) override { return this->parent_->state == this->state_.value(x...); }
32
33 protected:
35};
36
37template<typename... Ts> class TextSensorPublishAction : public Action<Ts...> {
38 public:
41
42 void play(const Ts &...x) override { this->sensor_->publish_state(this->state_.value(x...)); }
43
44 protected:
46};
47
48} // namespace esphome::text_sensor
virtual void play(const Ts &...x)=0
Base class for all automation conditions.
Definition automation.h:304
virtual bool check(const Ts &...x)=0
void trigger(const Ts &...x)
Definition automation.h:325
void add_on_state_callback(std::function< void(const std::string &)> callback)
void add_on_raw_state_callback(std::function< void(const std::string &)> callback)
Add a callback that will be called every time the sensor sends a raw value.
void publish_state(const std::string &state)
TEMPLATABLE_VALUE(std::string, state) void play(const Ts &...x) override
Definition automation.h:40
TEMPLATABLE_VALUE(std::string, state) bool check(const Ts &...x) override
Definition automation.h:29
bool state
Definition fan.h:2
uint16_t x
Definition tt21100.cpp:5