14 [
this](
const std::string &topic,
const std::string &payload) {
16 if (!
val.has_value()) {
17 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
29 LOG_SENSOR(
"",
"MQTT Subscribe",
this);
30 ESP_LOGCONFIG(TAG,
" Topic: %s", this->
topic_);
void subscribe(MQTTTopicSource topic, F &&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 publish_state(float state)
Publish a new state to the front-end.
ESPHOME_LOG_TAG(TAG, "mqtt_subscribe.sensor")
MQTTClientComponent * global_mqtt_client
constexpr float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.