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