Mqtt gateway on arduino mega + w5100 integration

currently I have about 8 sets of arduino mega + w5100 which are communicating with HA via MQTT. Each of set is either for contorliing output - topic like"


with value 0 or 1 to on/off the switch or for controlling input from buttons.
how should i write my sketch (or is there something already written?) so device will be picked up by ha integrations ? are there any instructions/convetions for writing programs for such devices ?


OpenMqttgateway can do this for you by using ZactuatorONOFF, do you need to control several pins on each mega ?

thanks, I’ll check that !
yes, I am using (on average) pins from 14 to 47 on all of my devices. I have three only for relays, and five for inputs such as buttons on the walls, pirs, door/window sensors etc.

I will need a modification to allow you to choose the pin when publishing.

i have really messy code, but it works in this manner :

  • connect to ethernet
  • connect to mqtt broker
  • build device mqtt topics like current device name/I’d, current build, current max/IP etc
  • if working mode is for outputs (relays)
    • subscribe to root_topic/device_id/# (full correct topic : root_topic/device_id/pin/set)
    • if pin from topic is within range of working pins set Arduino pin with state given in payload
    • confirm change of state on topic root_topic/device_id/pin/state
  • if working mode is for inputs :
    • listen to change on pins and publish it on root_topic/device_id/pin/state. (I have function whic distincts single click, double click and hold and publishes 1,2 or 3 via mqtt)