8namespace mqtt_subscribe {
10static const char *
const TAG =
"mqtt_subscribe.sensor";
15 [
this](
const std::string &topic,
const std::string &payload) {
17 if (!
val.has_value()) {
18 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
31 LOG_SENSOR(
"",
"MQTT Subscribe",
this);
32 ESP_LOGCONFIG(TAG,
" Topic: %s", this->
topic_.c_str());
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.
float get_setup_priority() const override
void dump_config() override
void set_qos(uint8_t qos)
void publish_state(float state)
Publish a new state to the front-end.
MQTTClientComponent * global_mqtt_client
const float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
Providing packet encoding functions for exchanging data with a remote host.
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.