ESPHome 2025.5.0
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
8namespace esphome {
9namespace mqtt_subscribe {
10
11static const char *const TAG = "mqtt_subscribe.text_sensor";
12
14 this->parent_->subscribe(
15 this->topic_, [this](const std::string &topic, const std::string &payload) { this->publish_state(payload); },
16 this->qos_);
17}
19void MQTTSubscribeTextSensor::set_qos(uint8_t qos) { this->qos_ = qos; }
21 LOG_TEXT_SENSOR("", "MQTT Subscribe Text Sensor", this);
22 ESP_LOGCONFIG(TAG, " Topic: %s", this->topic_.c_str());
23}
24
25} // namespace mqtt_subscribe
26} // namespace esphome
27
28#endif // USE_MQTT
void subscribe(const std::string &topic, mqtt_callback_t 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)
const float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
Definition component.cpp:27
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7