Brian Murray built this 4 channel relay box, I'm not sure exactly when he built it but around 2003-2004 it was installed in the ceiling space in the Asylum, a warehouse in Kingsford. It was controlling lights in the lounge/cinema. It was wired down to the server rack and I had written a php script for controlling the lights via a browser.
After Brian died I ended up with the relay box and I made sure I had a copy of the pic code running it so I could one day talk to it again.
' relay4.bas
'
' RS232 to 4 x 10A 240V relay interface
' for PIC16F84
'
Pins = %00000000
Dirs = %11111110 ' RB0 input, RB1..RB7 outputs
high 1 ' init serial out
high 2
pause 500
read 0,Pins
mainloop:
low 2 ' CTS active
serin 0,N9600,,B0
high 2 ' CTS inactive
if B0 = "0" then off0
if B0 = "1" then on0
if B0 = "2" then off1
if B0 = "3" then on1
if B0 = "4" then off2
if B0 = "5" then on2
if B0 = "6" then off3
if B0 = "7" then on3
B0 = B0 - "A"
if B0 >= 16 then mainloop
B0 = B0 * 16
B0 = B0 | %00000110
Pins = B0
commit:
write 0,Pins
goto mainloop
off0:
low 4
goto commit
on0:
high 4
goto commit
off1:
low 5
goto commit
on1:
high 5
goto commit
off2:
low 6
goto commit
on2:
high 6
goto commit
off3:
low 7
goto commit
on3:
high 7
goto commit
18 years later and the Relay 4 is back in service. While I could have replaced the existing control circuity or mount a board inside. I decided to leave it as is and talk to the box the way it was designed over RS-232. Conveniently I've been doing another RS-232 project talking to the Renogy Rover series solar charge controllers.
One wire had come adrift probably from me taking the lid off and having a look. But once that was fixed the unit worked as originally designed. The RS-232 protocol is pretty basic its just the asci number characters 0-7 so 0 is channel one off, 1 is channel 1 on and so on.
So I've written same basic firmware that makes the device controllable using the MQTT protocol. It subscribes to command topics, publishes it's state and makes its availability known, all pretty standard things that make it possible to add it to home assistant pretty easy. I didn't bother get into making it auto discoverable as there's only going to ever be one of these.
Fittingly it back in a ceiling space controlling lights in my workshop/studio/lab.
I've got a couple of "modern" off the shelf boards that do the same thing and really only need to be nicely mounted in an enclosure, so I'm thinking of building up some modern equivalents as there's always more thing to automate.