Before I start, I am not a programmer, I dont do much of this at all but IoT is a passion and I’ve created some ALPHA code that was based on Jon’s LightSwitchMQTT controller.
The code has 24 digital inputs and 24 digital outputs. I’ve removed all of the original OLED and tempsensor code as its something I don’t need.
When the unit powers up it sends all of its input states out via MQTT so you can sync your automation device.
panelID = 20 , you can change in the code.
Inputs:
stat/20/Input/1 0 means the input is shorted to ground
stat/20/Input/1 1 means the input is open (pulled high)
Outputs:
cmnd/20/Output/1 0 means you’ve turned the output on (setup to go high to control chinese relay boards)
cmnd/20/Output/1 1 means you’ve turned the output off
In response to receiving an “output” command, the device will respond so you’ve got positive acknowledgement
Sending it a: cmnd/20/Output/1 0 will return stat/20/Output/1 0
This will work well with NodeRed (switch status as an input)
Unit will send: tele/20/Status Alive when the watchdog timer trips.
The code can be found at:
If anyone wants to help me clean it up or do things smarter and better you are welcome to do a pull. There is heaps of debug on the serial port, probably needs cleaning up but it all helps with debugging. There are some bugs in the code:
- Always reports A0 status on boot
- sscanf(topic,"%[^/]/%d/%[^/]/%d",&tempInt,&OutputNumber); doesnt parse correctly on the complete topic however it gives me integers ok.