OK let’s see what I can do for you…
Your code subscribes to the topic “boiler” in the reconnect() function; this is your command_topic for your Home Assistant configuration:
client.subscribe("boiler");
That is an odd topic, generally MQTT topics are organized in some kind of hierarchy, like “upstairs/hallway/light” and generally the last segment gives an idea of what the topic is for (like “upstairs/hallway/light/command” for the device to subscribe to to receive commands and “upstairs/hallway/light/state” for the device to publish its state back to).
Unfortunately, the code you posted doesn’t publish anything. It receives a command over the “boiler” topic and looks like it sets the servo position based on the message received, but that’s it. So, you have no state_topic for your Home Assistant config.
Your code doesn’t provide for connecting with an MQTT username and password. But you can easily modify it to add them. Add mqtt_user and mqtt_pass variables under mqtt_server, like so:
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Servo.h>
const char* ssid = "weefi";
const char* password = "randompasswordhere";
const char* mqtt_server = "192.168.1.92";
const char* mqtt_user = "[your username]";
const char* mqtt_pass = "[your password]";
Then, in the reconnect() function, add those variables to the call to client.connect(), like so:
void reconnect() {
while (!client.connected())
{
Serial.print("Attempting MQTT connection...");
String clientId = "ESP8266Client-";
clientId += String(random(0xffff), HEX);
if (client.connect(clientId.c_str(), mqtt_user, mqtt_pass))
{
Serial.println("connected");
client.subscribe("boiler");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(6000);
}
}
} //end reconnect()
Try those things and then let me know what else you need help with!