How to use watt2kwh ( get value of energy consumed at the end of each hour)

dear all ,
how to use watt2kwh to calculate the energy consumed each hour.
I want the value of energy consumed at the end of each hour.

[{"id":"46a2a128.2d8c5","type":"debug","z":"d0eb3ee7.8c75","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1050,"y":60,"wires":[]},{"id":"453baa13.e653b4","type":"inject","z":"d0eb3ee7.8c75","name":"1 kW feed","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1000","payloadType":"str","x":730,"y":60,"wires":[["80f91507.3f46b8"]]},{"id":"80f91507.3f46b8","type":"watt2kwh","z":"d0eb3ee7.8c75","format":"kwh","maximum":"6","maximumunit":"mins","name":"","x":890,"y":60,"wires":[["46a2a128.2d8c5"]]}]

The node converts power to energy, so in your example you are inputting 1kW every second, so the node outputs 0.00027777777777777778kWh every second (this varies slightly because the inject node does not output precisely every second, and can vary a millisecond or two).

There are 3600 seconds in an hour, so 3600 x 0.00027777777777777778 = 1 (1kWh).

So to calculate the daily energy, you would create a running sum of the node output, starting at midnight each day before being reset the following midnight. The same applies for hourly usage, start the running sum on the hour, before resetting it the following hour.
I would suggest using a file system context to hold the running sum.

Alternatively, you could just keep accumulating the running sum without resetting, and get the reading every hour, subtracting the previous value from the current value.

You could also save the watt2kwh node output to a database, and then you could simply sum the values over the required timeframe. (This is my preferred option).

Hope this helps :wink:

That is the way I do it too. If you save the individual kWh values from the node to Influx then you can easily get the usage for an hour or a day or a month by using the CumulativeSum query available with Influxdb.

1 Like

thank you, I found this solution

[{"id":"d7825a7.be8c4a8","type":"inject","z":"386a07c8.b31678","name":"","props":[{"p":"payload"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1000","payloadType":"num","x":180,"y":520,"wires":[["6fd0fc36.1f6cc4"]]},{"id":"1483b2e3.824cad","type":"function","z":"386a07c8.b31678","name":"","func":"var inputVal = msg.payload;\n \nvar d  = new Date();\nvar datetime =(\"0\" + d.getDate()).slice(-2) + \"-\" + (\"0\"+(d.getMonth()+1)).slice(-2) + \"-\" +\n    d.getFullYear() + \"  \" + (\"0\" + d.getHours()).slice(-2) + \":\" + (\"0\" + d.getMinutes()).slice(-2)+ \":\" + (\"0\" + d.getSeconds()).slice(-2);\n\t\n\tvar minutes=(\"0\" + d.getMinutes()).slice(-2);\n  \n  context.etat=context.etat || 5;\n  \n\tif(minutes=='10' && context.etat=='5'){\n\t     var savedVal = flow.get('energyVal')||0;\n\t     flow.set(\"energyVal\",0); \n\t    msg.topic=\"save\";\n\t    msg.payload = savedVal;\n\t    //etat=false;\n\t     \n\t    context.etat='1';\nreturn msg;\n\t}\n\telse{\n\t    if(minutes!='10'){\n\t        //etat=true;\n\t        // flow.set(\"etatVal\",true); \n\t         context.etat='5';\n\t    }\n\t    \n\t    msg.topic=\"calcul\";\n\t    var savedVal = flow.get('energyVal')||0;\nsavedVal += inputVal;\nflow.set(\"energyVal\",savedVal);\nmsg.payload = savedVal;\ncontext.etat=context.etat;\nreturn msg;\n\t}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":540,"y":580,"wires":[["8f9625c7.1f7d08"]]},{"id":"8f9625c7.1f7d08","type":"switch","z":"386a07c8.b31678","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"save","vt":"str"},{"t":"eq","v":"calcul","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":520,"wires":[["3ec8fb92.fa51b4"],["a4417010.4633"]]},{"id":"3ec8fb92.fa51b4","type":"debug","z":"386a07c8.b31678","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":440,"wires":[]},{"id":"a4417010.4633","type":"debug","z":"386a07c8.b31678","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":560,"wires":[]},{"id":"6fd0fc36.1f6cc4","type":"watt2kwh","z":"386a07c8.b31678","format":"kwh","maximum":"60","maximumunit":"mins","name":"","x":380,"y":460,"wires":[["1483b2e3.824cad"]]}]

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