Home Brewed MQTT sketches in Arduino UNO/Wemos D1 R2/ESP8266/ESP32

I am doing my first baby steps in Home Assistant and what I really liked was that as soon as I connected my Mosquitto MQTT server to HA my 4 Tasmota devices were recognized.

But how to get my other home brewed Arduino UNO/ESP8266/ESP32 sketches recognized by HA?
Maybe I should do it the hard way and RTFM somewhere but can I explore it the easy way?

So the question is can I alter my sketch (read MQTT topics) in such a way that HA thinks it is a Tasmota device and benefits the automatic recognition of a Tasmota device? And if this is possible is this also possible for an Arduino UNO with W5100 Wifi hat?

fyi Running HA in a docker container on a NUC (together with Openhab, Frontail, InfluxDB, Grafana, Mosquitto, LMS, PiHole containers)

You should really do some reading. It’s all well documented here: MQTT - Home Assistant

In short: Home Assistant defines its own discovery convention, which your own Arduino sketches could implement.

However, before I even explain more about that, you probably do not need any of that. As long as your microcontrollers send status and receive commands via MQTT, you can simply define custom MQTT entities in your Home Assistant config. For a “sensor” example look here, “switch” or “light” entities are equally possible. MQTT Sensor - Home Assistant

Good advice - and after writing a custom watering controller in Python:

  • The mosquitto command line clients are very useful for development both to sub and to pub.
  • MQTT discovery works in real-time, so you can iterate your MQTT messages whilst watching what HASS sees.

More details are here:

I fully agree everybody should do a RTFM better but if I do and did at this point, but also after two beers, I might get confused at this page.

Is the HA MQTT default discovery now homeassistant or home-assistant (as used in ‘Testing your setup’) ??? Here is the devil in the detail.

I missed or did not read yet this part but I shall continue with the HA MQTT default discovery prefix (one of the two) and not try to pretend my device is a Tasmota device.

Also fully agree with James (@FloatingBoater) that MQTT explorer is one of the finest for MQTT,

There’s a snippet of mosquitto_pub test code in my linked post above which should help.

Install the mosquitto command line client (I used Linux on a RPi400 to sit outside next to the garden test rig), and paste the command line in. HASS should show a new device almost immediately. Use MQ Explorer to delete the retained message, and it’s like nothing happened!

As for the docs, I cheated and found a Flora code example to get the basic syntax, then crafted details like sensors/ actuators/ custom icons.

The first line of code is always the hardest. What function name should it be called? A mate just aways used porkpie!

The command line tool is always great to have at hand, however, for convenient testing I suggest to work with MQTT Explorer or another proper UI tool.