diff --git a/esphome/components/mqtt/mqtt_client.h b/esphome/components/mqtt/mqtt_client.h index 127e4073b0..0d52d98d2f 100644 --- a/esphome/components/mqtt/mqtt_client.h +++ b/esphome/components/mqtt/mqtt_client.h @@ -405,15 +405,14 @@ template class MQTTPublishJsonAction : public Action { void set_payload(std::function payload) { this->payload_ = payload; } void play(const Ts &...x) override { - auto f = std::bind(&MQTTPublishJsonAction::encode_, this, x..., std::placeholders::_1); auto topic = this->topic_.value(x...); auto qos = this->qos_.value(x...); auto retain = this->retain_.value(x...); - this->parent_->publish_json(topic, f, qos, retain); + this->parent_->publish_json( + topic, [this, x...](JsonObject root) { this->payload_(x..., root); }, qos, retain); } protected: - void encode_(Ts... x, JsonObject root) { this->payload_(x..., root); } std::function payload_; MQTTClientComponent *parent_; };