I'm not able to see my 'device/entitiy' in Home Assistant.
I'm using for the first time your library to simplify the management of the MQTT Discovery used by HA.
I have downloaded your "onoff_light" sample and loaded on my NodeMCU (with my settings for the ssid, password & c.)
I'm using Mosquitto broker Add on directly in HA, I have set the discovery_prefix to "/homeassistant" (I think the default of Home Assistant when it's not changed).
HAMqttDevice light("My Nice Lamp", HAMqttDevice::LIGHT, "/homeassistant");
I have also enabled the Serial to show some messages in the serial console:
client.enableDebuggingMessages();
The connection seems working in the correct way:
17:56:32.771 -> MQTT: Connecting to broker "192.168.1.15" with client name "my_sensor" ... (7.259000s) - ok. (7.366000s)
17:56:32.913 -> MQTT: Subscribed to [/homeassistant/light/my_nice_lamp/cmd]
17:56:32.913 -> MQTT: Subscribed to [/homeassistant/status]
17:56:33.056 -> MQTT >> [/homeassistant/status] online
17:56:33.056 -> MQTT << [/homeassistant/light/my_nice_lamp/config] {"~":"/homeassistant/light/my_nice_lamp","name":"My Nice Lamp","cmd_t":"~/cmd","stat_t":"~/state","json_attr_t":"~/attr"}
17:56:38.065 -> MQTT << [/homeassistant/light/my_nice_lamp/state] OFF
17:56:38.065 -> MQTT << [/homeassistant/light/my_nice_lamp/attr] {"IP":"192.168.1.153"}
But I'm not able to see the my Device in the integration page (under MQTT, but I'm not sure if the lib works in this way). I'm also not able to see my entity under the states page of "Developer tools" (I have searched the name 'my_nice_lamp'). The others devices that are using the MQTT are available under the MQTT integration (I have only Shelly devices actually), I think that the Mosquitto broker are configured correctly.
Have you additional test to suggest?
Thanks
Additional info.
I have changed again the discovery_prefix in this way:
HAMqttDevice light("My Nice Lamp", HAMqttDevice::LIGHT, "homeassistant");
And in the code:
client.subscribe("/homeassistant/status", [] (const String &payload)
In this way now I'm able to see the entity inside the list of entities (not visible in the MQTT integration, but I'm not sure if this is an error).
Did you ever get this working @gigios? I'm having the same issue. I connect to the MQTT broker, everything gets sent out for the config, but it never shows up in HA.
No, I'm currently testing ESPHome. Easier to configure but more 'rigid' in some settings. The ideal would be to be able to make the library work but at the moment I don't have much time to understand where I'm wrong.
Hello,
Never put a "/" before the prefix.
Doing this will not work:
HAMqttDevice light("My Nice Lamp", HAMqttDevice::LIGHT, "/homeassistant");
...
client.subscribe("/homeassistant/status", [] (const String &payload)
Doing this is ok :
HAMqttDevice light("My Nice Lamp", HAMqttDevice::LIGHT, "homeassistant");
...
client.subscribe("homeassistant/status", [] (const String &payload)
Also, the MQTT library used by this lib have a maximum payload size that is not really big. If you exceed the payload size, the config payload will not be sent and Home Assistant will not see your device.
Try to add this line in setup() to increase the maximum MQTT payload size to 512 bytes :
client.setMaxPacketSize(512);
See this line from the RGBW exemple.
I ended up creating a HA script that sets up all my new MQTT entities under a single HA device. Then I just skipped this whole library and manually publish updates using his other library EspMQTTClient. I wanted more customizable topics anyway.