ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
mqtt_subscribe_text_sensor.cpp
Go to the documentation of this file.
2
3#ifdef USE_MQTT
4
5#include "esphome/core/log.h"
6#include <utility>
7
9
10ESPHOME_LOG_TAG(TAG, "mqtt_subscribe.text_sensor");
11
13 this->parent_->subscribe(
14 this->topic_, [this](const std::string &topic, const std::string &payload) { this->publish_state(payload); },
15 this->qos_);
16}
19 LOG_TEXT_SENSOR("", "MQTT Subscribe Text Sensor", this);
20 ESP_LOGCONFIG(TAG, " Topic: %s", this->topic_);
21}
22
23} // namespace esphome::mqtt_subscribe
24
25#endif // USE_MQTT
void subscribe(MQTTTopicSource topic, F &&callback, uint8_t qos=0)
Subscribe to an MQTT topic and call callback when a message is received.
void publish_state(const std::string &state)
Definition text_sensor.h:42
ESPHOME_LOG_TAG(TAG, "mqtt_subscribe.sensor")
constexpr float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
Definition component.h:57