Help needed for mqtt multi sensor/switch device with autodiscovery

Hi all,
right now I have my home setup centralised in control cabinet in my garage - all lights, sockets I’d like to toggle, wall light buttons, pirs and da temperature sensor are in this cabinet.
I also have multiple Arduino mega+w5100 devices to read from buttons/pins and steer lights and sockets via relays (all through mqtt protocol). every switch has own topics, every button sends 1/2/3 (depending on short press, double press, hold) to mqtt on its own topic.
Right now I would like to write new sketch for Arduino, this time with autodiscovery. Has anyone written something like that and would like to share ? how should I config the "device"in the registry ? can I have “device” in area garage that steer light in area kitchen ?
is there maybe something like tasmota or esphome but for mega with Eth (not WiFi)? all I found was for esp :frowning:

Hi,

I tried to have auto discovery, but not working…
I use the mqtt add-on, I can catch all messages sent to mqtt and display them to Lovelace with mqtt sensors components, but the auto discovery is not working.
Similar topic : MQTT auto discovery not working
He have the same configuration as me, but for me, the link between mqtt add-on and home assistant is working!

Somebody can help us? :grin:

Well I’m rather looking for help in the setup part. My previous sketch works, but I want to update my devices with something up-to-date and using nowadays solutions :wink: I’d like to write sketch using some “official” convention of mqtt discovery (if there is any) and also looking for help how to create topics, how to configure every entity (for everey pin of mega) storing its name and all of configs, how should i configure the “device” with its firmware and so on.

See it discovery is enabled

Hi, working for me after multiple HA restarts

Hi, as i said - i’m looking for convention in writing sketch/best practises etc. My discovery works fine :slight_smile: I just don’t know how to handle ~25 pins at once, where some of them are for relays, some of them are for reading buttons/pirs, some for DS temp sensors, and so on :slight_smile: How should i define topics, try to do this dynamically ? how to generate topics (on the basis of pin role) and how to store them in sketch?