How to store value and make math operations without external database?

Hi Community, I have EV wall charger power meter where I'm picking up values like voltage,current,power etc from it via ModBus. Also everyday I'm taking kWh sample value at 0:30 and sending email to myself then same with another sample at 5:00 which is start and end of cheaper night tariff window, so in the morning I do see if my car charged up (sample2 - sample1 = xkwh in my head), now my question how can I do such very verycomplicated task..sample2 - sample1 from same source without external database/log? I wish to send third or only email to myself with pure calculation value.Thanks in advance

I think context storage is what you're looking for.

2 Likes

Hi. Maybe something like this. A simple function node to save the first reading as a flow variable and then when second reading is done work out the difference.

if(msg.topic === 'first_reading'){
    flow.set('first_reading', msg.reading)
} else {
    msg.result = msg.reading - flow.get('first_reading');
    return msg;
}
[{"id":"ffab00e3.ca281","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"c1241166.e489","type":"function","z":"ffab00e3.ca281","name":"","func":"var reading = msg.reading;\nvar result;\nif(msg.topic === 'first_reading'){\n    flow.set('first_reading', reading)\n} else {\n    let first_reading = flow.get('first_reading');\n    result = reading - first_reading;\n    msg.result = result;\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":160,"wires":[["47333c1c.862da4"]]},{"id":"29df7c11.4adb24","type":"comment","z":"ffab00e3.ca281","name":"trigger your reading","info":"","x":210,"y":100,"wires":[]},{"id":"3ed97ac0.3ce176","type":"inject","z":"ffab00e3.ca281","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":140,"wires":[["46430e36.0c291"]]},{"id":"46430e36.0c291","type":"change","z":"ffab00e3.ca281","name":"first_reading","rules":[{"t":"set","p":"reading","pt":"msg","to":"100","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"first_reading","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":140,"wires":[["c1241166.e489"]]},{"id":"47333c1c.862da4","type":"debug","z":"ffab00e3.ca281","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":740,"y":160,"wires":[]},{"id":"21fa44f0.6690dc","type":"inject","z":"ffab00e3.ca281","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":180,"wires":[["a9cdd55a.173498"]]},{"id":"a9cdd55a.173498","type":"change","z":"ffab00e3.ca281","name":"second_reading","rules":[{"t":"set","p":"reading","pt":"msg","to":"150","tot":"num"},{"t":"set","p":"topic","pt":"msg","to":"second_reading","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":180,"wires":[["c1241166.e489"]]}]

looks like solution thanks.

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