if you don’t want to program it all yourself take a look at open energy monitor which integrates well with Node-red and was designed for analysis of energy usage
Did you see that you can make them persistent? That means they are saved in a file and will be available following a restart. So you could save your running total in a persistent context variable (I suggest a flow rather than global variable) and then you can use that as the base value to add to the values from the device.
Well, im not the best programmer at all. Thats why im asking here for a solution.
Node-Red gives alot of solutions i may not know now.
I dont know how to explain well. I hope you understood my problem.
How should i use the context variables to add the power to a persistent variable?
If my Total consumption is around lets say 100Wh. Now the Shelly device is set to zero from its power. Then it starts counting again. Lets say it shows 10Wh at its energy topic. Then this 10Wh should be add to the existing 100Wh. If it now counts up to 15Wh, it have to add only the 5Wh diffrence from the last message to the total consumption, otherwise i would get bad results.
On startup pick up the persistent context value (100) from the context and save it in a different variable in context, something like baseUsage. Each time a new value comes from the device (say 10, then 15) then add baseUsage to it (so 100+10=110, then 100+15=115) and use that value for display, and save it back to the persistent context value. So the persistent one becomes 110 then 115, but baseUsage stays at 100. If you restart again at that point then it will pick up the 115 and put that in baseUsage ready for the next reading from the device.
Actually that will only work if you restart both node-red and the Shelly at the same time, so you will have to work at it a bit more. Hopefully that is enough to get you started at least.
Sounds nice. But restarting the device and node-red at the same time is no solution i think. What could be a workaround?
@ghayne: Im using more Shelly devices like Shelly 1PM, Shelly Plug and Shelly Plug S. Everything has a powermeter inside, but the "built-in energy history" is only included if you are using the cloud.
If you are using MQTT-Only then you have no history. Only the consumption from powering the device up
First you have to forget about the fact that it is software and work out logically how you might do it. Once you have worked out some logic then we can work out how to implement it. So the question is, I suppose, how can you tell that the shelly has reset? Is there some way of determining that from the data you can get from it?
If there is then you can extend my suggested algorithm to take the appropriate action when it sees the shelly has reset.
That will only tell you if it stays offline for more than about 30 secs I think (though not certain about that). Consider what will happen to the energy used value that you receive over a reset.