Pool Relays Using Raspberry PI and Node Red

Hey everyone,

I am new to node red and raspberry but have been working in tech for many years. I have built a simple system to automate my pool controls and it is working great. What I am struggling with is building a switch that operates multiple relays at one time. In the attached you will see my pump relay controls. I need to adjust the Timer Speed by opening and closing ports on an 8 port board I have attached to my Raspberry. I would like to use the slider for this and I would utilize 3 of my relays.

I currently have my temp sensors working and my valves operating but cant figure out how to control my relays with the slider.

If any of you would be kind enough to help I would appreciate it.

See the attached document to control the pool pump stages.

Basically for stages 1-8 it should be.
1 - OFF OFF OFF
2 - On OFF OFF
3 - OFF ON ON
and so on.

If you could help with two or three of them I could do the rest.

Thank you for all your help.![Screen Shot 2021-10-04 at 7.12.14 PM|472x500]

Hey here is what I have now but I know that it doesnt work. Sorry I should have put this in before.

Hello, and welcome to the forum.

It is just a picture :wink: We would need to see the flow to understand the inner workings. Please use the </> icon in the post editor to properly format your exported flow.

1 Like

Hey Sorry about that. I know what i have is not really close so didnt think you guys would want to see it. Thank you again.

[{"id":"7a6ef63f.680ad8","type":"tab","label":"Pool Control","disabled":false,"info":""},{"id":"bd4c6b9a.818a08","type":"rpi-gpio out","z":"7a6ef63f.680ad8","name":"Pin37","pin":"35","set":true,"level":"1","freq":"","out":"out","x":530,"y":140,"wires":[]},{"id":"3c8f165a.c6ff6a","type":"ui_switch","z":"7a6ef63f.680ad8","name":"WaterFall","label":"WaterFall","tooltip":"","group":"6c515e8b.33252","order":1,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"0","onvalueType":"str","onicon":"fa-power-off fa-3x","oncolor":"#0FD344","offvalue":"1","offvalueType":"str","officon":"fa-power-off fa-3x","offcolor":"#D30F0F","animate":true,"className":"","x":230,"y":140,"wires":[["bd4c6b9a.818a08","393afdd4.939002"]]},{"id":"9d51f839.883828","type":"rpi-gpio out","z":"7a6ef63f.680ad8","name":"Pin 31","pin":"31","set":true,"level":"0","freq":"","out":"out","x":510,"y":220,"wires":[]},{"id":"3908a932.732686","type":"rpi-gpio out","z":"7a6ef63f.680ad8","name":"Pin  33","pin":"33","set":true,"level":"1","freq":"","out":"out","x":510,"y":300,"wires":[]},{"id":"adb7ce14.2fe2a","type":"rpi-gpio out","z":"7a6ef63f.680ad8","name":"pin 35","pin":"37","set":true,"level":"1","freq":"","out":"out","x":510,"y":400,"wires":[]},{"id":"5e115b95.fedc24","type":"rpi-gpio out","z":"7a6ef63f.680ad8","name":"Pin31","pin":"29","set":true,"level":"1","freq":"","out":"out","x":510,"y":480,"wires":[]},{"id":"d88a6c56.8075b","type":"ui_switch","z":"7a6ef63f.680ad8","name":"Wall Jets","label":"Wall Jets","tooltip":"","group":"6c515e8b.33252","order":2,"width":"6","height":"1","passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"1","onvalueType":"str","onicon":"fa-power-off fa-3x","oncolor":"green","offvalue":"0","offvalueType":"str","officon":"fa-power-off fa-3x","offcolor":"red","animate":true,"className":"","x":220,"y":300,"wires":[["3908a932.732686"]]},{"id":"67eb21c3.78bfd","type":"ui_dropdown","z":"7a6ef63f.680ad8","name":"Bubbles/Spa Selection","label":"Bubbles/Spa","tooltip":"","place":"Select option","group":"6c515e8b.33252","order":4,"width":"6","height":"1","passthru":true,"multiple":false,"options":[{"label":"Spa Jets On","value":"1","type":"str"},{"label":"Bubles On","value":"0","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":260,"y":380,"wires":[["adb7ce14.2fe2a"]]},{"id":"b3ce6c19.ab2dd","type":"ui_switch","z":"7a6ef63f.680ad8","name":"Light","label":"Light","tooltip":"","group":"6c515e8b.33252","order":3,"width":"0","height":"0","passthru":false,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"0","offvalueType":"str","officon":"","offcolor":"","animate":true,"className":"","x":210,"y":240,"wires":[["9d51f839.883828"]]},{"id":"f3ecb84f.9f5298","type":"ui_dropdown","z":"7a6ef63f.680ad8","name":"Pool/Spa Drain","label":"Poo/Spa Drain1","tooltip":"","place":"Select option","group":"6c515e8b.33252","order":5,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"Jaccuzi Operation","value":"0","type":"str"},{"label":"Normal Operation","value":"1","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":220,"y":480,"wires":[["5e115b95.fedc24"]]},{"id":"393afdd4.939002","type":"rpi-gpio out","z":"7a6ef63f.680ad8","name":"Turn Off wall jets","pin":"33","set":"","level":"0","freq":"","out":"out","x":720,"y":180,"wires":[]},{"id":"d6fbdc5c.9b19f8","type":"ui_slider","z":"7a6ef63f.680ad8","name":"slider","label":"slider","tooltip":"","group":"6c515e8b.33252","order":8,"width":0,"height":0,"passthru":true,"outs":"end","topic":"topic","topicType":"msg","min":"1","max":"3","step":1,"className":"","x":290,"y":560,"wires":[["d5ab12d8.3872f8"]]},{"id":"c69ce93d.7af2b","type":"rpi-gpio out","z":"7a6ef63f.680ad8","name":"","pin":"15","set":"","level":"0","freq":"","out":"out","x":1100,"y":620,"wires":[]},{"id":"df928085.864a78","type":"rpi-gpio out","z":"7a6ef63f.680ad8","name":"","pin":"13","set":"","level":"0","freq":"","out":"out","x":1100,"y":560,"wires":[]},{"id":"a064fd2f.3e33f","type":"debug","z":"7a6ef63f.680ad8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":970,"y":800,"wires":[]},{"id":"d5ab12d8.3872f8","type":"switch","z":"7a6ef63f.680ad8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":670,"y":560,"wires":[["df928085.864a78","c69ce93d.7af2b","5449db92.240d7c"],["df928085.864a78","c69ce93d.7af2b","addd5ff0.3bc31","a064fd2f.3e33f"],["addd5ff0.3bc31","df928085.864a78","c69ce93d.7af2b","a1b8a17.5c54d6"]]},{"id":"addd5ff0.3bc31","type":"rpi-gpio out","z":"7a6ef63f.680ad8","name":"","pin":"11","set":"","level":"0","freq":"","out":"out","x":1110,"y":680,"wires":[]},{"id":"5449db92.240d7c","type":"debug","z":"7a6ef63f.680ad8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1000,"y":740,"wires":[]},{"id":"a1b8a17.5c54d6","type":"debug","z":"7a6ef63f.680ad8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":860,"wires":[]},{"id":"6c515e8b.33252","type":"ui_group","name":"Pool_Control","tab":"c82c84de.ad0fc8","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"c82c84de.ad0fc8","type":"ui_tab","name":"Pool","icon":"dashboard","disabled":false,"hidden":false}]

Firstly... I am not sure you have the concept of the switch node yet.

If you are using the slider as a three way switch (why not use the ui_multistate_switch node?) to send a specific payload to a specific nodes (I am using debug as I don't want to mess up my own RPi GPIOs) then you would have it arranged more like this.

However this only sends the payload value... what you want seems to be more like toggling GPIOs in various sequences based on payload.

I would possibly suggest a function node using an array of settings chosen based on the slider/switch output.

1 Like

Yes thank you very much. I was just toying around with that.

I will work on it tonight and tomorrow and let you know how it goes.

I do very much appreciate your willingness to help!!!!!!

This should do the trick...

image

[{"id":"75d8ea1d5b21ad5b","type":"function","z":"7a6ef63f.680ad8","name":"","func":"let msg1 = [];\nlet msg2 = [];\nlet msg3 = [];\n\nif (msg.payload == 1) {\n    msg1 = {payload: 0};\n    msg2 = {payload: 0};\n    msg3 = {payload: 0};\n} else if (msg.payload == 2) {\n    msg1 = { payload: 1 };\n    msg2 = { payload: 0 };\n    msg3 = { payload: 0 };\n} else if (msg.payload == 3) {\n    msg1 = { payload: 0 };\n    msg2 = { payload: 1 };\n    msg3 = { payload: 1 };\n}\n\nreturn [msg1, msg2, msg3];","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":260,"wires":[["5aa38115c09a8e0c"],["0959ac7c11745b14"],["4f6f6b496a01e9ee"]]},{"id":"5aa38115c09a8e0c","type":"debug","z":"7a6ef63f.680ad8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":900,"y":200,"wires":[]},{"id":"0959ac7c11745b14","type":"debug","z":"7a6ef63f.680ad8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":900,"y":260,"wires":[]},{"id":"4f6f6b496a01e9ee","type":"debug","z":"7a6ef63f.680ad8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":900,"y":320,"wires":[]},{"id":"516eeac197449c6d","type":"ui_slider","z":"7a6ef63f.680ad8","name":"slider","label":"slider","tooltip":"","group":"6c515e8b.33252","order":8,"width":0,"height":0,"passthru":true,"outs":"end","topic":"topic","topicType":"msg","min":"1","max":"3","step":1,"className":"","x":520,"y":260,"wires":[["75d8ea1d5b21ad5b"]]},{"id":"6c515e8b.33252","type":"ui_group","name":"Pool_Control","tab":"c82c84de.ad0fc8","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"c82c84de.ad0fc8","type":"ui_tab","name":"Pool","icon":"dashboard","disabled":false,"hidden":false}]

Using this in the function node

let msg1 = [];
let msg2 = [];
let msg3 = [];

if (msg.payload == 1) {
    msg1 = {payload: 0};
    msg2 = {payload: 0};
    msg3 = {payload: 0};
} else if (msg.payload == 2) {
    msg1 = {payload: 1};
    msg2 = {payload: 0};
    msg3 = {payload: 0};
} else if (msg.payload == 3) {
    msg1 = {payload: 0};
    msg2 = {payload: 1};
    msg3 = {payload: 1};
}

return [msg1, msg2, msg3];

Don't forget to add more outputs to the function node (in it's Setup) if you add switch options

Wow that is so awesome!!!!!

Thank you so much for helping me out.

That is very kind.

BTW I love Node-Red and Raspberry. I was a Linux admin for many years but am now doing something different. It has been alot of fun getting back into some fun tools. I cant get enough.

Thanks Again.

2 Likes

You might like to try this in the function. It should work for the values 1 to 8

let msgs = []
msg.payload = msg.payload - 1 // convert to 0 to 7

for (i=0; i<3; i++) {
    msgs.push({payload: msg.payload & 1})
    msg.payload = msg.payload >>> 1
}
return msgs
1 Like

Hey that works as well. Thank you Collin for the information. I will keep both solutions and study them to get better.

I don't understand how this function knows the correct sequence to activate the relays?

EDIT OK, it seems it is just a basic binary counter... not what the OP needed, but cool anyhow for seeing how the code works :wink:

Did you mean off, on, on for 3 or did you mean off, on, off? If you mean off, on, on then what did you mean by "and so on"?

I made a small error. To make it strictly correct it should be
for (let i=0; i<3; i++) {

These are the "relay" settings (not binary numbers) that OP needed to control via a slider or multi-switch. He provided the initial three as an example and the "and so on" meant settings 4-8 that he could program himself once a way was shown.

image

Thanks... I finally realized what was missing... doh... I should have known that.

Meanwhile, I made a neat "super computer" from your integer-to-binary code :stuck_out_tongue:

SuperComputer

[{"id":"c54521f6226155b2","type":"function","z":"7a6ef63f.680ad8","name":"","func":"let msgs = []\nmsg.payload = msg.payload// convert to 0 to 7\n\nfor (let i = 0; i < 255; i++) {\n    msgs.push({ payload: msg.payload & 1 })\n    msg.payload = msg.payload >>> 1\n}\nreturn msgs","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":120,"wires":[["33e8e13d3fe7db87"],["61bde71b8efd1e4e"],["74552130ebdfd591"],["ba20b3d518714600"],["e0e127d496def956"],["13759b4631b90c25"],["bc0849fc2f3b6f83"],["c603fdf5c543fda9"]]},{"id":"39bf0515f0b633f2","type":"random","z":"7a6ef63f.680ad8","name":"","low":"0","high":"255","inte":"true","property":"payload","x":300,"y":120,"wires":[["c54521f6226155b2","cfb831976b73d43b"]]},{"id":"cfb831976b73d43b","type":"debug","z":"7a6ef63f.680ad8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":290,"y":60,"wires":[]},{"id":"0a3df6293dfca1b8","type":"inject","z":"7a6ef63f.680ad8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":".5","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":130,"y":120,"wires":[["39bf0515f0b633f2"]]},{"id":"33e8e13d3fe7db87","type":"ui_led","z":"7a6ef63f.680ad8","order":8,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffff00","value":"0","valueType":"num"},{"color":"#008000","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"1-1","x":1450,"y":180,"wires":[]},{"id":"61bde71b8efd1e4e","type":"ui_led","z":"7a6ef63f.680ad8","order":7,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffff00","value":"0","valueType":"num"},{"color":"#008000","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"1-2","x":1330,"y":180,"wires":[]},{"id":"74552130ebdfd591","type":"ui_led","z":"7a6ef63f.680ad8","order":6,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffff00","value":"0","valueType":"num"},{"color":"#008000","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"1-4","x":1210,"y":180,"wires":[]},{"id":"ba20b3d518714600","type":"ui_led","z":"7a6ef63f.680ad8","order":5,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffff00","value":"0","valueType":"num"},{"color":"#008000","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"1-8","x":1090,"y":180,"wires":[]},{"id":"e0e127d496def956","type":"ui_led","z":"7a6ef63f.680ad8","order":4,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffff00","value":"0","valueType":"num"},{"color":"#008000","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"1-16","x":970,"y":180,"wires":[]},{"id":"13759b4631b90c25","type":"ui_led","z":"7a6ef63f.680ad8","order":3,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffff00","value":"0","valueType":"num"},{"color":"#008000","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"1-32","x":850,"y":180,"wires":[]},{"id":"bc0849fc2f3b6f83","type":"ui_led","z":"7a6ef63f.680ad8","order":2,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffff00","value":"0","valueType":"num"},{"color":"#008000","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"1-64","x":730,"y":180,"wires":[]},{"id":"c603fdf5c543fda9","type":"ui_led","z":"7a6ef63f.680ad8","order":1,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffff00","value":"0","valueType":"num"},{"color":"#008000","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"1-128","x":610,"y":180,"wires":[]},{"id":"18de6d0c813178eb","type":"function","z":"7a6ef63f.680ad8","name":"","func":"let msgs = []\nmsg.payload = msg.payload// convert to 0 to 7\n\nfor (let i = 0; i < 255; i++) {\n    msgs.push({ payload: msg.payload & 1 })\n    msg.payload = msg.payload >>> 1\n}\nreturn msgs","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":320,"wires":[["8755c9c4b6dbf826"],["0b5cd1467752cafe"],["137977ba5e5f60de"],["4ffe8d012df49c26"],["e85ddf51897c6e1b"],["1425fb5810a4d1e2"],["3f16081bb47e3ef4"],["4d71de7921033569"]]},{"id":"e2585f5a82374731","type":"random","z":"7a6ef63f.680ad8","name":"","low":"0","high":"255","inte":"true","property":"payload","x":300,"y":320,"wires":[["18de6d0c813178eb","7bf20707c2a26958"]]},{"id":"7bf20707c2a26958","type":"debug","z":"7a6ef63f.680ad8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":290,"y":260,"wires":[]},{"id":"20f45aa63cfcc4bb","type":"inject","z":"7a6ef63f.680ad8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":".75","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":130,"y":320,"wires":[["e2585f5a82374731"]]},{"id":"8755c9c4b6dbf826","type":"ui_led","z":"7a6ef63f.680ad8","order":16,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"0","valueType":"num"},{"color":"#0000ff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"2-1","x":1450,"y":380,"wires":[]},{"id":"0b5cd1467752cafe","type":"ui_led","z":"7a6ef63f.680ad8","order":15,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"0","valueType":"num"},{"color":"#0000ff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"2-2","x":1330,"y":380,"wires":[]},{"id":"137977ba5e5f60de","type":"ui_led","z":"7a6ef63f.680ad8","order":14,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"0","valueType":"num"},{"color":"#0000ff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"2-4","x":1210,"y":380,"wires":[]},{"id":"4ffe8d012df49c26","type":"ui_led","z":"7a6ef63f.680ad8","order":13,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"0","valueType":"num"},{"color":"#0000ff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"2-8","x":1090,"y":380,"wires":[]},{"id":"e85ddf51897c6e1b","type":"ui_led","z":"7a6ef63f.680ad8","order":12,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"0","valueType":"num"},{"color":"#0000ff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"2-16","x":970,"y":380,"wires":[]},{"id":"1425fb5810a4d1e2","type":"ui_led","z":"7a6ef63f.680ad8","order":11,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"0","valueType":"num"},{"color":"#0000ff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"2-32","x":850,"y":380,"wires":[]},{"id":"3f16081bb47e3ef4","type":"ui_led","z":"7a6ef63f.680ad8","order":10,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"0","valueType":"num"},{"color":"#0000ff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"2-64","x":730,"y":380,"wires":[]},{"id":"4d71de7921033569","type":"ui_led","z":"7a6ef63f.680ad8","order":9,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"0","valueType":"num"},{"color":"#0000ff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"2-128","x":610,"y":380,"wires":[]},{"id":"051d0e6d47583241","type":"function","z":"7a6ef63f.680ad8","name":"","func":"let msgs = []\nmsg.payload = msg.payload// convert to 0 to 7\n\nfor (let i = 0; i < 255; i++) {\n    msgs.push({ payload: msg.payload & 1 })\n    msg.payload = msg.payload >>> 1\n}\nreturn msgs","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":540,"wires":[["9894199d30ec233f"],["d1ed5915a6750f6b"],["ab6e62715682d7fd"],["f23f0dd66290f58e"],["bb1eb334746d052f"],["68446bbfc895aac9"],["16e7059115e0b3bf"],["671be4884bfdc13b"]]},{"id":"847e01713b9f8290","type":"random","z":"7a6ef63f.680ad8","name":"","low":"0","high":"255","inte":"true","property":"payload","x":300,"y":540,"wires":[["051d0e6d47583241","2c195a21352fe88c"]]},{"id":"2c195a21352fe88c","type":"debug","z":"7a6ef63f.680ad8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":290,"y":480,"wires":[]},{"id":"c09e9fe61cefe7d1","type":"inject","z":"7a6ef63f.680ad8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":".25","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":130,"y":540,"wires":[["847e01713b9f8290"]]},{"id":"9894199d30ec233f","type":"ui_led","z":"7a6ef63f.680ad8","order":24,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffffff","value":"0","valueType":"num"},{"color":"#ffa500","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"3-1","x":1450,"y":600,"wires":[]},{"id":"d1ed5915a6750f6b","type":"ui_led","z":"7a6ef63f.680ad8","order":23,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffffff","value":"0","valueType":"num"},{"color":"#ffa500","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"3-2","x":1330,"y":600,"wires":[]},{"id":"ab6e62715682d7fd","type":"ui_led","z":"7a6ef63f.680ad8","order":22,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffffff","value":"0","valueType":"num"},{"color":"#ffa500","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"3-4","x":1210,"y":600,"wires":[]},{"id":"f23f0dd66290f58e","type":"ui_led","z":"7a6ef63f.680ad8","order":21,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffffff","value":"0","valueType":"num"},{"color":"#ffa500","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"3-8","x":1090,"y":600,"wires":[]},{"id":"bb1eb334746d052f","type":"ui_led","z":"7a6ef63f.680ad8","order":20,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffffff","value":"0","valueType":"num"},{"color":"#ffa500","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"3-16","x":970,"y":600,"wires":[]},{"id":"68446bbfc895aac9","type":"ui_led","z":"7a6ef63f.680ad8","order":19,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffffff","value":"0","valueType":"num"},{"color":"#ffa500","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"3-32","x":850,"y":600,"wires":[]},{"id":"16e7059115e0b3bf","type":"ui_led","z":"7a6ef63f.680ad8","order":18,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffffff","value":"0","valueType":"num"},{"color":"#ffa500","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"3-64","x":730,"y":600,"wires":[]},{"id":"671be4884bfdc13b","type":"ui_led","z":"7a6ef63f.680ad8","order":17,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ffffff","value":"0","valueType":"num"},{"color":"#ffa500","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"3-128","x":610,"y":600,"wires":[]},{"id":"aef672735c6fa496","type":"function","z":"7a6ef63f.680ad8","name":"","func":"let msgs = []\nmsg.payload = msg.payload// convert to 0 to 7\n\nfor (let i = 0; i < 255; i++) {\n    msgs.push({ payload: msg.payload & 1 })\n    msg.payload = msg.payload >>> 1\n}\nreturn msgs","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":740,"wires":[["bde15beece574c72"],["d8e61c0ad4b65db9"],["3d93f9f2893a6ee4"],["2b0b69c62939e75b"],["838aab12f3bbd34a"],["6461177513c69613"],["7d7a6ab2c6962ad3"],["b130466b08881293"]]},{"id":"57a82a51495d8117","type":"random","z":"7a6ef63f.680ad8","name":"","low":"0","high":"255","inte":"true","property":"payload","x":300,"y":740,"wires":[["aef672735c6fa496","65a7ae22e0b153d9"]]},{"id":"65a7ae22e0b153d9","type":"debug","z":"7a6ef63f.680ad8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":290,"y":680,"wires":[]},{"id":"966afc805b676626","type":"inject","z":"7a6ef63f.680ad8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":130,"y":740,"wires":[["57a82a51495d8117"]]},{"id":"bde15beece574c72","type":"ui_led","z":"7a6ef63f.680ad8","order":32,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#800080","value":"0","valueType":"num"},{"color":"#00ffff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"4-1","x":1450,"y":800,"wires":[]},{"id":"d8e61c0ad4b65db9","type":"ui_led","z":"7a6ef63f.680ad8","order":31,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#800080","value":"0","valueType":"num"},{"color":"#00ffff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"4-2","x":1330,"y":800,"wires":[]},{"id":"3d93f9f2893a6ee4","type":"ui_led","z":"7a6ef63f.680ad8","order":30,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#800080","value":"0","valueType":"num"},{"color":"#00ffff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"4-4","x":1210,"y":800,"wires":[]},{"id":"2b0b69c62939e75b","type":"ui_led","z":"7a6ef63f.680ad8","order":29,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#800080","value":"0","valueType":"num"},{"color":"#00ffff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"4-8","x":1090,"y":800,"wires":[]},{"id":"838aab12f3bbd34a","type":"ui_led","z":"7a6ef63f.680ad8","order":28,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#800080","value":"0","valueType":"num"},{"color":"#00ffff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"4-16","x":970,"y":800,"wires":[]},{"id":"6461177513c69613","type":"ui_led","z":"7a6ef63f.680ad8","order":27,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#800080","value":"0","valueType":"num"},{"color":"#00ffff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"4-32","x":850,"y":800,"wires":[]},{"id":"7d7a6ab2c6962ad3","type":"ui_led","z":"7a6ef63f.680ad8","order":26,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#800080","value":"0","valueType":"num"},{"color":"#00ffff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"4-64","x":730,"y":800,"wires":[]},{"id":"b130466b08881293","type":"ui_led","z":"7a6ef63f.680ad8","order":25,"group":"6c515e8b.33252","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#800080","value":"0","valueType":"num"},{"color":"#00ffff","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"4-128","x":610,"y":800,"wires":[]},{"id":"6c515e8b.33252","type":"ui_group","name":"Super_Computer","tab":"c82c84de.ad0fc8","order":1,"disp":true,"width":"8","collapse":false,"className":""},{"id":"c82c84de.ad0fc8","type":"ui_tab","name":"WOPR","icon":"dashboard","disabled":false,"hidden":false}]
1 Like

That table is not the same as the OP posted. It shows 0ff, on, off for 3 whereas the initial post has off, on, on.

In fact that pattern absolutely is binary numbers, and I believe the function I posted does exactly that. The sequence in the table is
000, 100, 010, 110, 001, 101, 011, 111, which is 0 to 7 in binary (with the bit order least significant first).

So he made a typo :stuck_out_tongue: it happens. (And I read binary from right to left... I am silly that way :crazy_face: )

But since the OP hasn't said boo since, I think our further concern is irrelevant :slight_smile:

Hey guys I put in what Gunner suggested today. It worked great.

Looks like I had two different manuals that I pulled the relay from not sure.

Anyway it works great and I truly appreciate your help.

1 Like

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