Triggering i2c relays via node red

Was wondering if anyone has managed to use the "https://flows.nodered.org/node/node-red-contrib-i2c" to trigger the relays on a board like this one

I used the scan node and it detected it but i am unable to find out how to trigger the relay on it.
I was wanting to eventually be able to control those relays with buttons on a dashboard.

TIA

Is there some more info available for the board?
Datasheet with protocol description maybe or example code in other prog language.

I have a flow that uses a PCF8574 IO expansion module to drive a bank of 8 relays. It should give you an idea of how to do it. You don't have to use the PCF8574 IO board, just drive the relays via GPIO pin on the device of course.

[{"id":"6ad99e0f.f50c98","type":"tab","label":"Relay Control (PCF8574) 3.0.10","disabled":false,"info":""},{"id":"ba182acf.6e5e68","type":"comment","z":"6ad99e0f.f50c98","name":"Ensure Global Function (Settings.js) Includes i2c:require('i2c-bus')","info":"https://tech.scargill.net/i2c-for-everyone/","x":260,"y":40,"wires":[]},{"id":"ca3f518d.ad4ba","type":"inject","z":"6ad99e0f.f50c98","name":"Automatic","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":120,"wires":[["a469f45b.3410c"]]},{"id":"e834e369.2435f8","type":"i2c scan","z":"6ad99e0f.f50c98","name":"Scan","busno":"1","x":410,"y":120,"wires":[[],["644aa2c8.4d4afc"]]},{"id":"644aa2c8.4d4afc","type":"switch","z":"6ad99e0f.f50c98","name":"PCF8574 (Address 0x38 | 56) Exist?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"56","vt":"num"}],"checkall":"false","repair":false,"outputs":1,"x":650,"y":120,"wires":[["b5971f25.33356"]]},{"id":"368d9b68.5b02fc","type":"function","z":"6ad99e0f.f50c98","name":"Write PCF8574","func":"const i2c = global.get('i2c');\n\nconst PERSISTENT = 'persistent';\n\nconst theAddress = flow.get('pcf8574.address', PERSISTENT);\nconst theBus = flow.get('pcf8574.bus', PERSISTENT);\n\nvar theDevice = i2c.openSync(theBus);\ntheDevice.sendByteSync(theAddress, msg.payload);\ntheDevice.closeSync();\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":300,"wires":[["fbc73239.c287a8"]]},{"id":"3962fbc3.5697f4","type":"function","z":"6ad99e0f.f50c98","name":"Read PCF8574","func":"const i2c = global.get('i2c');\n\nconst PERSISTENT = 'persistent';\n\nconst theAddress = flow.get('pcf8574.address', PERSISTENT);\nconst theBus = flow.get('pcf8574.bus', PERSISTENT);\n\nvar theDevice = i2c.openSync(theBus);\nvar theRegister = theDevice.receiveByteSync(theAddress);\ntheDevice.closeSync();\n\nflow.set('pcf8574.register', theRegister, PERSISTENT);\n\nmsg.payload = theRegister;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":180,"wires":[["fbdb8524.b4395"]]},{"id":"b5971f25.33356","type":"change","z":"6ad99e0f.f50c98","name":"Set","rules":[{"t":"set","p":"#:(persistent)::pcf8574.exist","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":120,"wires":[[]]},{"id":"5627f683.7f8fd8","type":"inject","z":"6ad99e0f.f50c98","name":"Register?","props":[{"p":"payload"},{"p":"device","v":"0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":180,"wires":[["d1046b21.c473e8"]]},{"id":"c95e80c4.19039","type":"inject","z":"6ad99e0f.f50c98","name":"Toggle 0","props":[{"p":"channel","v":"0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":100,"y":380,"wires":[["46aa98b6.0ec6e8"]]},{"id":"d1046b21.c473e8","type":"switch","z":"6ad99e0f.f50c98","name":"Exist?","property":"#:(persistent)::pcf8574.exist","propertyType":"flow","rules":[{"t":"true"}],"checkall":"false","repair":false,"outputs":1,"x":250,"y":180,"wires":[["3962fbc3.5697f4"]]},{"id":"90467c4b.254468","type":"switch","z":"6ad99e0f.f50c98","name":"Exist?","property":"#:(persistent)::pcf8574.exist","propertyType":"flow","rules":[{"t":"true"}],"checkall":"false","repair":false,"outputs":1,"x":510,"y":300,"wires":[["368d9b68.5b02fc"]]},{"id":"4e83c681.dee158","type":"mqtt in","z":"6ad99e0f.f50c98","name":"Broker (/+/relay/pcf8574/control)","topic":"/+/relay/pcf8574/control","qos":"2","datatype":"auto","broker":"980ba0d2.c5dee","x":150,"y":760,"wires":[["d1249cb.739c56"]]},{"id":"b694b66f.f3f5f","type":"function","z":"6ad99e0f.f50c98","name":"Register","func":"const PERSISTENT = 'persistent';\n\nconst MASK = 1 << msg.topic;\n\nmsg.payload = Number(!msg.payload);\nflow.set(`pcf8574.${msg.topic}`, msg.payload, PERSISTENT);\n\nvar theRegister = flow.get('pcf8574.register', PERSISTENT);\n\nif (msg.payload) {\n    theRegister |= MASK;\n} else {\n    theRegister &= ~MASK;\n}\n\nflow.set('pcf8574.register', theRegister, PERSISTENT);\nmsg.payload = theRegister;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":300,"wires":[["90467c4b.254468"]]},{"id":"fbdb8524.b4395","type":"debug","z":"6ad99e0f.f50c98","name":"Message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":180,"wires":[]},{"id":"fbc73239.c287a8","type":"debug","z":"6ad99e0f.f50c98","name":"Message","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":860,"y":300,"wires":[]},{"id":"13237ed1.43c8d9","type":"ui_button","z":"6ad99e0f.f50c98","name":"Channel 0","group":"1eb8eebd.581109","order":9,"width":1,"height":1,"passthru":true,"label":"P0","tooltip":"","color":"","bgcolor":"","icon":"","payload":"#:(persistent)::pcf8574.0","payloadType":"flow","topic":"0","x":590,"y":380,"wires":[["e33eaeb3.6415f"]]},{"id":"cf707cc2.b45e3","type":"link in","z":"6ad99e0f.f50c98","name":"","links":["62d1f85f.1d3eb","14078f87.14b5a8","ac4b389e.892358","cd520271.bfa5e8","e8e5851d.fed4f","32ec9dcc.506ec2","598ccd80.78a9b4","f3e2b433.99481","2675cc55.07f404","bfb08edf.4e8c5","b113d389.29d92","861fdffb.fe204","8d630f75.50ce3","62a9c8d4.4791b8","af9eda80.f936d8","f281207f.7a281","e33eaeb3.6415f"],"x":35,"y":300,"wires":[["323a310f.35853e"]]},{"id":"e956aaba.15609","type":"ui_button","z":"6ad99e0f.f50c98","name":"Channel 1 ","group":"1eb8eebd.581109","order":10,"width":1,"height":1,"passthru":true,"label":"P1","tooltip":"","color":"","bgcolor":"","icon":"","payload":"#:(persistent)::pcf8574.1","payloadType":"flow","topic":"1","x":590,"y":420,"wires":[["e33eaeb3.6415f"]]},{"id":"85128cf3.f44c18","type":"ui_button","z":"6ad99e0f.f50c98","name":"Channel 2","group":"1eb8eebd.581109","order":11,"width":1,"height":1,"passthru":true,"label":"P2","tooltip":"","color":"","bgcolor":"","icon":"","payload":"#:(persistent)::pcf8574.2","payloadType":"flow","topic":"2","x":590,"y":460,"wires":[["e33eaeb3.6415f"]]},{"id":"a9b9159e.069de","type":"ui_button","z":"6ad99e0f.f50c98","name":"Channel 3","group":"1eb8eebd.581109","order":12,"width":1,"height":1,"passthru":true,"label":"P3","tooltip":"","color":"","bgcolor":"","icon":"","payload":"#:(persistent)::pcf8574.3","payloadType":"flow","topic":"3","x":590,"y":500,"wires":[["e33eaeb3.6415f"]]},{"id":"f1bc8033.2ad468","type":"ui_button","z":"6ad99e0f.f50c98","name":"Channel 4","group":"1eb8eebd.581109","order":13,"width":1,"height":1,"passthru":true,"label":"P4","tooltip":"","color":"","bgcolor":"","icon":"","payload":"#:(persistent)::pcf8574.4","payloadType":"flow","topic":"4","x":590,"y":540,"wires":[["e33eaeb3.6415f"]]},{"id":"8d8a9213.dadd38","type":"ui_button","z":"6ad99e0f.f50c98","name":"Channel 5","group":"1eb8eebd.581109","order":14,"width":1,"height":1,"passthru":true,"label":"P5","tooltip":"","color":"","bgcolor":"","icon":"","payload":"#:(persistent)::pcf8574.5","payloadType":"flow","topic":"5","x":590,"y":580,"wires":[["e33eaeb3.6415f"]]},{"id":"add41056.8b0c18","type":"ui_button","z":"6ad99e0f.f50c98","name":"Channel 6","group":"1eb8eebd.581109","order":15,"width":1,"height":1,"passthru":true,"label":"P6","tooltip":"","color":"","bgcolor":"","icon":"","payload":"#:(persistent)::pcf8574.6","payloadType":"flow","topic":"6","x":590,"y":620,"wires":[["e33eaeb3.6415f"]]},{"id":"c6704d0.3f5d53","type":"ui_button","z":"6ad99e0f.f50c98","name":"Channel 7","group":"1eb8eebd.581109","order":16,"width":1,"height":1,"passthru":true,"label":"P7","tooltip":"","color":"","bgcolor":"","icon":"","payload":"#:(persistent)::pcf8574.7","payloadType":"flow","topic":"7","x":590,"y":660,"wires":[["e33eaeb3.6415f"]]},{"id":"a469f45b.3410c","type":"change","z":"6ad99e0f.f50c98","name":"Set","rules":[{"t":"set","p":"#:(persistent)::pcf8574.address","pt":"flow","to":"56","tot":"num"},{"t":"set","p":"#:(persistent)::pcf8574.bus","pt":"flow","to":"1","tot":"num"},{"t":"set","p":"#:(persistent)::pcf8574.register","pt":"flow","to":"255","tot":"num"},{"t":"set","p":"#:(persistent)::pcf8574.exist","pt":"flow","to":"false","tot":"bool"},{"t":"set","p":"#:(persistent)::pcf8574.0","pt":"flow","to":"1","tot":"num"},{"t":"set","p":"#:(persistent)::pcf8574.1","pt":"flow","to":"1","tot":"num"},{"t":"set","p":"#:(persistent)::pcf8574.2","pt":"flow","to":"1","tot":"num"},{"t":"set","p":"#:(persistent)::pcf8574.3","pt":"flow","to":"1","tot":"num"},{"t":"set","p":"#:(persistent)::pcf8574.4","pt":"flow","to":"1","tot":"num"},{"t":"set","p":"#:(persistent)::pcf8574.5","pt":"flow","to":"1","tot":"num"},{"t":"set","p":"#:(persistent)::pcf8574.6","pt":"flow","to":"1","tot":"num"},{"t":"set","p":"#:(persistent)::pcf8574.7","pt":"flow","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":120,"wires":[["e834e369.2435f8"]]},{"id":"c6234c6c.1231b","type":"comment","z":"6ad99e0f.f50c98","name":"Relay? Low Trigger 0 = Open, 1 = Close, Default Register = 255","info":"","x":250,"y":260,"wires":[]},{"id":"449367a5.5e5838","type":"ui_led","z":"6ad99e0f.f50c98","group":"1eb8eebd.581109","order":1,"width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"name":"Channel 0","x":1110,"y":380,"wires":[]},{"id":"f786dc16.7cc9d","type":"ui_led","z":"6ad99e0f.f50c98","group":"1eb8eebd.581109","order":2,"width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"name":"Channel 1","x":1110,"y":420,"wires":[]},{"id":"67229314.c5367c","type":"ui_led","z":"6ad99e0f.f50c98","group":"1eb8eebd.581109","order":3,"width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"name":"Channel 2","x":1110,"y":460,"wires":[]},{"id":"5cb60398.c7539c","type":"ui_led","z":"6ad99e0f.f50c98","group":"1eb8eebd.581109","order":4,"width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"name":"Channel 3","x":1110,"y":500,"wires":[]},{"id":"a97fb126.2cf93","type":"ui_led","z":"6ad99e0f.f50c98","group":"1eb8eebd.581109","order":5,"width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"name":"Channel 4","x":1110,"y":540,"wires":[]},{"id":"7cf40860.9f9638","type":"ui_led","z":"6ad99e0f.f50c98","group":"1eb8eebd.581109","order":6,"width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"name":"Channel 5","x":1110,"y":580,"wires":[]},{"id":"3b72b144.caec8e","type":"ui_led","z":"6ad99e0f.f50c98","group":"1eb8eebd.581109","order":7,"width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"name":"Channel 6","x":1110,"y":620,"wires":[]},{"id":"57501c22.55bd74","type":"ui_led","z":"6ad99e0f.f50c98","group":"1eb8eebd.581109","order":8,"width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"name":"Channel 7","x":1110,"y":660,"wires":[]},{"id":"1a366223.e0065e","type":"inject","z":"6ad99e0f.f50c98","name":"Toggle 1","props":[{"p":"channel","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":100,"y":420,"wires":[["46aa98b6.0ec6e8"]]},{"id":"23b7248d.3f190c","type":"inject","z":"6ad99e0f.f50c98","name":"Toggle 2","props":[{"p":"channel","v":"2","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":100,"y":460,"wires":[["46aa98b6.0ec6e8"]]},{"id":"a5edd139.3328e","type":"inject","z":"6ad99e0f.f50c98","name":"Toggle 3","props":[{"p":"channel","v":"3","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":100,"y":500,"wires":[["46aa98b6.0ec6e8"]]},{"id":"691afb65.5f6d14","type":"inject","z":"6ad99e0f.f50c98","name":"Toggle 4","props":[{"p":"channel","v":"4","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":100,"y":540,"wires":[["46aa98b6.0ec6e8"]]},{"id":"de908f92.54692","type":"inject","z":"6ad99e0f.f50c98","name":"Toggle 5","props":[{"p":"channel","v":"5","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":100,"y":580,"wires":[["46aa98b6.0ec6e8"]]},{"id":"2fe00731.a47058","type":"inject","z":"6ad99e0f.f50c98","name":"Toggle 6","props":[{"p":"channel","v":"6","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":100,"y":620,"wires":[["46aa98b6.0ec6e8"]]},{"id":"d0bf2043.cee18","type":"inject","z":"6ad99e0f.f50c98","name":"Toggle 7","props":[{"p":"channel","v":"7","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":100,"y":660,"wires":[["46aa98b6.0ec6e8"]]},{"id":"7dee44d8.f81a2c","type":"switch","z":"6ad99e0f.f50c98","name":"Channel?","property":"channel","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"},{"t":"eq","v":"5","vt":"num"},{"t":"eq","v":"6","vt":"num"},{"t":"eq","v":"7","vt":"num"}],"checkall":"false","repair":false,"outputs":8,"x":420,"y":520,"wires":[["13237ed1.43c8d9"],["e956aaba.15609"],["85128cf3.f44c18"],["a9b9159e.069de"],["f1bc8033.2ad468"],["8d8a9213.dadd38"],["add41056.8b0c18"],["c6704d0.3f5d53"]]},{"id":"6b46403d.ccc85","type":"switch","z":"6ad99e0f.f50c98","name":"Channel?","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"},{"t":"eq","v":"5","vt":"num"},{"t":"eq","v":"6","vt":"num"},{"t":"eq","v":"7","vt":"num"}],"checkall":"false","repair":false,"outputs":8,"x":940,"y":520,"wires":[["449367a5.5e5838"],["f786dc16.7cc9d"],["67229314.c5367c"],["5cb60398.c7539c"],["a97fb126.2cf93"],["7cf40860.9f9638"],["3b72b144.caec8e"],["57501c22.55bd74"]]},{"id":"531f96e3.8f8fe8","type":"link in","z":"6ad99e0f.f50c98","name":"","links":["e33eaeb3.6415f"],"x":815,"y":520,"wires":[["6b46403d.ccc85"]]},{"id":"e33eaeb3.6415f","type":"link out","z":"6ad99e0f.f50c98","name":"","links":["cf707cc2.b45e3","531f96e3.8f8fe8"],"x":735,"y":520,"wires":[]},{"id":"323a310f.35853e","type":"delay","z":"6ad99e0f.f50c98","name":"Topic (250/ms)","pauseType":"delay","timeout":"250","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"250","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":180,"y":300,"wires":[["b694b66f.f3f5f"]]},{"id":"fa7f6c93.563fc","type":"link in","z":"6ad99e0f.f50c98","name":"","links":["46aa98b6.0ec6e8","4e01f125.903fa","ee8fc7b0.bce718"],"x":295,"y":520,"wires":[["7dee44d8.f81a2c"]]},{"id":"46aa98b6.0ec6e8","type":"link out","z":"6ad99e0f.f50c98","name":"","links":["fa7f6c93.563fc"],"x":215,"y":520,"wires":[]},{"id":"d1249cb.739c56","type":"json","z":"6ad99e0f.f50c98","name":"Channel And State","property":"payload","action":"obj","pretty":false,"x":410,"y":760,"wires":[["39a69435.622f6c","7e5423b4.1d1dbc"]]},{"id":"ee8fc7b0.bce718","type":"link out","z":"6ad99e0f.f50c98","name":"","links":["fa7f6c93.563fc"],"x":775,"y":740,"wires":[]},{"id":"39a69435.622f6c","type":"debug","z":"6ad99e0f.f50c98","name":"Message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":780,"wires":[]},{"id":"7e5423b4.1d1dbc","type":"change","z":"6ad99e0f.f50c98","name":"Channel And State","rules":[{"t":"set","p":"channel","pt":"msg","to":"payload.channel","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":740,"wires":[["ee8fc7b0.bce718"]]},{"id":"3880604c.607a1","type":"comment","z":"6ad99e0f.f50c98","name":"Need Method To Specific Set State Not Just Toggle","info":"","x":730,"y":820,"wires":[]},{"id":"980ba0d2.c5dee","type":"mqtt-broker","z":"","name":"Broker","broker":"broker.dachshund-digital.org","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"1eb8eebd.581109","type":"ui_group","z":"","name":"Relay Control (PCF8574) 3.0.5","tab":"354d78f.3809288","order":3,"disp":true,"width":"8","collapse":true},{"id":"354d78f.3809288","type":"ui_tab","z":"","name":"Control","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

My PCF8574 IO board is i2c bus controlled as well by the way. I use this flow as a foundation for several projects, a garage door controller, sprinkler controller, etc.

The ui-led module is optional, I used it to display the state of the relays, or you can just query the 'register' state, sample of how to get the register date of the PCF8574 IC in within the flow above.

Looking at the Wiki for this board, it is a direct read and write i2c device, just like the PCF8574 is. The control method is almost identical. You just need to pass (write) to the right address, the correct number of bytes, the right byte values, in the right order to drive the relay state(s).

I am in the same boat, just registered to follow this particular discussion.

Have the same board, I can manually trigger the relays via i2set commands on the rpi console, but cannot seem to figure out the way to make Node-Red trigger with a button/timer and setup the flows.

command on RPI cmd line: i2set -y 1 0x10 0x01 0x00/0xFF

I imported the above provided flow, and was pretty much lost immediately :frowning: appreciate any guidance or direction, if I can make a single node, send the above command, I'd be more than happy to build the rest of the flows as that can be quite straight forward.

Link to the board wiki: https://wiki.52pi.com/index.php/DockerPi_4_Channel_Relay_SKU:_EP-0099

Ok, lets take this one step at a time. My flow does 3 things.

  1. It determines if I have a PCF8574 board present on the i2c bus. If so, it sets a flow variable to true. Other flows use this to determine if they can do their respective task(s).
  1. The register flow captures the state of the PCF8574 register, think of this as the state of the board at the time something changes. The PCF8574 has no on-board memory of what each GPIO pin is set to, for output on or off for example. So my flows assume all pins are at a high state, i.e. OFF. As I turn a pin ON, I update the register variable (bit mask) to reflect each change. This is typically how you track the state of the pins on a PCF85* IC controlled interface.

  2. Last, I have a flow that turns the GPIO pins on the PCF8574 board ON or OFF. Hence the relay connected to each pin is OPENED or CLOSED. My relay board closes a relay on LOW or 0, and opens on HIGH or 1. This works well with the PCF8574 board since it follows the same logic, initial state HIGH, 1 or OFF, and enabled state, i.e. LOW, 0, ON... or close the relay.

So I suggest you look at the first flow, and see that it scans the i2C bus, looks for the address present for the PCF8574 board, decimal 56, as I recall.

As for the register value, 255 sets all the GPIO pins to HIGH, as you flip a bit to ON or 0 the register value changes for the bit that is changed, so 255 to 254 means you flip the 7th bit (0 to 7) or P0 to P7, to 0. It is a bit tricky to understand how the register maps to the PCF8574 pins. Basically it is...

P0 to P1 (P=pin), and register value 0 to 255. 0 means P0 to P7 are ALL on. And 255 means P0 to P7 are ALL off.

You will do the same basic thing with your device, or you should, track the state of the relays, if the device does not remember it for you some how. A quick read of the wiki, I did not see any apparent state information, so you may want to do that your self. Just something that might be relevant to your project. I have a UI that shows the state of all the relays, so keeping the state makes it easy to keep the UI in sync with the actual relay state(s).

Gotcha, that gives me some good aides in understanding the flow I'm looking at. I'll dive in a bit and tinker some more.

Appreciate the break-down and time you've given!

Sure.... since could not find a working PCF8574 node for NR, I created what I shared. The more people that learn from it, the better, I say. If you have more questions just asked. I or others I am sure will help as needed. We will not give answers by default but will given examples that you can learn from. The ultimate goal is to get everyone to learn how all this 'stuff' works!

1 Like

Agreed... to be fair, I didn't catch that this was an I2C relay board, I had flows already pre-configured to manage a RPI GPIO controlled node-red setup. (I can still do this, but hey... learn something new!) I am officially in ~8hrs into the world of I2C.

I have older relay boards that are direct GPIO driven. The concept is similar that you may want to retain the 'state' of the relays, so you always know which is on and off. Direct driven is easier since no i2c interface, but you use a lot of GPIO pins of course. Once I got the i2c interface working... lot less effort in the long run, at least for me.

This flow is fantastic. Thanks for the insight, I did not know about the PCF8574 IO expansion module. This would be super helpful for me in the case of expansion !

@socialdeviat I just figured it out !

You're in luck. Its fairly simple tbh,

Here is my flow

[{"id":"c6535213.beea8","type":"switch","z":"686e77f4.058018","name":"Relay Triggered ON","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"AN1C1 ON","vt":"str"},{"t":"eq","v":"AN1C2 ON","vt":"str"},{"t":"eq","v":"AN1C3 ON","vt":"str"},{"t":"eq","v":"AN1C4 ON","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":580,"y":540,"wires":[["d5d52faa.4b035"],["50554cfb.e779b4"],["296ee592.36a8fa"],["cf0c9782.efee98"]]},{"id":"d5d52faa.4b035","type":"i2c out","z":"686e77f4.058018","name":"Relay 1 - ON ","busno":"1","address":"16","command":"255","payload":"[16,1,255]","payloadType":"bin","count":"3","x":830,"y":480,"wires":[["3c8e887d.2c5ac8"]]},{"id":"50554cfb.e779b4","type":"i2c out","z":"686e77f4.058018","name":"Relay 2 - ON ","busno":"1","address":"16","command":"255","payload":"[16,2,255]","payloadType":"bin","count":"3","x":830,"y":520,"wires":[[]]},{"id":"296ee592.36a8fa","type":"i2c out","z":"686e77f4.058018","name":"Relay 3 - ON ","busno":"1","address":"16","command":"255","payload":"[16,3,255]","payloadType":"bin","count":"3","x":830,"y":560,"wires":[[]]},{"id":"cf0c9782.efee98","type":"i2c out","z":"686e77f4.058018","name":"Relay 4 - ON ","busno":"1","address":"16","command":"255","payload":"[16,4,255]","payloadType":"bin","count":"3","x":830,"y":600,"wires":[[]]},{"id":"46fd8512.29a3dc","type":"switch","z":"686e77f4.058018","name":"Relay Triggered OFF","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"AN1C1 OFF","vt":"str"},{"t":"eq","v":"AN1C2 OFF","vt":"str"},{"t":"eq","v":"AN1C3 OFF","vt":"str"},{"t":"eq","v":"AN1C4 OFF","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":580,"y":760,"wires":[["b254d3f3.3d092"],["c425a917.bd83a8"],["a3ff75ab.786908"],["d688ff62.cd973"]]},{"id":"b254d3f3.3d092","type":"i2c out","z":"686e77f4.058018","name":"Relay 1 - OFF","busno":"1","address":"16","command":"255","payload":"[16,1,0]","payloadType":"bin","count":"3","x":840,"y":700,"wires":[["1b90e1a2.d76f6e"]]},{"id":"c425a917.bd83a8","type":"i2c out","z":"686e77f4.058018","name":"Relay 2 - OFF","busno":"1","address":"16","command":"255","payload":"[16,2,0]","payloadType":"bin","count":"3","x":840,"y":740,"wires":[[]]},{"id":"a3ff75ab.786908","type":"i2c out","z":"686e77f4.058018","name":"Relay 3 - OFF ","busno":"1","address":"16","command":"255","payload":"[16,3,0]","payloadType":"bin","count":"3","x":840,"y":780,"wires":[[]]},{"id":"d688ff62.cd973","type":"i2c out","z":"686e77f4.058018","name":"Relay 4 - OFF ","busno":"1","address":"16","command":"255","payload":"[16,4,0]","payloadType":"bin","count":"3","x":840,"y":820,"wires":[[]]},{"id":"8d35c507.1764a8","type":"rpi-gpio out","z":"686e77f4.058018","name":"","pin":"15","set":true,"level":"0","freq":"","out":"out","x":1240,"y":580,"wires":[]},{"id":"3c8e887d.2c5ac8","type":"change","z":"686e77f4.058018","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1020,"y":480,"wires":[["8d35c507.1764a8"]]},{"id":"1b90e1a2.d76f6e","type":"change","z":"686e77f4.058018","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1020,"y":700,"wires":[["8d35c507.1764a8"]]}]

So what I have done is RELAY Triggered ON & OFF nodes are just checking for incoming strings (Since these strings are coming from MQTT Clients). I then feed it to i2c out node where i send the payload of type buffer with [16, 1, 255] which basically means (0x10 0x01 0xFF), then a change node to make it HIGH and trigger an LED which is attached to a GPIO.

This way i have the relay triggered & LED glowing to show the state outside the relay board.

1 Like

Nice, really cool.

this is an seed i2c 4 relay board solution

@juntiedt If you want to know how to trigger the relays using python (if i understood you correctly)
Here is a snippet which will help you

import sys      # Used for I2C Relays
import smbus    # Used for I2C Relays

self.DEVICE_BUS = 1
self.DEVICE_ADDR = 0x10  # This could change depending on what the address switch is set to on the relay board
self.bus = smbus.SMBus(self.DEVICE_BUS)

self.bus.write_byte_data(self.DEVICE_ADDR, 1, 0xFF)  # 1 can be 2,3, or 4 depending on the relay you want to trigger on the board (relay ON)

self.bus.write_byte_data(self.DEVICE_ADDR, 1, 0x00) # relay OFF

Hope this helps
Your relay board is just manufactured by Seeed. But it will work exactly like my board !

lmk if it works though

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.