Sum different values depending on time?

I have a value which varies every hour. I get that one from a reading, but I need to sum this value with a solid number between 06.00 and 23.00 (last input at 22.00) and with another one between 23.00 and 06.00 (Last input at 05.00). Any suggestions hove I solve this?

Best regards
Freddy

Since nobody chimed in you get the B team, me. Possibly even the C team.
First thing I see is you are going to need to store a value maybe several. This can either be a flow save or a context save. If you google node red context or flow save you should get examples. The next part I'm not sure I fully understand. Do you want to sum at a specific time or when a value arrives?

Here is a simpla example hope it help

[{"id":"a91958b1.07a2c8","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":110,"y":1060,"wires":[["73a6434b.d073fc"]]},{"id":"73a6434b.d073fc","type":"switch","z":"b779de97.b1b46","name":"","property":"$toMillis(\"1970-01-01T\" & $substringAfter($now(),\"T\"))","propertyType":"jsonata","rules":[{"t":"btwn","v":"21600000","vt":"num","v2":"82000000","v2t":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":260,"y":1060,"wires":[["b52932b3.d6fa68"],["7773f63c.a2d5b"]]},{"id":"b52932b3.d6fa68","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"sum.day","pt":"flow","to":"$$.payload + ($exists($flowContext(\"sum.day\")) ? $flowContext(\"sum.day\") : 0)","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"sum.day","tot":"flow"},{"t":"set","p":"sum.night","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":1040,"wires":[["38c93b0.6dfd3c6"]]},{"id":"7773f63c.a2d5b","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"sum.night","pt":"flow","to":"$$.payload + ($exists($flowContext(\"sum.night\")) ? $flowContext(\"sum.night\") : 0)","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"sum.night","tot":"flow"},{"t":"set","p":"sum.day","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":1100,"wires":[["5a03a1da.5e2458"]]},{"id":"38c93b0.6dfd3c6","type":"debug","z":"b779de97.b1b46","name":"day","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":670,"y":1040,"wires":[]},{"id":"5a03a1da.5e2458","type":"debug","z":"b779de97.b1b46","name":"night","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":660,"y":1100,"wires":[]},{"id":"84e51c51.691938","type":"function","z":"b779de97.b1b46","name":"","func":"msg.payload = msg.payload.toFixed(7);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":920,"wires":[["38c93b0.6dfd3c6"]]},{"id":"b2b18590.1f1ac8","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"24.45","payloadType":"num","x":80,"y":920,"wires":[["84e51c51.691938"]]}]

21600000 is 6am
82000000 is about 10 minutes to 11pm

1 Like

Thank you, I think I can work with that.