Energy calculation

Hi all. I try to work out how to make a function javascript to calculate cost ow energy. I have daily data coming through mqtt, which is zero itself every day at 00:00
I managed to store the data to the flow, and I managed to access it and zero this value via inject node.

What I try to work out to set a secondary and third flow. Weekly and monthly cost.
So ideally I have daily flow stored and I wish to add this value to another flow called weekly and the daily flow should be added to weekly every day of the week. On Sunday at 23:59 trigger a save function and zero the flow at 00:01. This can be achieved by a inject node.

Same for the monthly, but this function should read the date and should make save on the last day of the month at 23:59 and zero the flow at 00:01. In this case I will not be able to use a inject node as it is only allows days.

Would really appreciate if I can get some help.
Thanks in advance.

The rest of the flow is all working nice and when this cost calculation is finished I will share the flow as I am pretty sure others would use it to.

No need for extra flows, store all the data in a database and use queries to analyse data on a daily, weekly or monthly basis.

Well that is another approach. In that case I have to start all over... I just managed to learn how to store data to flow. :slight_smile: Very beginner user here. Never learned how to write programs or such.

At the moment I am standing here.
I have the stored flow,and can call the value in to my other flow which is weekly but I just can not work out how to add those data every time the inject node is triggered. It is over writes the data instead of adding to it.

Here is my function node:
//var count=context.get('count') || 0;
var count=flow.get('Daily') || 0;

count +=0;
msg.payload="Daily"+msg.payload+" "+count;
return msg;

Hello Pisti

Even i have same kind of issue , Can you please guide me with your flow so that i can get a clear idea on my flow


Hi! Sorry for not responding to your message. I did not login for a while.
Here is the full flow and it is now working as it should. You can download it from my drive.
You just change the mqtt details and you good to go. I also have one for the Eastron SDM120 and SDM630 3 phase meter, but that is Modbus communication.
Hope it helps.
Best wishes.

Thanks for your kind response @Pisti

I will work on it and will update you

Much appreciated

Energy charges