const relays = [];
// loops through the 8 relays and creates a msg property
// object to send to the entity node to turn it on/off
for(let i = 0;i < 8;i++) {
relays[i] = {
// msg.payload.substr(i * 4, 4) same as you had original to parse out the string
// Number() converts the string '0001' or '0000' to a number 1 or 0
// !! convert the number to a boolean - true or false
enable: !!Number(msg.payload.substr(i * 4, 4))
}
}
// check if any relay is on then sets the relayall to on
// if not to off
relays[8] = { enable: relays.some((r) => r.enable) };
return relays;
[{"id":"3910f388ec3bada2","type":"function","z":"ffbd7f06.4a014","name":"","func":"const relays = [];\n\n// loops through the 8 relays and creates a msg property \n// object to send to the entity node to turn it on/off\nfor(let i = 0;i < 8;i++) {\n relays[i] = {\n // msg.payload.substr(i * 4, 4) same as you had original to parse out the string\n // Number() converts the string '0001' or '0000' to a number 1 or 0\n // !! convert the number to a boolean - true or false \n enable: !!Number(msg.payload.substr(i * 4, 4))\n }\n}\n// check if any really is on then sets the relayall to on\n// if not to off\nrelays[8] = { enable: relays.some((r) => r.enable) };\nreturn relays;","outputs":9,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":1440,"wires":[["a43a62d7d39cc187"],["9b549ffffd735144"],["1611aedc737322fc"],["f4e27578d393a8db"],["a1ba711f9939e345"],["aee0f79ac62ed38f"],["814e4c774a9a8752"],["62cee85c217c2426"],["706350d61da23944"]]},{"id":"2eac18bae0479504","type":"inject","z":"ffbd7f06.4a014","name":"evens on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"00000001000000010000000100000001","payloadType":"str","x":140,"y":1392,"wires":[["3910f388ec3bada2"]]},{"id":"a43a62d7d39cc187","type":"ha-entity","z":"ffbd7f06.4a014","name":"relay1","server":"","version":1,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"relay1"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"$entity().state ? 1 : 0","outputPayloadType":"jsonata","x":466,"y":1392,"wires":[["1d71e3db592478cd"],["1d71e3db592478cd"]]},{"id":"9b549ffffd735144","type":"ha-entity","z":"ffbd7f06.4a014","name":"relay2","server":"","version":1,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"relay2"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"$entity().state ? 1 : 0","outputPayloadType":"jsonata","x":466,"y":1440,"wires":[["a3a91e0cf64f5430"],["a3a91e0cf64f5430"]]},{"id":"1611aedc737322fc","type":"ha-entity","z":"ffbd7f06.4a014","name":"relay3","server":"","version":1,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"relay3"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"$entity().state ? 1 : 0","outputPayloadType":"jsonata","x":466,"y":1488,"wires":[["8ae82d25e1ae28bf"],["8ae82d25e1ae28bf"]]},{"id":"f4e27578d393a8db","type":"ha-entity","z":"ffbd7f06.4a014","name":"relay4","server":"","version":1,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"relay4"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"$entity().state ? 1 : 0","outputPayloadType":"jsonata","x":466,"y":1536,"wires":[["a5a7b6569c443b8c"],["a5a7b6569c443b8c"]]},{"id":"a1ba711f9939e345","type":"ha-entity","z":"ffbd7f06.4a014","name":"relay5","server":"","version":1,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"relay5"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"$entity().state ? 1 : 0","outputPayloadType":"jsonata","x":466,"y":1584,"wires":[["6ff2b7c45b55a028"],["6ff2b7c45b55a028"]]},{"id":"aee0f79ac62ed38f","type":"ha-entity","z":"ffbd7f06.4a014","name":"relay6","server":"","version":1,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"relay6"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"$entity().state ? 1 : 0","outputPayloadType":"jsonata","x":466,"y":1632,"wires":[["61accdf31f240ed4"],["61accdf31f240ed4"]]},{"id":"814e4c774a9a8752","type":"ha-entity","z":"ffbd7f06.4a014","name":"relay7","server":"","version":1,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"relay7"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"$entity().state ? 1 : 0","outputPayloadType":"jsonata","x":466,"y":1680,"wires":[["c2958026b048c166"],["c2958026b048c166"]]},{"id":"62cee85c217c2426","type":"ha-entity","z":"ffbd7f06.4a014","name":"relay8","server":"","version":1,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"relay8"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"$entity().state ? 1 : 0","outputPayloadType":"jsonata","x":466,"y":1728,"wires":[["dea5b7753392b861"],["dea5b7753392b861"]]},{"id":"1d71e3db592478cd","type":"debug","z":"ffbd7f06.4a014","name":"mqtt node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":1392,"wires":[]},{"id":"a3a91e0cf64f5430","type":"debug","z":"ffbd7f06.4a014","name":"mqtt node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":652,"y":1440,"wires":[]},{"id":"8ae82d25e1ae28bf","type":"debug","z":"ffbd7f06.4a014","name":"mqtt node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":652,"y":1488,"wires":[]},{"id":"a5a7b6569c443b8c","type":"debug","z":"ffbd7f06.4a014","name":"mqtt node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":652,"y":1536,"wires":[]},{"id":"6ff2b7c45b55a028","type":"debug","z":"ffbd7f06.4a014","name":"mqtt node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":652,"y":1584,"wires":[]},{"id":"61accdf31f240ed4","type":"debug","z":"ffbd7f06.4a014","name":"mqtt node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":652,"y":1632,"wires":[]},{"id":"c2958026b048c166","type":"debug","z":"ffbd7f06.4a014","name":"mqtt node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":652,"y":1680,"wires":[]},{"id":"dea5b7753392b861","type":"debug","z":"ffbd7f06.4a014","name":"mqtt node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":652,"y":1728,"wires":[]},{"id":"ef6b16033ca4ef57","type":"inject","z":"ffbd7f06.4a014","name":"odds on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"00010000000100000001000000010000","payloadType":"str","x":130,"y":1440,"wires":[["3910f388ec3bada2"]]},{"id":"cb166f0d426f3fd5","type":"inject","z":"ffbd7f06.4a014","name":"first and last","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"00010000000000000000000000000001","payloadType":"str","x":150,"y":1488,"wires":[["3910f388ec3bada2"]]},{"id":"86a50e0742ef4ee9","type":"inject","z":"ffbd7f06.4a014","name":"all off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"00000000000000000000000000000000","payloadType":"str","x":130,"y":1536,"wires":[["3910f388ec3bada2"]]},{"id":"015ab5d4be74214c","type":"inject","z":"ffbd7f06.4a014","name":"all on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"00010001000100010001000100010001","payloadType":"str","x":130,"y":1584,"wires":[["3910f388ec3bada2"]]},{"id":"706350d61da23944","type":"ha-entity","z":"ffbd7f06.4a014","name":"relayall","server":"","version":1,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"relayall"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"$entity().state ? 1 : 0","outputPayloadType":"jsonata","x":476,"y":1776,"wires":[["1d71e3db592478cd","a3a91e0cf64f5430","8ae82d25e1ae28bf","a5a7b6569c443b8c","6ff2b7c45b55a028","61accdf31f240ed4","c2958026b048c166","dea5b7753392b861"],["1d71e3db592478cd","a3a91e0cf64f5430","8ae82d25e1ae28bf","a5a7b6569c443b8c","6ff2b7c45b55a028","61accdf31f240ed4","c2958026b048c166","dea5b7753392b861"]]}]