"Help" value for rotating between flows

Hello,

I have created a automation for having excess solar energy put into a three phase heater in the warm water tank.
It is a three phase system so currently it is switching on one phase at a time but this results in that phase 1 resistor is getting the most hours on it.

So now to the problem I’m having. I would like to create a sensor entity or something which value would be set as the last resistor is turned of.

It would be something like
“help value” = 1 then the order would be L1 → L2 → L3 and when the excess energy decreases it would switch off L3 → L2 → L1 and then set “help value” = 2
“help value” = 2 then the order would be L2 → L3 → L1 and switching off L1 → L3 → L2 and the set “help value” = 3.
“help value” = 3 then the order would be L3 → L1 → L2 and switching off L2 → L1 → L3 and setting “help value” = 1

How could I create this kind of “help value”?

I used a state machine node to model this (there are probably better ways to do this but hey, I had some fun doing this).

[{"id":"9730b3e50d94bee3","type":"state-machine","z":"8b43de8505f17be7","name":"","triggerProperty":"payload","triggerPropertyType":"msg","stateProperty":"payload","statePropertyType":"msg","initialDelay":"0","persistOnReload":true,"outputStateChangeOnly":false,"throwException":false,"states":["start","L1 On","L2 On","L3 On","L1 Off","L2 Off","L3 Off"],"transitions":[{"name":"start","from":"start","to":"L1 On"},{"name":"1.1","from":"L1 On","to":"L2 On"},{"name":"1.2","from":"L2 On","to":"L3 On"},{"name":"1.3","from":"L3 On","to":"L3 Off"},{"name":"1.4","from":"L3 Off","to":"L2 Off"},{"name":"1.5","from":"L2 Off","to":"L1 Off"},{"name":"2.1","from":"L1 Off","to":"L2 On"},{"name":"2.2","from":"L2 On","to":"L3 On"},{"name":"2.3","from":"L3 On","to":"L1 On"},{"name":"2.4","from":"L1 On","to":"L1 Off"},{"name":"2.5","from":"L1 Off","to":"L3 Off"},{"name":"2.6","from":"L3 Off","to":"L2 Off"},{"name":"3.1","from":"L2 Off","to":"L3 On"},{"name":"3.2","from":"L3 On","to":"L1 On"},{"name":"3.3","from":"L1 On","to":"L2 On"},{"name":"3.4","from":"L2 On","to":"L2 Off"},{"name":"3.5","from":"L2 Off","to":"L1 Off"},{"name":"3.6","from":"L1 Off","to":"L3 Off"}],"x":980,"y":440,"wires":[["f7e88da829ecdf77"]]},{"id":"f57841bb9389b766","type":"inject","z":"8b43de8505f17be7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1.1","payloadType":"str","x":770,"y":440,"wires":[["9730b3e50d94bee3"]]},{"id":"f7e88da829ecdf77","type":"debug","z":"8b43de8505f17be7","name":"debug 8","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1180,"y":440,"wires":[]},{"id":"14d389c3f887a367","type":"inject","z":"8b43de8505f17be7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"start","payloadType":"str","x":770,"y":380,"wires":[["9730b3e50d94bee3"]]},{"id":"f84e39080b188201","type":"inject","z":"8b43de8505f17be7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1.2","payloadType":"str","x":770,"y":500,"wires":[["9730b3e50d94bee3"]]},{"id":"2bf9f488b1b9506f","type":"inject","z":"8b43de8505f17be7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1.3","payloadType":"str","x":770,"y":560,"wires":[["9730b3e50d94bee3"]]},{"id":"2cb6b8b4074daba5","type":"inject","z":"8b43de8505f17be7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1.4","payloadType":"str","x":770,"y":620,"wires":[["9730b3e50d94bee3"]]},{"id":"e7c2bad8f40e0d90","type":"inject","z":"8b43de8505f17be7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1.5","payloadType":"str","x":770,"y":680,"wires":[["9730b3e50d94bee3"]]}]

Or you could use a node-red context to keep track of your “helper value”

https://nodered.org/docs/user-guide/context