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.