Node-red-contrib-i2c & Seeed Raspi Relay Board

I am trying to switch the seeed relay Board (4 relays) with node-red-contrib-i2c. Does anybody already successfully run this relay board with node-red? I only have a Python program and have problems to extract the command bytes.

[LInk to Python code]
(https://github.com/johnwargo/Seeed-Studio-Relay-Board/blob/master/relay_lib_seeed.py)

wiki.seeedstudio.com/Raspberry_Pi_Relay_Board_v1.0/

Any help appreciated

You could run the Python script from node-red with the exec node.

it's a demo code and runs all relays. That is not what I want. Actually, as I understand from the demo program, I have to use 3 bytes to send to the board. On 2 of them they are doing some bit shifting. It looks like a logic "or" and "and". I am not good enough in Python to understand what the result should be.
Actually sending a buffer (only 0s and 1s) with the I2C node containing 3 bytes should be the way to go.

Just had a quick look at the code:
Device address is 0x20
DEVICE_REG_MODE1 = 0x06
relay 1 =1, 2=2, 3=4, 4=8 (Binary)

Try sending 0x20, 0x06, 0x1 to turn the first relay on
and 0x20, 0x06, 0x0 to turn it off. No guarantees.

Thats address 0x20
Register 0x06
data 0x1

Data might be inverted 0=on 1=off

Thanks for your support. I have it running with node red since yesterday. Funny thing is that relay 2 = 4 and relay 3 is 2. As soon as I have made my flows a bit nicer I will post them here. Switching a single relay is also a bit tricky as you first have to get the current status of the relays on the board and then change only the bit of the relay you want to switch and send all four bits back to the board. btw node-red-contrib-i2c works perfectly.

Yes, classic bit masking. I had almost forgotten how to do it! Glad you got it working!

with the help of a loupe I just found out, that the sequence of the leds is 1324. this means that you where right with the relay numbering! I thought they were in a sequence.

Can you try this please:

[{"id":"644d9b48.5064f4","type":"inject","z":"8c9265a3.f5a4a8","name":"","topic":"on","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":240,"wires":[["4bfe726.5d6058c"]]},{"id":"f8afecb0.5aba3","type":"debug","z":"8c9265a3.f5a4a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":730,"y":440,"wires":[]},{"id":"7ab9ba6f.1a5b94","type":"inject","z":"8c9265a3.f5a4a8","name":"","topic":"","payload":"15","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":640,"wires":[["e740c631.884a88"]]},{"id":"e740c631.884a88","type":"change","z":"8c9265a3.f5a4a8","name":"","rules":[{"t":"set","p":"command","pt":"flow","to":"payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":640,"wires":[["497ce237.5b3dac"]]},{"id":"4bfe726.5d6058c","type":"function","z":"8c9265a3.f5a4a8","name":"","func":"var command = flow.get(\"command\");\nmsg.relay = 1 << (msg.payload-1)\n\nswitch(msg.topic){\n    case 'on':\n    command = command &= ~msg.relay\n    break;\n    case 'off':\n    command = command |= msg.relay\n    break;\n}\nflow.set(\"command\", command);\nmsg.payload = command\nreturn msg;\n\n// Invert the following\n\n//To set a bit:\n\n//n |= mask;\n//To clear a bit:\n\n//n &= ~mask;\n//To toggle a bit:\n\n//n ^= mask;\n\n//switch(expression) {//\n//  case x:\n//    // code block\n//    break;\n//  case y:\n//    // code block\n//    break;\n//  default:\n//    // code block\n//}","outputs":1,"noerr":0,"x":310,"y":380,"wires":[["e74e37a8.740468"]]},{"id":"99312c1f.1ac4a","type":"inject","z":"8c9265a3.f5a4a8","name":"","topic":"off","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":280,"wires":[["4bfe726.5d6058c"]]},{"id":"4b3ddb33.6248d4","type":"inject","z":"8c9265a3.f5a4a8","name":"","topic":"on","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":320,"wires":[["4bfe726.5d6058c"]]},{"id":"300697ee.ab4428","type":"inject","z":"8c9265a3.f5a4a8","name":"","topic":"off","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":360,"wires":[["4bfe726.5d6058c"]]},{"id":"623dbae7.b76cf4","type":"inject","z":"8c9265a3.f5a4a8","name":"","topic":"on","payload":"3","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":400,"wires":[["4bfe726.5d6058c"]]},{"id":"8a488e4b.78f35","type":"inject","z":"8c9265a3.f5a4a8","name":"","topic":"off","payload":"3","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":440,"wires":[["4bfe726.5d6058c"]]},{"id":"84ccb4d9.ef1c18","type":"inject","z":"8c9265a3.f5a4a8","name":"","topic":"on","payload":"4","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":480,"wires":[["4bfe726.5d6058c"]]},{"id":"5f33bea4.0fd2e","type":"inject","z":"8c9265a3.f5a4a8","name":"","topic":"off","payload":"4","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":520,"wires":[["4bfe726.5d6058c"]]},{"id":"24748512.65e78a","type":"comment","z":"8c9265a3.f5a4a8","name":"Inject this first to turn off all relays and initialise the flow variable","info":"Inject this first to turn off all relays","x":290,"y":600,"wires":[]},{"id":"e74e37a8.740468","type":"function","z":"8c9265a3.f5a4a8","name":"Replace this with the the I2C out node","func":"//address 32\n//command 6\nreturn msg;","outputs":1,"noerr":0,"x":560,"y":380,"wires":[["f8afecb0.5aba3"]]},{"id":"497ce237.5b3dac","type":"function","z":"8c9265a3.f5a4a8","name":"Replace this with the the I2C out node","func":"//address 32\n//command 6\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":640,"wires":[[]]}]

here my flows for the Seeed Raspi Relay shield:

[{"id":"57da71a5.519be","type":"tab","label":"I2C","disabled":false,"info":""},{"id":"a0db703.98f6b9","type":"i2c scan","z":"57da71a5.519be","name":"I2C scan","x":280,"y":100,"wires":[["73b294be.cc89ec"],["22b9fd8c.88e152"]]},{"id":"73b294be.cc89ec","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":80,"wires":[]},{"id":"22b9fd8c.88e152","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":120,"wires":[]},{"id":"c80b3a64.ef9f68","type":"inject","z":"57da71a5.519be","name":"I2C","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":100,"wires":[["a0db703.98f6b9"]]},{"id":"c8d32b33.1066a8","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":300,"wires":[["357ac0ab.10245"]]},{"id":"357ac0ab.10245","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":300,"wires":[]},{"id":"c7c67536.cc0d98","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"0","payloadType":"num","count":"1","x":320,"y":260,"wires":[]},{"id":"aa1d6209.04a5c","type":"inject","z":"57da71a5.519be","name":"all r on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":260,"wires":[["c7c67536.cc0d98","130d917e.ff055f"]]},{"id":"97199226.7e122","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"1","payloadType":"num","count":"1","x":1000,"y":440,"wires":[]},{"id":"c3796079.36dd8","type":"inject","z":"57da71a5.519be","name":"r1 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":810,"y":440,"wires":[["97199226.7e122","eda21c15.1eeee"]]},{"id":"3b28f587.bb707a","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"2","payloadType":"num","count":"1","x":1000,"y":520,"wires":[]},{"id":"bdb527fe.e4a2c8","type":"inject","z":"57da71a5.519be","name":"r2 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":810,"y":520,"wires":[["3b28f587.bb707a","dd7d368.330a4c8"]]},{"id":"ea1026ec.f299c8","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"4","payloadType":"num","count":"1","x":1000,"y":600,"wires":[]},{"id":"576221d7.f80ab","type":"inject","z":"57da71a5.519be","name":"r3 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":810,"y":600,"wires":[["ea1026ec.f299c8","18c118bd.5d26c7"]]},{"id":"8afffeec.0c145","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"8","payloadType":"num","count":"1","x":1000,"y":680,"wires":[]},{"id":"5cba0fb8.cdbb7","type":"inject","z":"57da71a5.519be","name":"r4 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":810,"y":680,"wires":[["8afffeec.0c145","f8b4768c.2d8398"]]},{"id":"38347ddb.22b4e2","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"15","payloadType":"num","count":"1","x":1000,"y":260,"wires":[]},{"id":"fe419c0e.54517","type":"inject","z":"57da71a5.519be","name":"all r off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":810,"y":260,"wires":[["38347ddb.22b4e2","ee4d7fa6.376b2"]]},{"id":"130d917e.ff055f","type":"delay","z":"57da71a5.519be","name":"500 ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":300,"wires":[["c8d32b33.1066a8"]]},{"id":"eda21c15.1eeee","type":"delay","z":"57da71a5.519be","name":"500 ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1000,"y":480,"wires":[["439d8afb.e771d4"]]},{"id":"439d8afb.e771d4","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":1130,"y":480,"wires":[["4fec07c4.57a038"]]},{"id":"4fec07c4.57a038","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1270,"y":480,"wires":[]},{"id":"dd7d368.330a4c8","type":"delay","z":"57da71a5.519be","name":"500 ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1000,"y":560,"wires":[["b932029e.ed005"]]},{"id":"b932029e.ed005","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":1130,"y":560,"wires":[["ffc9ca96.58b898"]]},{"id":"ffc9ca96.58b898","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1270,"y":560,"wires":[]},{"id":"18c118bd.5d26c7","type":"delay","z":"57da71a5.519be","name":"500 ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1000,"y":640,"wires":[["d38a1a69.31ed68"]]},{"id":"d38a1a69.31ed68","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":1130,"y":640,"wires":[["501f7d37.581564"]]},{"id":"501f7d37.581564","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1270,"y":640,"wires":[]},{"id":"f8b4768c.2d8398","type":"delay","z":"57da71a5.519be","name":"500 ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1000,"y":720,"wires":[["2954527f.8779ce"]]},{"id":"2954527f.8779ce","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":1130,"y":720,"wires":[["62df7f67.1b875"]]},{"id":"62df7f67.1b875","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1270,"y":720,"wires":[]},{"id":"ee4d7fa6.376b2","type":"delay","z":"57da71a5.519be","name":"500 ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1000,"y":300,"wires":[["d6b688cf.2024a8"]]},{"id":"d6b688cf.2024a8","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":1130,"y":300,"wires":[["d3d743d6.857aa"]]},{"id":"d3d743d6.857aa","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1270,"y":300,"wires":[]},{"id":"923e4243.3b7bb","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"14","payloadType":"num","count":"1","x":320,"y":440,"wires":[]},{"id":"ff8feb43.e040f8","type":"inject","z":"57da71a5.519be","name":"r1 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":440,"wires":[["923e4243.3b7bb","db8b96d1.c93088"]]},{"id":"aa202f8f.7940a","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"13","payloadType":"num","count":"1","x":320,"y":520,"wires":[]},{"id":"8bf27fbd.2f309","type":"inject","z":"57da71a5.519be","name":"r2 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":520,"wires":[["aa202f8f.7940a","3da7cd90.07eef2"]]},{"id":"5cbd50fb.8162b","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"11","payloadType":"num","count":"1","x":320,"y":600,"wires":[]},{"id":"b94212dc.616a4","type":"inject","z":"57da71a5.519be","name":"r3 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":600,"wires":[["5cbd50fb.8162b","58fbd114.5eb47"]]},{"id":"4602c948.b5f098","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"7","payloadType":"num","count":"1","x":320,"y":680,"wires":[]},{"id":"f55b5814.429d18","type":"inject","z":"57da71a5.519be","name":"r4 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":680,"wires":[["4602c948.b5f098","6791fdc0.9bee54"]]},{"id":"db8b96d1.c93088","type":"delay","z":"57da71a5.519be","name":"500 ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":480,"wires":[["fb06afab.b1e5b"]]},{"id":"fb06afab.b1e5b","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":480,"wires":[["103d444.1cf6abc"]]},{"id":"103d444.1cf6abc","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":480,"wires":[]},{"id":"3da7cd90.07eef2","type":"delay","z":"57da71a5.519be","name":"500 ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":560,"wires":[["18b86c49.201f44"]]},{"id":"18b86c49.201f44","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":560,"wires":[["c9980dd9.45e51"]]},{"id":"c9980dd9.45e51","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":560,"wires":[]},{"id":"58fbd114.5eb47","type":"delay","z":"57da71a5.519be","name":"500 ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":640,"wires":[["44cc93ac.1942ec"]]},{"id":"44cc93ac.1942ec","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":640,"wires":[["c35cedbf.13e52"]]},{"id":"c35cedbf.13e52","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":640,"wires":[]},{"id":"6791fdc0.9bee54","type":"delay","z":"57da71a5.519be","name":"500 ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":720,"wires":[["dac65cfc.3b779"]]},{"id":"dac65cfc.3b779","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":720,"wires":[["e12642b9.0253f"]]},{"id":"e12642b9.0253f","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":720,"wires":[]},{"id":"7f2eb4d3.4a86dc","type":"inject","z":"57da71a5.519be","name":"device status check","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":690,"y":100,"wires":[["4b7766b7.4dfe88"]]},{"id":"4b7766b7.4dfe88","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":870,"y":100,"wires":[["28b96e3c.e9bd02"]]},{"id":"c9b53692.3a60d8","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1170,"y":80,"wires":[]},{"id":"28b96e3c.e9bd02","type":"function","z":"57da71a5.519be","name":"","func":"return [{payload : msg.payload},\n        {payload :  msg.payload.toString(2).padStart(4, '0')}\n       ];","outputs":2,"noerr":0,"x":1010,"y":100,"wires":[["c9b53692.3a60d8"],["932d9fe8.031dd"]]},{"id":"932d9fe8.031dd","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1170,"y":120,"wires":[]},{"id":"641c1ba9.c785d4","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":630,"y":1260,"wires":[["555dd908.37f148"]]},{"id":"44be667e.060e68","type":"inject","z":"57da71a5.519be","name":"toggle r1","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":880,"wires":[["2459c14d.a2c3ce"]]},{"id":"70c2b9e2.824c28","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":630,"y":940,"wires":[["245a9c21.285894"]]},{"id":"245a9c21.285894","type":"function","z":"57da71a5.519be","name":"","func":"var data = msg.payload;\nvar relay = msg.relay;\nvar result = data^relay;\nmsg.payload = result;\nreturn msg;","outputs":1,"noerr":0,"x":750,"y":940,"wires":[["b72763c7.c7b12"]]},{"id":"b72763c7.c7b12","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"payload","payloadType":"msg","count":"1","x":880,"y":940,"wires":[]},{"id":"2459c14d.a2c3ce","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":880,"wires":[["fa736429.7760c8"]]},{"id":"86fe7eae.59976","type":"inject","z":"57da71a5.519be","name":"toggle r2","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":920,"wires":[["68140e94.fd806"]]},{"id":"68140e94.fd806","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":920,"wires":[["fa736429.7760c8"]]},{"id":"187a93ee.08aedc","type":"inject","z":"57da71a5.519be","name":"toggle r3","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":960,"wires":[["aa757bb4.8d4878"]]},{"id":"aa757bb4.8d4878","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"3","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":960,"wires":[["fa736429.7760c8"]]},{"id":"1ac58952.79aab7","type":"inject","z":"57da71a5.519be","name":"toggle r4","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1000,"wires":[["7c085399.f5e9ec"]]},{"id":"7c085399.f5e9ec","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"4","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1000,"wires":[["fa736429.7760c8"]]},{"id":"47583018.67892","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1120,"wires":[["9afb19ee.559858"]]},{"id":"fa736429.7760c8","type":"function","z":"57da71a5.519be","name":"","func":"var relay = msg.relay;\nif (relay == 3){\n    msg.relay = 4;\n}\nif (relay == 4){\n    msg.relay = 8;\n}\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":940,"wires":[["70c2b9e2.824c28"]]},{"id":"4b25d308.b98fac","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"4","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1360,"wires":[["9afb19ee.559858"]]},{"id":"77d5b4d5.25d71c","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"3","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1280,"wires":[["9afb19ee.559858"]]},{"id":"d21e2dde.0a8a9","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1200,"wires":[["9afb19ee.559858"]]},{"id":"960e3a67.f5d538","type":"inject","z":"57da71a5.519be","name":"switch r1 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1120,"wires":[["47583018.67892"]]},{"id":"cb732c72.1c852","type":"inject","z":"57da71a5.519be","name":"switch r2 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1200,"wires":[["d21e2dde.0a8a9"]]},{"id":"3f9755c1.39bfaa","type":"inject","z":"57da71a5.519be","name":"switch r3 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1280,"wires":[["77d5b4d5.25d71c"]]},{"id":"17c78dc7.2f5482","type":"inject","z":"57da71a5.519be","name":"switch r4 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1360,"wires":[["4b25d308.b98fac"]]},{"id":"c6fbc1d5.0c648","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1160,"wires":[["9afb19ee.559858"]]},{"id":"4f85deba.616a7","type":"inject","z":"57da71a5.519be","name":"switch r1 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1160,"wires":[["c6fbc1d5.0c648"]]},{"id":"57251349.0c76ec","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1240,"wires":[["9afb19ee.559858"]]},{"id":"2aaca5ac.8a173a","type":"inject","z":"57da71a5.519be","name":"switch r2 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1240,"wires":[["57251349.0c76ec"]]},{"id":"5e6ac02c.b5372","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"3","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1320,"wires":[["9afb19ee.559858"]]},{"id":"c69dd00d.1097","type":"inject","z":"57da71a5.519be","name":"switch r3 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1320,"wires":[["5e6ac02c.b5372"]]},{"id":"fc5eed6b.9baea","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"4","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1400,"wires":[["9afb19ee.559858"]]},{"id":"9a34a124.52787","type":"inject","z":"57da71a5.519be","name":"switch r4 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1400,"wires":[["fc5eed6b.9baea"]]},{"id":"9afb19ee.559858","type":"function","z":"57da71a5.519be","name":"","func":"var relay = msg.relay;\nif (relay == 3){\n    msg.relay = 4;\n}\nif (relay == 4){\n    msg.relay = 8;\n}\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":1260,"wires":[["641c1ba9.c785d4"]]},{"id":"89de8eca.023bb","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"payload","payloadType":"msg","count":"1","x":880,"y":1260,"wires":[]},{"id":"83b87ebc.429","type":"comment","z":"57da71a5.519be","name":"switch on or off; with bit masking, no impact on other relays,  if relay already on or off do nothing","info":"","x":360,"y":1060,"wires":[]},{"id":"78b139e2.f909a8","type":"comment","z":"57da71a5.519be","name":"switch all 4 relays on or off","info":"","x":150,"y":180,"wires":[]},{"id":"dc7c9541.bad5a8","type":"comment","z":"57da71a5.519be","name":"simple switch, no bit masking, impacts other relays","info":"","x":230,"y":380,"wires":[]},{"id":"1f5e76b2.fb5cb9","type":"comment","z":"57da71a5.519be","name":"Toggles relay on and of","info":"","x":140,"y":820,"wires":[]},{"id":"555dd908.37f148","type":"function","z":"57da71a5.519be","name":"","func":"var data = msg.payload;\nvar relay = msg.relay;\nvar value = msg.value;\nvar bit = data&relay;\nif (value === 1){\n    if (bit !== relay){\n        msg.payload = data\n        return msg;\n    }    \n    msg.payload = data^relay;\n    return msg;\n}\nif (value === 0){\n    if (bit === relay){\n        msg.payload = data\n        return msg;\n    }    \n    msg.payload = data^relay;\n} \nreturn msg;","outputs":1,"noerr":0,"x":750,"y":1260,"wires":[["89de8eca.023bb"]]}]

Can easily be integrated with websocket or MQTT

I will try your flow and let you know my results soon.

Thanks to ghayne's input I fine tuned my flow and added MQTT and websocket connection demo.
Have fun with it :slight_smile:

[{"id":"57da71a5.519be","type":"tab","label":"I2C","disabled":false,"info":""},{"id":"a0db703.98f6b9","type":"i2c scan","z":"57da71a5.519be","name":"I2C scan","x":280,"y":120,"wires":[["73b294be.cc89ec"],["22b9fd8c.88e152"]]},{"id":"73b294be.cc89ec","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":100,"wires":[]},{"id":"22b9fd8c.88e152","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":140,"wires":[]},{"id":"c80b3a64.ef9f68","type":"inject","z":"57da71a5.519be","name":"I2C","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":120,"wires":[["a0db703.98f6b9"]]},{"id":"c8d32b33.1066a8","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":300,"wires":[["d9405581.7230e8"]]},{"id":"c7c67536.cc0d98","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"0","payloadType":"num","count":"1","x":320,"y":260,"wires":[]},{"id":"aa1d6209.04a5c","type":"inject","z":"57da71a5.519be","name":"all r on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":260,"wires":[["c7c67536.cc0d98","130d917e.ff055f"]]},{"id":"130d917e.ff055f","type":"delay","z":"57da71a5.519be","name":"100 ms","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":300,"wires":[["c8d32b33.1066a8"]]},{"id":"7f2eb4d3.4a86dc","type":"inject","z":"57da71a5.519be","name":"device status check","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":690,"y":120,"wires":[["4b7766b7.4dfe88"]]},{"id":"4b7766b7.4dfe88","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":870,"y":120,"wires":[["28b96e3c.e9bd02"]]},{"id":"c9b53692.3a60d8","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1170,"y":100,"wires":[]},{"id":"28b96e3c.e9bd02","type":"function","z":"57da71a5.519be","name":"","func":"return [{payload : msg.payload},\n        {payload : msg.payload.toString(2).padStart(4,'0')}\n       ];","outputs":2,"noerr":0,"x":1010,"y":120,"wires":[["c9b53692.3a60d8"],["932d9fe8.031dd"]]},{"id":"932d9fe8.031dd","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1170,"y":140,"wires":[]},{"id":"641c1ba9.c785d4","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":710,"y":900,"wires":[["ccdad9d2.3d9a98"]]},{"id":"44be667e.060e68","type":"inject","z":"57da71a5.519be","name":"toggle r1","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":500,"wires":[["2459c14d.a2c3ce"]]},{"id":"70c2b9e2.824c28","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":630,"y":560,"wires":[["245a9c21.285894"]]},{"id":"245a9c21.285894","type":"function","z":"57da71a5.519be","name":"","func":"return{payload:msg.payload^msg.relay};","outputs":1,"noerr":0,"x":750,"y":560,"wires":[["b72763c7.c7b12"]]},{"id":"b72763c7.c7b12","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"payload","payloadType":"msg","count":"1","x":880,"y":560,"wires":[]},{"id":"2459c14d.a2c3ce","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"1","tot":"num"},{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":500,"wires":[["81b483b4.e9eaa"]]},{"id":"86fe7eae.59976","type":"inject","z":"57da71a5.519be","name":"toggle r2","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":540,"wires":[["68140e94.fd806"]]},{"id":"68140e94.fd806","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"2","tot":"num"},{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":540,"wires":[["81b483b4.e9eaa"]]},{"id":"187a93ee.08aedc","type":"inject","z":"57da71a5.519be","name":"toggle r3","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":580,"wires":[["aa757bb4.8d4878"]]},{"id":"aa757bb4.8d4878","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"3","tot":"num"},{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":580,"wires":[["81b483b4.e9eaa"]]},{"id":"1ac58952.79aab7","type":"inject","z":"57da71a5.519be","name":"toggle r4","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":620,"wires":[["7c085399.f5e9ec"]]},{"id":"7c085399.f5e9ec","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"set","p":"relay","pt":"msg","to":"4","tot":"num"},{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":620,"wires":[["81b483b4.e9eaa"]]},{"id":"47583018.67892","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":760,"wires":[["8e1b10c7.d7ee1"]]},{"id":"4b25d308.b98fac","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"4","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1000,"wires":[["8e1b10c7.d7ee1"]]},{"id":"77d5b4d5.25d71c","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"3","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":920,"wires":[["8e1b10c7.d7ee1"]]},{"id":"d21e2dde.0a8a9","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":840,"wires":[["8e1b10c7.d7ee1"]]},{"id":"960e3a67.f5d538","type":"inject","z":"57da71a5.519be","name":"switch r1 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":760,"wires":[["47583018.67892"]]},{"id":"cb732c72.1c852","type":"inject","z":"57da71a5.519be","name":"switch r2 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":840,"wires":[["d21e2dde.0a8a9"]]},{"id":"3f9755c1.39bfaa","type":"inject","z":"57da71a5.519be","name":"switch r3 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":920,"wires":[["77d5b4d5.25d71c"]]},{"id":"17c78dc7.2f5482","type":"inject","z":"57da71a5.519be","name":"switch r4 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1000,"wires":[["4b25d308.b98fac"]]},{"id":"c6fbc1d5.0c648","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":800,"wires":[["8e1b10c7.d7ee1"]]},{"id":"4f85deba.616a7","type":"inject","z":"57da71a5.519be","name":"switch r1 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":800,"wires":[["c6fbc1d5.0c648"]]},{"id":"57251349.0c76ec","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":880,"wires":[["8e1b10c7.d7ee1"]]},{"id":"2aaca5ac.8a173a","type":"inject","z":"57da71a5.519be","name":"switch r2 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":880,"wires":[["57251349.0c76ec"]]},{"id":"5e6ac02c.b5372","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"3","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":960,"wires":[["8e1b10c7.d7ee1"]]},{"id":"c69dd00d.1097","type":"inject","z":"57da71a5.519be","name":"switch r3 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":960,"wires":[["5e6ac02c.b5372"]]},{"id":"fc5eed6b.9baea","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"4","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1040,"wires":[["8e1b10c7.d7ee1"]]},{"id":"9a34a124.52787","type":"inject","z":"57da71a5.519be","name":"switch r4 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1040,"wires":[["fc5eed6b.9baea"]]},{"id":"89de8eca.023bb","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"payload","payloadType":"msg","count":"1","x":960,"y":900,"wires":[]},{"id":"83b87ebc.429","type":"comment","z":"57da71a5.519be","name":"switch on or off; with bit masking, no impact on other relays,  if relay already on or off do nothing","info":"","x":360,"y":700,"wires":[]},{"id":"78b139e2.f909a8","type":"comment","z":"57da71a5.519be","name":"switch all 4 relays on or off","info":"","x":150,"y":200,"wires":[]},{"id":"1f5e76b2.fb5cb9","type":"comment","z":"57da71a5.519be","name":"Toggles relay on and of","info":"","x":140,"y":440,"wires":[]},{"id":"22a8b580.1c9aba","type":"mqtt out","z":"57da71a5.519be","name":"","topic":"relay_shield","qos":"0","retain":"","broker":"ae5e8621.14af98","x":650,"y":1140,"wires":[]},{"id":"ca05163f.ccc348","type":"inject","z":"57da71a5.519be","name":"switch r1 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1120,"wires":[["7c1cd4e1.70617c"]]},{"id":"9596ed95.4de5c","type":"mqtt in","z":"57da71a5.519be","name":"","topic":"relay_shield/#","qos":"0","datatype":"auto","broker":"ae5e8621.14af98","x":890,"y":1140,"wires":[["c59eed13.6ef25"]]},{"id":"81b483b4.e9eaa","type":"function","z":"57da71a5.519be","name":"","func":"return{relay:(1 << (msg.relay-1))};","outputs":1,"noerr":0,"x":510,"y":560,"wires":[["70c2b9e2.824c28"]]},{"id":"8ce96375.8d598","type":"inject","z":"57da71a5.519be","name":"switch r1 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1160,"wires":[["78c44824.98eb28"]]},{"id":"c5bdf61e.64d9a8","type":"websocket in","z":"57da71a5.519be","name":"","server":"67c95b04.5d27a4","client":"","x":910,"y":1240,"wires":[["c59eed13.6ef25"]]},{"id":"163abc81.8cf893","type":"websocket out","z":"57da71a5.519be","name":"","server":"","client":"aa148930.c68918","x":700,"y":1240,"wires":[]},{"id":"81f7da08.b5c0d8","type":"inject","z":"57da71a5.519be","name":"switch r1 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1220,"wires":[["2fefe0a1.ae176"]]},{"id":"702388a8.da5e48","type":"inject","z":"57da71a5.519be","name":"switch r1 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1260,"wires":[["670caf0c.7466c"]]},{"id":"3bb32304.45b28c","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"1","payloadType":"num","count":"1","x":320,"y":1480,"wires":[]},{"id":"34766a3f.a957b6","type":"inject","z":"57da71a5.519be","name":"r1 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1480,"wires":[["3bb32304.45b28c","53dc4d1.cdfdfb4"]]},{"id":"7d8e22e5.194a3c","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"2","payloadType":"num","count":"1","x":320,"y":1640,"wires":[]},{"id":"c8f3ad02.4e8ec","type":"inject","z":"57da71a5.519be","name":"r2 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1640,"wires":[["7d8e22e5.194a3c","4576da2e.7b9494"]]},{"id":"1c2b5753.90d919","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"4","payloadType":"num","count":"1","x":320,"y":1800,"wires":[]},{"id":"42fe372d.0a4fe8","type":"inject","z":"57da71a5.519be","name":"r3 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1800,"wires":[["1c2b5753.90d919","3392a3d0.233dbc"]]},{"id":"a6c2adf0.89033","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"8","payloadType":"num","count":"1","x":320,"y":1880,"wires":[]},{"id":"cb96c25f.88bea","type":"inject","z":"57da71a5.519be","name":"r4 off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1880,"wires":[["a6c2adf0.89033","f0c57ee7.87366"]]},{"id":"53dc4d1.cdfdfb4","type":"delay","z":"57da71a5.519be","name":"100 ms","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":1520,"wires":[["a8cd98cd.252488"]]},{"id":"a8cd98cd.252488","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":1520,"wires":[["c40b4bbe.5a34e8"]]},{"id":"4576da2e.7b9494","type":"delay","z":"57da71a5.519be","name":"100 ms","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":1680,"wires":[["ddf670c7.d8401"]]},{"id":"ddf670c7.d8401","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":1680,"wires":[["c40b4bbe.5a34e8"]]},{"id":"3392a3d0.233dbc","type":"delay","z":"57da71a5.519be","name":"100 ms","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":1840,"wires":[["d79c57db.aad3c8"]]},{"id":"d79c57db.aad3c8","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":1840,"wires":[["c40b4bbe.5a34e8"]]},{"id":"f0c57ee7.87366","type":"delay","z":"57da71a5.519be","name":"100 ms","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":1920,"wires":[["eec51295.d6916"]]},{"id":"eec51295.d6916","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":1920,"wires":[["c40b4bbe.5a34e8"]]},{"id":"305f67c.4876298","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"14","payloadType":"num","count":"1","x":320,"y":1400,"wires":[]},{"id":"1b2ea991.81b8d6","type":"inject","z":"57da71a5.519be","name":"r1 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1400,"wires":[["305f67c.4876298","f3415c83.c831e"]]},{"id":"8325b536.9aa7d8","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"13","payloadType":"num","count":"1","x":320,"y":1560,"wires":[]},{"id":"721693d4.c9700c","type":"inject","z":"57da71a5.519be","name":"r2 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1560,"wires":[["8325b536.9aa7d8","6640c9f2.f6b598"]]},{"id":"d2d4f047.fc875","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"11","payloadType":"num","count":"1","x":320,"y":1720,"wires":[]},{"id":"371e7130.81675e","type":"inject","z":"57da71a5.519be","name":"r3 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1720,"wires":[["d2d4f047.fc875","cb5483d.1cf378"]]},{"id":"4af4b15f.3191","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"7","payloadType":"num","count":"1","x":320,"y":1960,"wires":[]},{"id":"f8680d0b.0d7f2","type":"inject","z":"57da71a5.519be","name":"r4 on","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1960,"wires":[["4af4b15f.3191","d4210a42.8cf998"]]},{"id":"f3415c83.c831e","type":"delay","z":"57da71a5.519be","name":"100 ms","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":1440,"wires":[["d63e7dba.5814b"]]},{"id":"d63e7dba.5814b","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":1440,"wires":[["c40b4bbe.5a34e8"]]},{"id":"6640c9f2.f6b598","type":"delay","z":"57da71a5.519be","name":"100 ms","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":1600,"wires":[["b50a6134.7f74b"]]},{"id":"b50a6134.7f74b","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":1600,"wires":[["c40b4bbe.5a34e8"]]},{"id":"cb5483d.1cf378","type":"delay","z":"57da71a5.519be","name":"100 ms","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":1760,"wires":[["a774f87f.661e28"]]},{"id":"a774f87f.661e28","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":1760,"wires":[["c40b4bbe.5a34e8"]]},{"id":"d4210a42.8cf998","type":"delay","z":"57da71a5.519be","name":"100 ms","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":2000,"wires":[["2426a945.a1a516"]]},{"id":"2426a945.a1a516","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":2000,"wires":[["c40b4bbe.5a34e8"]]},{"id":"54e5ea86.7df4a4","type":"comment","z":"57da71a5.519be","name":"simple switch, no bit masking, impacts other relays","info":"","x":230,"y":1340,"wires":[]},{"id":"d099268e.ffdfc8","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":810,"y":1700,"wires":[]},{"id":"c40b4bbe.5a34e8","type":"function","z":"57da71a5.519be","name":"","func":"return [{payload : msg.payload},\n        {payload : msg.payload.toString(2).padStart(4,'0')}\n       ];","outputs":2,"noerr":0,"x":650,"y":1720,"wires":[["d099268e.ffdfc8"],["24cd8061.9b00d"]]},{"id":"24cd8061.9b00d","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":810,"y":1740,"wires":[]},{"id":"3d2861bc.a08bae","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":320,"wires":[]},{"id":"d9405581.7230e8","type":"function","z":"57da71a5.519be","name":"","func":"return [{payload : msg.payload},\n        {payload : msg.payload.toString(2).padStart(4,'0')}\n       ];","outputs":2,"noerr":0,"x":590,"y":340,"wires":[["3d2861bc.a08bae"],["e8f42019.4fd82"]]},{"id":"e8f42019.4fd82","type":"debug","z":"57da71a5.519be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":360,"wires":[]},{"id":"c03ea9e3.554a88","type":"i2c in","z":"57da71a5.519be","name":"","address":"32","command":"6","count":"1","x":450,"y":380,"wires":[["d9405581.7230e8"]]},{"id":"d19281f2.dea63","type":"i2c out","z":"57da71a5.519be","name":"","address":"32","command":"6","payload":"15","payloadType":"num","count":"1","x":320,"y":340,"wires":[]},{"id":"6e1a54ff.fecdbc","type":"inject","z":"57da71a5.519be","name":"all r off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":340,"wires":[["d19281f2.dea63","f2249c9b.6607f"]]},{"id":"f2249c9b.6607f","type":"delay","z":"57da71a5.519be","name":"100 ms","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":380,"wires":[["c03ea9e3.554a88"]]},{"id":"cfabdeb6.8f0d","type":"comment","z":"57da71a5.519be","name":"Utilities","info":"","x":90,"y":40,"wires":[]},{"id":"381aabc1.252884","type":"comment","z":"57da71a5.519be","name":"MQTT","info":"","x":1070,"y":1140,"wires":[]},{"id":"9f6ce1af.3947e","type":"comment","z":"57da71a5.519be","name":"Websocket","info":"","x":1080,"y":1240,"wires":[]},{"id":"8e1b10c7.d7ee1","type":"function","z":"57da71a5.519be","name":"","func":"return{relay:(1 << (msg.relay-1)),value:msg.value};","outputs":1,"noerr":0,"x":590,"y":900,"wires":[["641c1ba9.c785d4"]]},{"id":"ccdad9d2.3d9a98","type":"function","z":"57da71a5.519be","name":"","func":"switch(msg.value){\n    case 1:\n        return{payload:(msg.payload &= ~msg.relay)};\n    case 0:\n        return{payload:(msg.payload |= msg.relay)};\n} \n\n","outputs":1,"noerr":0,"x":830,"y":900,"wires":[["89de8eca.023bb"]]},{"id":"2e4d2c10.b31fc4","type":"function","z":"57da71a5.519be","name":"obj to string","func":"var obj = JSON.parse(JSON.stringify(msg));\nreturn {payload : JSON.stringify(obj)};\n\n","outputs":1,"noerr":0,"x":490,"y":1140,"wires":[["22a8b580.1c9aba"]]},{"id":"c59eed13.6ef25","type":"function","z":"57da71a5.519be","name":"string to obj","func":"return JSON.parse(msg.payload);","outputs":1,"noerr":0,"x":1110,"y":1180,"wires":[["8e1b10c7.d7ee1"]]},{"id":"7c1cd4e1.70617c","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1120,"wires":[["2e4d2c10.b31fc4"]]},{"id":"78c44824.98eb28","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1160,"wires":[["2e4d2c10.b31fc4"]]},{"id":"cd0e876c.64c948","type":"function","z":"57da71a5.519be","name":"obj to string","func":"var obj = JSON.parse(JSON.stringify(msg));\nreturn {payload : JSON.stringify(obj)};\n\n","outputs":1,"noerr":0,"x":490,"y":1240,"wires":[["163abc81.8cf893"]]},{"id":"2fefe0a1.ae176","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1220,"wires":[["cd0e876c.64c948"]]},{"id":"670caf0c.7466c","type":"change","z":"57da71a5.519be","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"relay","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"value","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1260,"wires":[["cd0e876c.64c948"]]},{"id":"ae5e8621.14af98","type":"mqtt-broker","z":"","name":"10.0.0.43","broker":"10.0.0.43","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"67c95b04.5d27a4","type":"websocket-listener","z":"","path":"/ws","wholemsg":"false"},{"id":"aa148930.c68918","type":"websocket-client","z":"","path":"ws://localhost:1880/ws","tls":"","wholemsg":"false"}]
2 Likes