Output sequentially and randomly to 3 different nodes

Ah, that explains something.
I think I have it all working and I will upload the flow once i've tidied it up and remade it without the Victron nodes.
The thing that I was struggling to expain was something that happens when relays should be switching off: let's say there were 2 relays on, it would switch off one then switch off another then switch a different one back on so it went from 2 to 1 relays as it should but not exactly as I, or Colin presumably, expected. Anyway it is a great node for my purposes.

So there is a kind of sequentiality (is that a real word?) in the all operations of this node it seems.

I think ideally, if it goes from 2 to 1, when 2 and 3 are on, then it should just switch off output 2.

Yes that would mean less switching.

It is possible that I'm mis-reading what's happening on the flow though.
Here is the flow albeit still in a bit of a mess:

[{"id":"9dde6298d23603e4","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"a8b65dbc8afb6270","type":"junction","z":"9dde6298d23603e4","x":641.9325766861439,"y":482.4776236433536,"wires":[["3fa3d798aebe85be"]]},{"id":"803f2b30fd0a87bc","type":"switch","z":"9dde6298d23603e4","name":"Amps >20 or <2","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"20","vt":"num"},{"t":"lt","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":225.265380859375,"y":291.90370750427246,"wires":[["4712693fd502bc61"],["e1ca453e45143458"]]},{"id":"e1ca453e45143458","type":"change","z":"9dde6298d23603e4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":441.2730712890625,"y":481.7422065734863,"wires":[["a8b65dbc8afb6270"]]},{"id":"3a713b86b727cc5c","type":"switch","z":"9dde6298d23603e4","name":"SoC","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"50","vt":"num"},{"t":"btwn","v":"50","vt":"num","v2":"69","v2t":"num"},{"t":"btwn","v":"70","vt":"num","v2":"79","v2t":"num"},{"t":"gte","v":"80","vt":"num"}],"checkall":"true","repair":false,"outputs":4,"x":263.26539611816406,"y":131.28460597991943,"wires":[["6d0f7e5448e4a382"],["683bccdb22ee1ca7"],["d12b728d2edba41f"],["87f19a532a9c49f4"]]},{"id":"3fa3d798aebe85be","type":"function","z":"9dde6298d23603e4","name":"Sequentially","func":"// On Start\nlet msg1 = {}\nlet msg2 = {}\nlet msg3 = {}\nlet msg4 = {}\n\nlet aArray = context.get('aArray')\nlet aCount = context.get('aCount')\nlet pFront = context.get('pFront')\nlet pBack = context.get('pBack')\n\nconst invar = msg.payload\n\nswitch (invar) {\n    case 1:\n        if(aCount === 3) {\n            // \n        } else {\n            aCount += 1\n            pFront = (pFront += 1)% 3\n            aArray[pFront] = 1\n        }   \n        break\n    case 0:\n        if (aCount === 0) {\n            //\n        } else {\n            aCount -= 1\n            pBack = (pBack += 1)% 3\n            aArray[pBack] = 0\n        }\n        break\n}\n\nnode.status('Input ' + invar + ' Count ' + aCount)\n\ncontext.set('aArray', aArray)\ncontext.set('aCount', aCount)\ncontext.set('pFront', pFront)\ncontext.set('pBack', pBack)\nmsg1.payload = aArray[0]\nmsg2.payload = aArray[1]\nmsg3.payload = aArray[2]\nmsg4.payload = aCount\n\nreturn [msg1, msg2, msg3,msg4]\n","outputs":4,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\n\ncontext.set('aArray', [0,0,0])\ncontext.set('aCount', 0)\ncontext.set('pFront', -1)\ncontext.set('pBack', -1)\n\nlet msg1 = {payload: 0}\nlet msg2 = {payload: 0}\nlet msg3 = {payload: 0}\nlet msg4 = {payload: 0}\nnode.send([msg1, msg2, msg3, msg4])\nnode.status('Input ' + 0 + ' Count ' + 0)\n\n","finalize":"","libs":[],"x":759.1345596313477,"y":482.23852252960205,"wires":[["be9a14a54b75ec91","a30edd2fb4d6d7df"],["4560a6b735e8b524","3417bb3701d12156"],["95eb404695640edb","f0c6518b812df717"],["6d51049146c86b4c"]]},{"id":"be9a14a54b75ec91","type":"debug","z":"9dde6298d23603e4","name":"debug 281","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1067.1344985961914,"y":370.2384614944458,"wires":[]},{"id":"4560a6b735e8b524","type":"debug","z":"9dde6298d23603e4","name":"debug 282","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1065.1345596313477,"y":454.2384605407715,"wires":[]},{"id":"95eb404695640edb","type":"debug","z":"9dde6298d23603e4","name":"debug 283","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1067.1344985961914,"y":542.2384595870972,"wires":[]},{"id":"cdf720ae45978931","type":"throttle","z":"9dde6298d23603e4","name":"","throttleType":"time","timeLimit":"2","timeLimitType":"minutes","countLimit":0,"blockSize":0,"locked":false,"x":218.265380859375,"y":447.7576789855957,"wires":[["803f2b30fd0a87bc"]]},{"id":"99b4e2f979394daa","type":"change","z":"9dde6298d23603e4","name":"Set flow.state","rules":[{"t":"set","p":"state","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":760.1345596313477,"y":113.37304592132568,"wires":[["7a0d385b0bbf2693"]]},{"id":"909d1f4470c0ce0b","type":"link out","z":"9dde6298d23603e4","name":"Stop All link out 8","mode":"link","links":["af5164fbd47a94bb"],"x":702.2730503082275,"y":40.00000762939453,"wires":[]},{"id":"87f19a532a9c49f4","type":"change","z":"9dde6298d23603e4","name":"80% 3 Relays Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"3","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":486.2653350830078,"y":151.0615530014038,"wires":[["99b4e2f979394daa"]]},{"id":"d12b728d2edba41f","type":"change","z":"9dde6298d23603e4","name":"70% 2 Relays Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":489.26927185058594,"y":114.05767726898193,"wires":[["99b4e2f979394daa"]]},{"id":"683bccdb22ee1ca7","type":"change","z":"9dde6298d23603e4","name":"50% 1 Relay Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":490.27310943603516,"y":77.06155300140381,"wires":[["99b4e2f979394daa","909d1f4470c0ce0b"]]},{"id":"6d0f7e5448e4a382","type":"change","z":"9dde6298d23603e4","name":"Master Relay OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":478.27308654785156,"y":40.053847312927246,"wires":[["909d1f4470c0ce0b","99b4e2f979394daa"]]},{"id":"7a0d385b0bbf2693","type":"change","z":"9dde6298d23603e4","name":"Save Flow state","rules":[{"t":"set","p":"flowstate","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":747.9181900024414,"y":168.52166557312012,"wires":[["a50abb98260e99e1","a79e39af856e996d"]]},{"id":"6d51049146c86b4c","type":"change","z":"9dde6298d23603e4","name":"Save relay on count","rules":[{"t":"set","p":"relaycount","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":459.91819763183594,"y":584.5216627120972,"wires":[["a50abb98260e99e1","a90d2b6ae3da6d57"]]},{"id":"a50abb98260e99e1","type":"function","z":"9dde6298d23603e4","name":"Compare relaycount and flowstate","func":"let relaycount = flow.get('relaycount')\nlet flowstate = flow.get('flowstate')\n\nif ( relaycount === undefined | flowstate === undefined) {\n    return;\n}\n\nif (relaycount >= flowstate) {\n  msg.payload = 0\n}\nif (relaycount < flowstate) {\n    msg.payload = 1\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":711.9181976318359,"y":226.5216646194458,"wires":[["0fb79ba3ac40969d","3a8ca7474b5ea3be"]]},{"id":"0fb79ba3ac40969d","type":"debug","z":"9dde6298d23603e4","name":"debug 284","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1063.2729263305664,"y":179.80380058288574,"wires":[]},{"id":"a90d2b6ae3da6d57","type":"debug","z":"9dde6298d23603e4","name":"debug 285","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":761.2652969360352,"y":583.8001050949097,"wires":[]},{"id":"3a8ca7474b5ea3be","type":"BooleanLogic","z":"9dde6298d23603e4","name":"","operation":"AND","inputCount":2,"topic":"result","x":758.4500503540039,"y":286.3769197463989,"wires":[["ea406aa21a4eab1c"]]},{"id":"3ea4bc6366f99cf4","type":"debug","z":"9dde6298d23603e4","name":"debug 286","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1053.6964492797852,"y":236.83856010437012,"wires":[]},{"id":"4712693fd502bc61","type":"change","z":"9dde6298d23603e4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":449.7000732421875,"y":285.65004539489746,"wires":[["3a8ca7474b5ea3be"]]},{"id":"ea406aa21a4eab1c","type":"switch","z":"9dde6298d23603e4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"true","vt":"jsonata"},{"t":"eq","v":"false","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":2,"x":772.7000503540039,"y":350.01537799835205,"wires":[["3ea4bc6366f99cf4","940004e4e0d1d6a4"],[]]},{"id":"940004e4e0d1d6a4","type":"change","z":"9dde6298d23603e4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":746.7038955688477,"y":402.48461532592773,"wires":[["a8b65dbc8afb6270","4007324d42bd1472"]]},{"id":"4007324d42bd1472","type":"debug","z":"9dde6298d23603e4","name":"debug 287","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1051.6962661743164,"y":282.66537284851074,"wires":[]},{"id":"a30edd2fb4d6d7df","type":"link out","z":"9dde6298d23603e4","name":"link out 4","mode":"link","links":["8790e476a15ec5f5"],"x":1048.7039556503296,"y":408.4307222366333,"wires":[]},{"id":"3417bb3701d12156","type":"link out","z":"9dde6298d23603e4","name":"link out 5","mode":"link","links":["e1397b487a729bce"],"x":1049.7000494003296,"y":492.43078207969666,"wires":[]},{"id":"f0c6518b812df717","type":"link out","z":"9dde6298d23603e4","name":"link out 6","mode":"link","links":["16b342adf23cd288"],"x":1049.7000484466553,"y":582.4307813644409,"wires":[]},{"id":"a79e39af856e996d","type":"debug","z":"9dde6298d23603e4","name":"debug 288","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1057.6960830688477,"y":126.66540431976318,"wires":[]},{"id":"c302f2c564437dec","type":"throttle","z":"9dde6298d23603e4","name":"","throttleType":"time","timeLimit":"3","timeLimitType":"minutes","countLimit":0,"blockSize":0,"locked":false,"x":132.27308654785156,"y":129.76537990570068,"wires":[["3a713b86b727cc5c"]]},{"id":"1ac1ec8ec56680e9","type":"inject","z":"9dde6298d23603e4","name":"Soc 49%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"49","payloadType":"num","x":85.39614868164062,"y":41.98461294174194,"wires":[["c302f2c564437dec"]]},{"id":"fd35479a0c4d693c","type":"inject","z":"9dde6298d23603e4","name":"SoC 50%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"50","payloadType":"num","x":83.40383911132812,"y":80.98461818695068,"wires":[["c302f2c564437dec"]]},{"id":"473c26250d8f89d7","type":"inject","z":"9dde6298d23603e4","name":"Soc 70%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"70","payloadType":"num","x":81.39999389648438,"y":172.98077964782715,"wires":[["c302f2c564437dec"]]},{"id":"502ece2389d3e9c4","type":"inject","z":"9dde6298d23603e4","name":"Soc 80%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"80","payloadType":"num","x":80.39614868164062,"y":208.98077677001953,"wires":[["c302f2c564437dec"]]},{"id":"faabfbd1bb211ebe","type":"inject","z":"9dde6298d23603e4","name":"Charge amps good","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":111.39614868164062,"y":390.9807929992676,"wires":[["cdf720ae45978931"]]},{"id":"63aa68ac7acb9267","type":"inject","z":"9dde6298d23603e4","name":"Charge amps bad","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":111.39999389648438,"y":505.9768867492676,"wires":[["cdf720ae45978931"]]}]

The function in that flow only appears to understand inputs of 0 and 1, I thought it had been updated to understand 0 to 3

Do you mean the "sequentially" node? I have no idea about it really, I just took it directly from the flow (very kindly) offered.

I need to know:
Do relays also need to be changed when % changes and current is > 20?
Or must it only be changed when current is <2?

Yes when the % goes from 49 to 50, 69 to 70 or 79 to 80.
Relay number can only go upwards not downwards if amps >20.
Theoretically the % cannot be going down if the amps are a positive number.

Am I close now?

[{"id":"e644407221b2afd5","type":"tab","label":"Victron","disabled":false,"info":"","env":[]},{"id":"0102e3923423067d","type":"junction","z":"e644407221b2afd5","x":520,"y":340,"wires":[["911dd5ee3b968153"]]},{"id":"1050cc06c58bd6c1","type":"junction","z":"e644407221b2afd5","x":154,"y":141,"wires":[["27114bc9f5dec638"]]},{"id":"2114162add383de1","type":"junction","z":"e644407221b2afd5","x":720,"y":580,"wires":[["c9b48cd88525229e","b52c4227358e602b"]]},{"id":"519c6d7987e9a83a","type":"junction","z":"e644407221b2afd5","x":720,"y":500,"wires":[["9f340c3dcf553dd6","82b3f8d2986cd871"]]},{"id":"08dc8802c5060c16","type":"junction","z":"e644407221b2afd5","x":720,"y":420,"wires":[["fe0a1ce2394bfd94","ee5a48bb723726d5"]]},{"id":"135018486de1ed71","type":"junction","z":"e644407221b2afd5","x":60,"y":740,"wires":[["a4ba6523b89822f6"]]},{"id":"64da6f9ddb409660","type":"junction","z":"e644407221b2afd5","x":640,"y":140,"wires":[["206bd6eac512fdd5"]]},{"id":"6d8ee7faeafef911","type":"junction","z":"e644407221b2afd5","x":640,"y":80,"wires":[["3d51a643a78ee935"]]},{"id":"14bcb9cf59196577","type":"switch","z":"e644407221b2afd5","name":"Amps >20 or <2","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"20","vt":"num"},{"t":"lt","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":160,"y":340,"wires":[["f770baea1d12048b"],["bb66719a4327ad1b"]]},{"id":"f770baea1d12048b","type":"change","z":"e644407221b2afd5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"AMP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":320,"wires":[["0102e3923423067d"]]},{"id":"bb66719a4327ad1b","type":"change","z":"e644407221b2afd5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"AMP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":360,"wires":[["0102e3923423067d"]]},{"id":"7582c4885052129d","type":"debug","z":"e644407221b2afd5","name":"debug 292","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1058.0075454711914,"y":187.90009307861328,"wires":[]},{"id":"4a1dace501b7fed0","type":"debug","z":"e644407221b2afd5","name":"debug 293","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1048.4310684204102,"y":244.93485260009766,"wires":[]},{"id":"acb21d4fd567da59","type":"debug","z":"e644407221b2afd5","name":"debug 294","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1046.4308853149414,"y":290.7616653442383,"wires":[]},{"id":"ee5a48bb723726d5","type":"debug","z":"e644407221b2afd5","name":"debug 295","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":380,"wires":[]},{"id":"fe0a1ce2394bfd94","type":"link out","z":"e644407221b2afd5","name":"link out 28","mode":"link","links":["8790e476a15ec5f5"],"x":885,"y":420,"wires":[]},{"id":"82b3f8d2986cd871","type":"debug","z":"e644407221b2afd5","name":"debug 296","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":460,"wires":[]},{"id":"9f340c3dcf553dd6","type":"link out","z":"e644407221b2afd5","name":"link out 29","mode":"link","links":["e1397b487a729bce"],"x":885,"y":500,"wires":[]},{"id":"b52c4227358e602b","type":"debug","z":"e644407221b2afd5","name":"debug 297","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":540,"wires":[]},{"id":"c9b48cd88525229e","type":"link out","z":"e644407221b2afd5","name":"link out 30","mode":"link","links":["16b342adf23cd288"],"x":885,"y":580,"wires":[]},{"id":"a4ba6523b89822f6","type":"debug","z":"e644407221b2afd5","name":"debug 298","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":170,"y":740,"wires":[]},{"id":"b857e13a09c5820a","type":"change","z":"e644407221b2afd5","name":"80% 3 Relays Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"3","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"PRC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":200,"wires":[["64da6f9ddb409660"]]},{"id":"5acc2b8b0d0280b1","type":"change","z":"e644407221b2afd5","name":"70% 2 Relays Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"PRC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":160,"wires":[["64da6f9ddb409660"]]},{"id":"ca76c45eda895f56","type":"change","z":"e644407221b2afd5","name":"50% 1 Relay Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"PRC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":120,"wires":[["64da6f9ddb409660","6d8ee7faeafef911"]]},{"id":"84f94d5afb023a35","type":"change","z":"e644407221b2afd5","name":"Master Relay OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"PRC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":80,"wires":[["64da6f9ddb409660","6d8ee7faeafef911"]]},{"id":"27114bc9f5dec638","type":"switch","z":"e644407221b2afd5","name":"SoC","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"50","vt":"num"},{"t":"btwn","v":"50","vt":"num","v2":"69","v2t":"num"},{"t":"btwn","v":"70","vt":"num","v2":"79","v2t":"num"},{"t":"gte","v":"80","vt":"num"}],"checkall":"true","repair":false,"outputs":4,"x":270,"y":140,"wires":[["84f94d5afb023a35"],["ca76c45eda895f56"],["5acc2b8b0d0280b1"],["b857e13a09c5820a"]]},{"id":"3d51a643a78ee935","type":"link out","z":"e644407221b2afd5","name":"Stop All link out 8","mode":"link","links":["af5164fbd47a94bb"],"x":695,"y":80,"wires":[]},{"id":"010b808f8471d6e4","type":"inject","z":"e644407221b2afd5","name":"SoC 50%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"50","payloadType":"num","x":120,"y":100,"wires":[["1050cc06c58bd6c1"]]},{"id":"7fe3642670eafdeb","type":"inject","z":"e644407221b2afd5","name":"Soc 49%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"49","payloadType":"num","x":120,"y":60,"wires":[["1050cc06c58bd6c1"]]},{"id":"3c58777230d67b1a","type":"inject","z":"e644407221b2afd5","name":"Soc 70%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"70","payloadType":"num","x":120,"y":180,"wires":[["1050cc06c58bd6c1"]]},{"id":"2292f10810139e2e","type":"inject","z":"e644407221b2afd5","name":"Soc 80%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"80","payloadType":"num","x":120,"y":220,"wires":[["1050cc06c58bd6c1"]]},{"id":"8ec839ff38098e39","type":"inject","z":"e644407221b2afd5","name":"Charge amps good","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":150,"y":300,"wires":[["14bcb9cf59196577"]]},{"id":"da68434dbd3c8cf5","type":"inject","z":"e644407221b2afd5","name":"Charge amps bad","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":150,"y":380,"wires":[["14bcb9cf59196577"]]},{"id":"8d4d7cd222f01cd8","type":"function","z":"e644407221b2afd5","name":"Sequentially","func":"// On Start\nlet msg1 = {}\nlet msg2 = {}\nlet msg3 = {}\n\nlet aPRC = context.get('aPRC')\nlet aPRCm = context.get('aPRCm')\nlet aAMP = context.get('aAMP')\nlet aArray = context.get('aArray')\nlet aCount = context.get('aCount')\nlet pFront = context.get('pFront')\nlet pBack = context.get('pBack')\nlet bState\nlet flowstate = flow.get('flowstate')\nconst invar = msg.payload\nconst topic = msg.topic\n\n\nswitch (topic) {\n    case 'AMP':\n        aAMP = invar\n        switch (invar) {\n            case 1:\n                if(aCount === 3) {\n                    // \n                } else {\n                    bState = aPRC\n                    while (bState > 0) {\n                        bState -= 1\n                        aCount += 1\n                        pFront = (pFront += 1)% 3\n                        aArray[pFront] = 1\n                    }\n                }   \n            break\n            case 0:\n                if (aCount === 0) {\n                    //\n                } else {\n                    bState = aCount\n                    while (bState > 0) {\n                        bState -= 1\n                        aCount -= 1\n                        pBack = (pBack += 1)% 3\n                        aArray[pBack] = 0\n\n\n                    }\n                }\n                aPRCm = aPRC\n                aArray = [0, 0, 0]   \n            break\n        }\n    break\n\n\n    case 'PRC':\n        switch (invar) {\n            case 0:\n                aPRCm = 0\n            break\n            case 1:\n            break\n            case 2:\n                if(invar > aPRCm) {\n                    aPRCm = invar\n                    if(aAMP === 1) {\n                        aCount += 1\n                        pFront = (pFront += 1) % 3\n                        aArray[pFront] = 1\n                    }\n                }  \n            break\n            case 3:\n                if (invar > aPRCm) {\n                    aPRCm = invar\n                    if(aAMP === 1) {\n                        aCount += 1\n                        pFront = (pFront += 1) % 3\n                        aArray[pFront] = 1\n                    }\n                }  \n            break\n        }\n        aPRC = invar\n    break\n}\n\nnode.status('PRC ' + aPRC + ' Count ' + aCount)\n\ncontext.set('aPRC', aPRC)\ncontext.set('aPRCm', aPRCm)\ncontext.set('aAMP', aAMP)\ncontext.set('aArray', aArray)\ncontext.set('aCount', aCount)\ncontext.set('pFront', pFront)\ncontext.set('pBack', pBack)\nmsg1.payload = aArray[0]\nmsg2.payload = aArray[1]\nmsg3.payload = aArray[2]\n\nreturn [msg1, msg2, msg3]\n","outputs":3,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\n\ncontext.set('aPRC', 0)\ncontext.set('aPRCm', 0)\ncontext.set('aAMP', 0)\ncontext.set('aArray', [0,0,0])\ncontext.set('aCount', 0)\ncontext.set('pFront', -1)\ncontext.set('pBack', -1)\n\nlet msg1 = {payload: 0}\nlet msg2 = {payload: 0}\nlet msg3 = {payload: 0}\nnode.send([msg1, msg2, msg3])\nnode.status('PRC ' + 0 + ' Count ' + 0)\n","finalize":"","libs":[],"x":590,"y":480,"wires":[["08dc8802c5060c16"],["519c6d7987e9a83a"],["2114162add383de1"]]},{"id":"206bd6eac512fdd5","type":"link out","z":"e644407221b2afd5","name":"link out 31","mode":"link","links":["df780405aeaad647"],"x":695,"y":140,"wires":[]},{"id":"911dd5ee3b968153","type":"link out","z":"e644407221b2afd5","name":"link out 32","mode":"link","links":["df780405aeaad647"],"x":565,"y":340,"wires":[]},{"id":"df780405aeaad647","type":"link in","z":"e644407221b2afd5","name":"link in 14","links":["206bd6eac512fdd5","911dd5ee3b968153"],"x":455,"y":480,"wires":[["8d4d7cd222f01cd8"]]}]

Thanks very much, I will try that tomorrow. My hot water is all heated up for today!
My existing flow has been altered to add another change node (set msg payload) after the "Amps >20 or <2" switch node and before the AND gate which inputs a "0" when amps are between 19 and 3. I think this was why it would sometimes behave incorrectly as the AND gate needed an actual "0" not just the lack of a "1".
Tomorrow or the next day I will give both flows a whirl and let you know.
Thanks again.

The other thing to consider is that maybe you should turn on the same heating element first each time. That way, when it fails, you will have 2 "virtually unused" elements to carry-on with while the first is replaced. By balancing-out the usage, they will all be ready to fail at the same time :slight_smile: Or if you do want to balance-out the usage, just turn them on in sequence.

A small adjustment.

[{"id":"260ed6da8bf50f6f","type":"tab","label":"Victron1","disabled":false,"info":"","env":[]},{"id":"222d87a8ade83fb1","type":"junction","z":"260ed6da8bf50f6f","x":640,"y":320,"wires":[["29cb70083d7c3c1b"]]},{"id":"70e28b0eb9dc381b","type":"junction","z":"260ed6da8bf50f6f","x":160,"y":140,"wires":[["3fa018cd59e3878c"]]},{"id":"baa32005eca1f72e","type":"junction","z":"260ed6da8bf50f6f","x":720,"y":560,"wires":[["9bced3475c39253f","0ffa0e1ba0ba8f25"]]},{"id":"2241ddd9f8411bc9","type":"junction","z":"260ed6da8bf50f6f","x":720,"y":480,"wires":[["5b7f51a063f7e0cd","c683e93eee3f4e46"]]},{"id":"ba2cfcddc699b7f9","type":"junction","z":"260ed6da8bf50f6f","x":720,"y":400,"wires":[["0c1456c471458302","450dc30dfd0d2a10"]]},{"id":"c8348cf88982b8bf","type":"junction","z":"260ed6da8bf50f6f","x":640,"y":140,"wires":[["9b526487f5e3efba"]]},{"id":"da0406f5ae56057b","type":"junction","z":"260ed6da8bf50f6f","x":640,"y":80,"wires":[["ed7ad07dd3aecfa1"]]},{"id":"412b887e2ee8567b","type":"switch","z":"260ed6da8bf50f6f","name":"Amps >20 or <2","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"20","vt":"num"},{"t":"lt","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":240,"y":320,"wires":[["fe9599516fd65ad4"],["442de32ffc1c350a"]]},{"id":"fe9599516fd65ad4","type":"change","z":"260ed6da8bf50f6f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"AMP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":300,"wires":[["222d87a8ade83fb1"]]},{"id":"442de32ffc1c350a","type":"change","z":"260ed6da8bf50f6f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"AMP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":340,"wires":[["222d87a8ade83fb1"]]},{"id":"bf4ce5c5881fa1fd","type":"debug","z":"260ed6da8bf50f6f","name":"debug 292","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1058.0075454711914,"y":187.90009307861328,"wires":[]},{"id":"944345bd9fb048a9","type":"debug","z":"260ed6da8bf50f6f","name":"debug 293","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1048.4310684204102,"y":244.93485260009766,"wires":[]},{"id":"185274477d1bed6c","type":"debug","z":"260ed6da8bf50f6f","name":"debug 294","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1046.4308853149414,"y":290.7616653442383,"wires":[]},{"id":"450dc30dfd0d2a10","type":"debug","z":"260ed6da8bf50f6f","name":"debug 295","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":360,"wires":[]},{"id":"0c1456c471458302","type":"link out","z":"260ed6da8bf50f6f","name":"link out 28","mode":"link","links":["8790e476a15ec5f5"],"x":885,"y":400,"wires":[]},{"id":"c683e93eee3f4e46","type":"debug","z":"260ed6da8bf50f6f","name":"debug 296","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":440,"wires":[]},{"id":"5b7f51a063f7e0cd","type":"link out","z":"260ed6da8bf50f6f","name":"link out 29","mode":"link","links":["e1397b487a729bce"],"x":885,"y":480,"wires":[]},{"id":"0ffa0e1ba0ba8f25","type":"debug","z":"260ed6da8bf50f6f","name":"debug 297","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":520,"wires":[]},{"id":"9bced3475c39253f","type":"link out","z":"260ed6da8bf50f6f","name":"link out 30","mode":"link","links":["16b342adf23cd288"],"x":885,"y":560,"wires":[]},{"id":"78849aa923d6994e","type":"change","z":"260ed6da8bf50f6f","name":"80% 3 Relays Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"3","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"SoC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":200,"wires":[["c8348cf88982b8bf"]]},{"id":"36f04b60a4ec707d","type":"change","z":"260ed6da8bf50f6f","name":"70% 2 Relays Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"SoC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":160,"wires":[["c8348cf88982b8bf"]]},{"id":"5db8cd83947601ab","type":"change","z":"260ed6da8bf50f6f","name":"50% 1 Relay Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"SoC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":120,"wires":[["c8348cf88982b8bf","da0406f5ae56057b"]]},{"id":"d01c33508c7631f3","type":"change","z":"260ed6da8bf50f6f","name":"Master Relay OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"SoC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":80,"wires":[["c8348cf88982b8bf","da0406f5ae56057b"]]},{"id":"3fa018cd59e3878c","type":"switch","z":"260ed6da8bf50f6f","name":"SoC","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"50","vt":"num"},{"t":"btwn","v":"50","vt":"num","v2":"69","v2t":"num"},{"t":"btwn","v":"70","vt":"num","v2":"79","v2t":"num"},{"t":"gte","v":"80","vt":"num"}],"checkall":"true","repair":false,"outputs":4,"x":270,"y":140,"wires":[["d01c33508c7631f3"],["5db8cd83947601ab"],["36f04b60a4ec707d"],["78849aa923d6994e"]]},{"id":"ed7ad07dd3aecfa1","type":"link out","z":"260ed6da8bf50f6f","name":"Stop All link out 8","mode":"link","links":["af5164fbd47a94bb"],"x":695,"y":80,"wires":[]},{"id":"ef1ed7914873afe6","type":"inject","z":"260ed6da8bf50f6f","name":"SoC 50%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"50","payloadType":"num","x":120,"y":100,"wires":[["70e28b0eb9dc381b"]]},{"id":"1d6c967708388eba","type":"inject","z":"260ed6da8bf50f6f","name":"SoC 49%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"49","payloadType":"num","x":120,"y":60,"wires":[["70e28b0eb9dc381b"]]},{"id":"db42ddb132363307","type":"inject","z":"260ed6da8bf50f6f","name":"SoC 70%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"70","payloadType":"num","x":120,"y":180,"wires":[["70e28b0eb9dc381b"]]},{"id":"d96c67a4766759e5","type":"inject","z":"260ed6da8bf50f6f","name":"SoC 80%","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"80","payloadType":"num","x":120,"y":220,"wires":[["70e28b0eb9dc381b"]]},{"id":"349ac519a9f76ec6","type":"inject","z":"260ed6da8bf50f6f","name":"Charge amps good","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":150,"y":280,"wires":[["412b887e2ee8567b"]]},{"id":"1f7a4edbfafe6659","type":"inject","z":"260ed6da8bf50f6f","name":"Charge amps bad","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":150,"y":360,"wires":[["412b887e2ee8567b"]]},{"id":"61cc196e550e3abf","type":"function","z":"260ed6da8bf50f6f","name":"Sequentially","func":"// On Start\nlet msg1 = {}\nlet msg2 = {}\nlet msg3 = {}\n\nlet aSoC   = context.get('aSoC')\nlet aSoCm  = context.get('aSoCm')\nlet aAMP   = context.get('aAMP')\nlet aArray = context.get('aArray')\nlet aCount = context.get('aCount')\nlet pFront = context.get('pFront')\nlet pBack  = context.get('pBack')\nlet bState\n\nconst invar = msg.payload\nconst topic = msg.topic\n\nfunction fSoC() {\n    if (invar > aSoCm) {\n        aSoCm = invar\n        if (aAMP === 1) {\n            aCount += 1\n            pFront = (pFront += 1) % 3\n            aArray[pFront] = 1\n        }\n    }  \n}\n\nswitch (topic) {\n    case 'AMP':\n        aAMP = invar\n        switch (invar) {\n            case 1:\n                if ((aCount === 3) || (aCount === aSoC) || (aCount === aSoCm)) {\n                    // \n                } else {\n                    bState = aSoC\n                    while (bState > 0) {\n                        bState -= 1\n                        aCount += 1\n                        pFront = (pFront += 1) % 3\n                        aArray[pFront] = 1\n                    }\n                }   \n            break\n            case 0:\n                if (aCount === 0) {\n                    //\n                } else {\n                    bState = aCount\n                    while (bState > 0) {\n                        bState -= 1\n                        aCount -= 1\n                        pBack = (pBack += 1) % 3\n                        aArray[pBack] = 0\n                    }\n                }\n                aSoCm = aSoC \n            break\n        }\n    break\n\n    case 'SoC':\n        switch (invar) {\n            case 0:\n                aSoCm = 0\n            break\n            case 1:\n                fSoC()\n            break\n            case 2:\n                fSoC()\n            break\n            case 3:\n                fSoC()\n            break\n        }\n        aSoC = invar\n    break\n}\n\nnode.status('SoCm ' + aSoCm + ' SoC ' + aSoC + ' Count ' + aCount)\n\ncontext.set('aSoC'  , aSoC)\ncontext.set('aSoCm' , aSoCm)\ncontext.set('aAMP'  , aAMP)\ncontext.set('aArray', aArray)\ncontext.set('aCount', aCount)\ncontext.set('pFront', pFront)\ncontext.set('pBack' , pBack)\nmsg1.payload = aArray[0]\nmsg2.payload = aArray[1]\nmsg3.payload = aArray[2]\n\nreturn [msg1, msg2, msg3]\n","outputs":3,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\n\ncontext.set('aSoC', 0)\ncontext.set('aSoCm', 0)\ncontext.set('aAMP', 0)\ncontext.set('aArray', [0,0,0])\ncontext.set('aCount', 0)\ncontext.set('pFront', -1)\ncontext.set('pBack', -1)\n\nlet msg1 = {payload: 0}\nlet msg2 = {payload: 0}\nlet msg3 = {payload: 0}\nnode.send([msg1, msg2, msg3])\nnode.status('SoCm ' + 0 + ' SoC ' + 0 + ' Count ' + 0)\n","finalize":"","libs":[],"x":590,"y":460,"wires":[["ba2cfcddc699b7f9"],["2241ddd9f8411bc9"],["baa32005eca1f72e"]]},{"id":"9b526487f5e3efba","type":"link out","z":"260ed6da8bf50f6f","name":"link out 31","mode":"link","links":["9defebdf7ed7a4a5"],"x":695,"y":140,"wires":[]},{"id":"29cb70083d7c3c1b","type":"link out","z":"260ed6da8bf50f6f","name":"link out 32","mode":"link","links":["9defebdf7ed7a4a5"],"x":695,"y":320,"wires":[]},{"id":"9defebdf7ed7a4a5","type":"link in","z":"260ed6da8bf50f6f","name":"link in 14","links":["9b526487f5e3efba","29cb70083d7c3c1b"],"x":455,"y":460,"wires":[["61cc196e550e3abf"]]}]
1 Like

When I get home this evening I will have a play.

I don't know if you can replace the elements separately though. They are all in the same unit which is designed for single or 3-phase installation depending on how you wire them, so I am using them separately but probably the thing is scrap once one of them goes.

I have set that flow in motion but the PV production is too low at this time to turn on any elements. I will know more sometime tomorrow and I will report back. Thanks again Frida.

Big thanks to @Frida whose nodes have made this a fully functional flow doing exactly what I need to control my 3-element water heater via Node-Red.

I have added a few easy bits like turning off after dark and a 3-minute delay and maybe I will add a manual override later and some SoC/Time of day conditions if I can work that out.
I will also put it on the Victron website in case anyone else might be able to use it in their systems as Node-Red is included in the Victron firmware to help with automatic load/production management etc.
Credit will be given to this website and especially Frida who looks like an Australian Terrier but can really write code! ( :laughing:)

[{"id":"8443e347bccc88bc","type":"tab","label":"Victron 2","disabled":false,"info":"","env":[]},{"id":"b07c3cf69f132e2e","type":"junction","z":"8443e347bccc88bc","x":640.9999694824219,"y":387,"wires":[["00af6be591f51115"]]},{"id":"9774d3c2cb215fea","type":"junction","z":"8443e347bccc88bc","x":720.9999694824219,"y":627,"wires":[["69cb7482c36d3cd1","0dcaef1989cf60b0"]]},{"id":"f6c0433b9fd2f9d9","type":"junction","z":"8443e347bccc88bc","x":720.9999694824219,"y":547,"wires":[["432ead21be009b5f","6fb68e7b2d0811c5"]]},{"id":"986a2fc77fb5916c","type":"junction","z":"8443e347bccc88bc","x":720.9999694824219,"y":467,"wires":[["1fd5916cfb52a857","fdd84b3362b1187c"]]},{"id":"1f2fa2399f377717","type":"junction","z":"8443e347bccc88bc","x":793.9999694824219,"y":201,"wires":[["b2404ae3fd955f92"]]},{"id":"330566a33512316b","type":"junction","z":"8443e347bccc88bc","x":793.5043593645096,"y":113.93516516685486,"wires":[["6dd86a18f98586e1"]]},{"id":"906903ac2acc2219","type":"switch","z":"8443e347bccc88bc","name":"Amps >25 or <2","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"25","vt":"num"},{"t":"lt","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":240.99996948242188,"y":387,"wires":[["62302cd6e719d6d2"],["ab476ea27008db98"]]},{"id":"62302cd6e719d6d2","type":"change","z":"8443e347bccc88bc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"AMP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460.9999694824219,"y":367,"wires":[["b07c3cf69f132e2e"]]},{"id":"ab476ea27008db98","type":"change","z":"8443e347bccc88bc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"AMP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460.9999694824219,"y":407,"wires":[["b07c3cf69f132e2e"]]},{"id":"fdd84b3362b1187c","type":"debug","z":"8443e347bccc88bc","name":"debug 295","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830.9999694824219,"y":427,"wires":[]},{"id":"1fd5916cfb52a857","type":"link out","z":"8443e347bccc88bc","name":"link out 28","mode":"link","links":["8790e476a15ec5f5"],"x":885.9999694824219,"y":467,"wires":[]},{"id":"6fb68e7b2d0811c5","type":"debug","z":"8443e347bccc88bc","name":"debug 296","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830.9999694824219,"y":507,"wires":[]},{"id":"432ead21be009b5f","type":"link out","z":"8443e347bccc88bc","name":"link out 29","mode":"link","links":["e1397b487a729bce"],"x":885.9999694824219,"y":547,"wires":[]},{"id":"0dcaef1989cf60b0","type":"debug","z":"8443e347bccc88bc","name":"debug 297","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830.9999694824219,"y":587,"wires":[]},{"id":"69cb7482c36d3cd1","type":"link out","z":"8443e347bccc88bc","name":"link out 30","mode":"link","links":["16b342adf23cd288"],"x":885.9999694824219,"y":627,"wires":[]},{"id":"b0a2079ccf1e9507","type":"change","z":"8443e347bccc88bc","name":"80% 3 Relays Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"3","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"SoC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":633.9999694824219,"y":261,"wires":[["1f2fa2399f377717"]]},{"id":"196f3b64c9941690","type":"change","z":"8443e347bccc88bc","name":"70% 2 Relays Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"SoC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":633.9999694824219,"y":221,"wires":[["1f2fa2399f377717"]]},{"id":"6717cb9a9d61f77b","type":"change","z":"8443e347bccc88bc","name":"50% 1 Relay Allowed","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"SoC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":633.9999694824219,"y":181,"wires":[["1f2fa2399f377717","330566a33512316b"]]},{"id":"444d7df9c276469c","type":"change","z":"8443e347bccc88bc","name":"Master Relay OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"SoC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":623.9999694824219,"y":141,"wires":[["1f2fa2399f377717","330566a33512316b"]]},{"id":"2ec7a90cb6ca4f41","type":"switch","z":"8443e347bccc88bc","name":"SoC","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"50","vt":"num"},{"t":"btwn","v":"50","vt":"num","v2":"69","v2t":"num"},{"t":"btwn","v":"70","vt":"num","v2":"79","v2t":"num"},{"t":"gte","v":"80","vt":"num"}],"checkall":"true","repair":false,"outputs":4,"x":423.9999694824219,"y":201,"wires":[["444d7df9c276469c"],["6717cb9a9d61f77b"],["196f3b64c9941690"],["b0a2079ccf1e9507"]]},{"id":"6dd86a18f98586e1","type":"link out","z":"8443e347bccc88bc","name":"Stop All link out 8","mode":"link","links":["af5164fbd47a94bb"],"x":849.9999008178711,"y":142,"wires":[]},{"id":"b2404ae3fd955f92","type":"link out","z":"8443e347bccc88bc","name":"link out 31","mode":"link","links":["dda44c243164d003"],"x":848.9999694824219,"y":201,"wires":[]},{"id":"00af6be591f51115","type":"link out","z":"8443e347bccc88bc","name":"link out 32","mode":"link","links":["dda44c243164d003"],"x":695.9999694824219,"y":387,"wires":[]},{"id":"dda44c243164d003","type":"link in","z":"8443e347bccc88bc","name":"link in 14","links":["b2404ae3fd955f92","00af6be591f51115"],"x":423.9999656677246,"y":526.9999885559082,"wires":[["ed572c6c58d55a2d"]]},{"id":"ed572c6c58d55a2d","type":"function","z":"8443e347bccc88bc","name":"Sequentially 1.0","func":"// On Start\nlet msg1 = {}\nlet msg2 = {}\nlet msg3 = {}\n\nlet aSoC   = context.get('aSoC')\nlet aAMP   = context.get('aAMP')\nlet aArray = context.get('aArray')\nlet aCount = context.get('aCount')\nlet pFront = context.get('pFront')\nlet pBack  = context.get('pBack')\n\nconst invar = msg.payload\nconst topic = msg.topic\n\nfunction fUP() {\n    aCount += 1\n    pFront = (pFront += 1) % 3\n    aArray[pFront] = 1\n}\n\n\nswitch (topic) {\n    case 'AMP':\n        aAMP = invar\n        switch (invar) {\n            case 0:\n                if (aCount === 0) {\n                    //\n                } else {\n                    aCount -= 1\n                    pBack = (pBack += 1) % 3\n                    aArray[pBack] = 0\n                }\n            break\n            case 1:\n                if ((aCount >= aSoC)) {\n                    // \n                } else {\n                    fUP()\n                }   \n            break\n        } // end invar\n    break // end AMP\n\n    case 'SoC':\n        if (aAMP === 1) {\n            if (invar > aSoC) {\n                fUP()\n            }\n        }\n        if (invar === 0) {\n            aCount = 0\n            aArray = [0, 0, 0]\n        }\n        aSoC = invar\n    break // end SoC\n} // end topic\n\n\nnode.status('AMP ' + aAMP + ' SoC ' + aSoC + ' Count ' + aCount)\n\ncontext.set('aSoC'  , aSoC)\ncontext.set('aAMP'  , aAMP)\ncontext.set('aArray', aArray)\ncontext.set('aCount', aCount)\ncontext.set('pFront', pFront)\ncontext.set('pBack' , pBack)\n\nmsg1.payload = aArray[0]\nmsg2.payload = aArray[1]\nmsg3.payload = aArray[2]\n\nreturn [msg1, msg2, msg3]\n","outputs":3,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\n\nnode.status('AMP ' + 0 + ' SoC ' + 0 + ' Count ' + 0)\n\ncontext.set('aSoC', 0)\ncontext.set('aAMP', 0)\ncontext.set('aArray', [0,0,0])\ncontext.set('aCount', 0)\ncontext.set('pFront', -1)\ncontext.set('pBack', -1)\n\nlet msg1 = {payload: 0}\nlet msg2 = {payload: 0}\nlet msg3 = {payload: 0}\n\nnode.send([msg1, msg2, msg3])\n","finalize":"","libs":[],"x":555.9999618530273,"y":526.9999885559082,"wires":[["986a2fc77fb5916c"],["f6c0433b9fd2f9d9"],["9774d3c2cb215fea"]]},{"id":"1b27664c69817970","type":"throttle","z":"8443e347bccc88bc","name":"","throttleType":"time","timeLimit":"3","timeLimitType":"minutes","countLimit":0,"blockSize":0,"locked":false,"x":261.40380859375,"y":201.5807638168335,"wires":[["2ec7a90cb6ca4f41"]]},{"id":"8ab317435b4cb534","type":"throttle","z":"8443e347bccc88bc","name":"","throttleType":"time","timeLimit":"3","timeLimitType":"minutes","countLimit":0,"blockSize":0,"locked":false,"x":191.40380859375,"y":335.58078287353516,"wires":[["906903ac2acc2219"]]},{"id":"394c472dad1cb04f","type":"victron-input-battery","z":"8443e347bccc88bc","service":"com.victronenergy.battery/512","path":"/Soc","serviceObj":{"service":"com.victronenergy.battery/512","name":"Pylontech battery"},"pathObj":{"path":"/Soc","type":"float","name":"State of charge (%)"},"name":"SoC","onlyChanges":false,"roundValues":"3","x":55.999969482421875,"y":121.41923141479492,"wires":[["b2bbf9aa00b650b4"]]},{"id":"319c9b590e89cde3","type":"victron-input-battery","z":"8443e347bccc88bc","service":"com.victronenergy.battery/512","path":"/Dc/0/Current","serviceObj":{"service":"com.victronenergy.battery/512","name":"Pylontech battery"},"pathObj":{"path":"/Dc/0/Current","type":"float","name":"Current (A)"},"name":"Charge Amps","onlyChanges":false,"roundValues":"3","x":75.99996948242188,"y":267.42308616638184,"wires":[["bfe5b2c30116d7fe"]]},{"id":"b2bbf9aa00b650b4","type":"time-range-switch","z":"8443e347bccc88bc","name":"7pm to 10am OFF","lat":"","lon":"","startTime":"19:00","endTime":"10:00","startOffset":0,"endOffset":0,"x":266.3961181640625,"y":121.25769424438477,"wires":[[],["1b27664c69817970"]]},{"id":"bfe5b2c30116d7fe","type":"time-range-switch","z":"8443e347bccc88bc","name":"7pm to 10am OFF","lat":"","lon":"","startTime":"19:00","endTime":"10:00","startOffset":0,"endOffset":0,"x":274.39996337890625,"y":267.26153848876953,"wires":[[],["8ab317435b4cb534"]]}]

1 Like

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