# Cost Calculation

**URL:** https://discourse.nodered.org/t/cost-calculation/66321
**Category:** General
**Created:** [11 August 2022 11:42 UTC](https://discourse.nodered.org/t/cost-calculation/66321 "2022-08-11T11:42:57Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)
#### Post date: [11 August 2022 11:42 UTC](https://discourse.nodered.org/t/cost-calculation/66321/1 "2022-08-11T11:42:57Z")

</div>

I have an energy meter which I would like to accumulate a cost per unit of electric. Does anybody have a flow I can copy and paste or guid me hoe I can accumulate my Kwh and put that into a cost per Kwh per Hour and then over a 24 hour period and then save that at midnight so it will say you used £xx.xx in Kwh yesterday?  
This is my current flow.  
Thanks for any advice  
Paul.

```auto
[{"id":"ff4ea44f.0119c","type":"tab","label":"OR-WE-514 ORNO","disabled":false,"info":""},{"id":"1871b2a2.91984d","type":"modbus-read","z":"ff4ea44f.0119c","name":"Voltage 0x0131","topic":"Voltage","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"001","dataType":"HoldingRegister","adr":"0x0131","quantity":"1","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"ad952d25.37b4","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":120,"y":40,"wires":[["8efb0f77.aecbf8"],[]]},{"id":"8efb0f77.aecbf8","type":"range","z":"ff4ea44f.0119c","minin":"0","maxin":"10000","minout":"0","maxout":"100","action":"scale","round":true,"property":"payload","name":"","x":360,"y":20,"wires":[["7812d783.a5fa8"]]},{"id":"dfcd44d2.a235b","type":"modbus-read","z":"ff4ea44f.0119c","name":"Frequency 0x0130","topic":"Frequency","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"001","dataType":"HoldingRegister","adr":"0x130","quantity":"1","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"ad952d25.37b4","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":130,"y":100,"wires":[["b6849155.ac06d"],[]]},{"id":"b6849155.ac06d","type":"range","z":"ff4ea44f.0119c","minin":"0","maxin":"10000","minout":"0","maxout":"100","action":"scale","round":true,"property":"payload","name":"","x":360,"y":80,"wires":[["c5fb8aca.38f2a"]]},{"id":"1fa4c271.a3aaa6","type":"modbus-read","z":"ff4ea44f.0119c","name":"Power Factor 0x0158","topic":"PowerFactor","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"001","dataType":"HoldingRegister","adr":"0x158","quantity":"1","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"ad952d25.37b4","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":140,"y":160,"wires":[["64249f3f.55a16"],[]]},{"id":"64249f3f.55a16","type":"range","z":"ff4ea44f.0119c","minin":"0","maxin":"1000","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload","name":"","x":360,"y":140,"wires":[["23c54e0d.6617c2"]]},{"id":"be7e1db7.046e88","type":"modbus-read","z":"ff4ea44f.0119c","name":"0x0150 - Apparent Power","topic":"Apparent Power","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"001","dataType":"HoldingRegister","adr":"0x0150","quantity":"2","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"ad952d25.37b4","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":150,"y":400,"wires":[["be65e0aa.a3bb98"],[]]},{"id":"3aa5f8e9.413158","type":"split","z":"ff4ea44f.0119c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":350,"y":200,"wires":[["1fb070a5.64a88f"]]},{"id":"1fb070a5.64a88f","type":"switch","z":"ff4ea44f.0119c","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":490,"y":200,"wires":[["31e529fc.b4acf6"],["31e529fc.b4acf6"]]},{"id":"31e529fc.b4acf6","type":"join","z":"ff4ea44f.0119c","name":"Amps","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":650,"y":200,"wires":[["631716ec.763cd8"]]},{"id":"631716ec.763cd8","type":"change","z":"ff4ea44f.0119c","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Amps","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":200,"wires":[["3b7899f6.f90756"]]},{"id":"3b7899f6.f90756","type":"function","z":"ff4ea44f.0119c","name":"32bit register coversion /100","func":"var low = msg.payload[1];\nvar high = msg.payload[0];\n\nvar lowhex = low.toString(16);\nvar highhex = high.toString(16);\n\nvar total = ((high << 16) + low) / 100;\n\nmsg.payload = total;\n//msg.measurement = \"W\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1140,"y":300,"wires":[["4d17f2f4.ca24e4"]]},{"id":"4d17f2f4.ca24e4","type":"switch","z":"ff4ea44f.0119c","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Amps","vt":"str"},{"t":"eq","v":"ActivePower","vt":"str"},{"t":"eq","v":"ReActivePower","vt":"str"},{"t":"eq","v":"ApparentPower","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":490,"y":600,"wires":[["7837a53c.c21a5c"],["922022df.a495"],["bed9452e.0ad7d"],["db99d604.b9efe"]]},{"id":"7837a53c.c21a5c","type":"range","z":"ff4ea44f.0119c","minin":"0","maxin":"1000","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload","name":"","x":640,"y":560,"wires":[["921b3e6d.04fc48","c5b11e7.79146e","6d70ed49.a78664"]]},{"id":"f1b7c9e3.8b9328","type":"split","z":"ff4ea44f.0119c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":350,"y":260,"wires":[["66bbb2c3.9673ec"]]},{"id":"66bbb2c3.9673ec","type":"switch","z":"ff4ea44f.0119c","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":490,"y":260,"wires":[["69238cc4.e41f64"],["69238cc4.e41f64"]]},{"id":"69238cc4.e41f64","type":"join","z":"ff4ea44f.0119c","name":"ActivePower","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":670,"y":260,"wires":[["9efdce11.8b45"]]},{"id":"9efdce11.8b45","type":"change","z":"ff4ea44f.0119c","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"ActivePower","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":260,"wires":[["3b7899f6.f90756"]]},{"id":"922022df.a495","type":"range","z":"ff4ea44f.0119c","minin":"0","maxin":"1000","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload","name":"","x":640,"y":600,"wires":[["a4e14454.9845f8"]]},{"id":"c58848b7.d50ac8","type":"split","z":"ff4ea44f.0119c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":350,"y":340,"wires":[["d8bea899.b762c"]]},{"id":"d8bea899.b762c","type":"switch","z":"ff4ea44f.0119c","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":490,"y":340,"wires":[["f7d477c8.62ff78"],["f7d477c8.62ff78"]]},{"id":"f7d477c8.62ff78","type":"join","z":"ff4ea44f.0119c","name":"ReActivePower","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":680,"y":340,"wires":[["ea35c814.cee85"]]},{"id":"ea35c814.cee85","type":"change","z":"ff4ea44f.0119c","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"ReActivePower","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":340,"wires":[["3b7899f6.f90756"]]},{"id":"bed9452e.0ad7d","type":"range","z":"ff4ea44f.0119c","minin":"0","maxin":"1000","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload","name":"","x":640,"y":640,"wires":[["8f63947a.847dc8"]]},{"id":"d5fdc007.9142e","type":"modbus-read","z":"ff4ea44f.0119c","name":"0x0148 - Reactive Power","topic":"Reactive Power","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"001","dataType":"HoldingRegister","adr":"0x0148","quantity":"2","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"ad952d25.37b4","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":150,"y":340,"wires":[["c58848b7.d50ac8"],[]]},{"id":"5535c8f6.485f08","type":"modbus-read","z":"ff4ea44f.0119c","name":"0x0140 - Active Power","topic":"Active Power","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"001","dataType":"HoldingRegister","adr":"0x0140","quantity":"2","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"ad952d25.37b4","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":140,"y":280,"wires":[["f1b7c9e3.8b9328"],[]]},{"id":"841ac646.b59d8","type":"modbus-read","z":"ff4ea44f.0119c","name":"0x0139 - Amps","topic":"Amps","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"001","dataType":"HoldingRegister","adr":"0x0139","quantity":"2","rate":"1","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"ad952d25.37b4","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":120,"y":220,"wires":[["3aa5f8e9.413158"],[]]},{"id":"be65e0aa.a3bb98","type":"split","z":"ff4ea44f.0119c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":350,"y":400,"wires":[["1c71a45e.ae44d4"]]},{"id":"1c71a45e.ae44d4","type":"switch","z":"ff4ea44f.0119c","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":490,"y":400,"wires":[["91178ddf.686fc"],["91178ddf.686fc"]]},{"id":"91178ddf.686fc","type":"join","z":"ff4ea44f.0119c","name":"ApparentPower","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":680,"y":400,"wires":[["914db8ab.86291"]]},{"id":"914db8ab.86291","type":"change","z":"ff4ea44f.0119c","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"ApparentPower","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":400,"wires":[["3b7899f6.f90756"]]},{"id":"db99d604.b9efe","type":"range","z":"ff4ea44f.0119c","minin":"0","maxin":"1000","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload","name":"","x":640,"y":680,"wires":[["94cd589f.95fcd8"]]},{"id":"7812d783.a5fa8","type":"influxdb out","z":"ff4ea44f.0119c","influxdb":"ef6b85bb.96471","name":"","measurement":"Voltage","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":570,"y":20,"wires":[]},{"id":"921b3e6d.04fc48","type":"influxdb out","z":"ff4ea44f.0119c","influxdb":"ef6b85bb.96471","name":"","measurement":"Amps","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":850,"y":560,"wires":[]},{"id":"a4e14454.9845f8","type":"influxdb out","z":"ff4ea44f.0119c","influxdb":"ef6b85bb.96471","name":"","measurement":"ActivePower","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":870,"y":600,"wires":[]},{"id":"8f63947a.847dc8","type":"influxdb out","z":"ff4ea44f.0119c","influxdb":"ef6b85bb.96471","name":"","measurement":"ReActivePower","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":880,"y":640,"wires":[]},{"id":"c5fb8aca.38f2a","type":"influxdb out","z":"ff4ea44f.0119c","influxdb":"ef6b85bb.96471","name":"","measurement":"Frequency","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":580,"y":80,"wires":[]},{"id":"23c54e0d.6617c2","type":"influxdb out","z":"ff4ea44f.0119c","influxdb":"ef6b85bb.96471","name":"","measurement":"PowerFactor","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":590,"y":140,"wires":[]},{"id":"94cd589f.95fcd8","type":"influxdb out","z":"ff4ea44f.0119c","influxdb":"ef6b85bb.96471","name":"","measurement":"ApparentPower","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":880,"y":680,"wires":[]},{"id":"c5b11e7.79146e","type":"ui_text","z":"ff4ea44f.0119c","group":"cf7e1722.e9c28","order":12,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":1020,"y":520,"wires":[]},{"id":"6d70ed49.a78664","type":"ui_chart","z":"ff4ea44f.0119c","name":"","group":"cf7e1722.e9c28","order":13,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1120,"y":580,"wires":[[]]},{"id":"ad952d25.37b4","type":"modbus-client","z":"","name":"Serial","clienttype":"serial","bufferCommands":true,"stateLogEnabled":true,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"even","serialConnectionDelay":"100","unit_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":false},{"id":"ef6b85bb.96471","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"home","name":"Influx","usetls":false,"tls":"","influxdbVersion":"1.x","url":"http://localhost:8086","rejectUnauthorized":true},{"id":"cf7e1722.e9c28","type":"ui_group","z":"","name":"Spa Charts","tab":"c1c558a3.75e47","order":2,"disp":true,"width":"20","collapse":false},{"id":"c1c558a3.75e47","type":"ui_tab","z":"","name":"Spa","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [11 August 2022 13:35 UTC](https://discourse.nodered.org/t/cost-calculation/66321/2 "2022-08-11T13:35:33Z")

</div>

This has cropped up a few times before with solutions provided by others. Worth searching through the forum.

---

<div class="post-metadata">

### Author: ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)
#### Post date: [11 August 2022 13:59 UTC](https://discourse.nodered.org/t/cost-calculation/66321/3 "2022-08-11T13:59:10Z")

</div>

Trust me I tried the search before hand and thought hopefully somebody will remember it of know the solution. But thanks anyway  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/83f5024225436e90fdff4043e1e7ae1bed8a79c6.png)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [11 August 2022 16:49 UTC](https://discourse.nodered.org/t/cost-calculation/66321/4 "2022-08-11T16:49:56Z")

</div>

not looked at any of these but:

> [@Best strategy for Reading & Sorting Electricity Cost Array](https://discourse.nodered.org/t/best-strategy-for-reading-sorting-electricity-cost-array/7929):
>
> Hi I have just switched electricity suppliers to Octopus Energy who I think are maybe one of the first to have variable half hour rates in the UK depending on wholesale price. Naturally I want to make some switching decisions based on future electricity cost. There is an example curl statement that gets the results in file attache.[result.txt](https://discourse.nodered.org/uploads/short-url/ekN0sYYiaByIOjpUV0kIddTUcEt.txt) (11.6 KB) This gives the pricing for the next 24 hours. I am no programmer but I have Node-RED successfully controlling all sorts of devices mainly by c…

> [@Daily energy usage plus costs](https://discourse.nodered.org/t/daily-energy-usage-plus-costs/4648):
>
> Hi, I have a hassio running with node-red with an usb cable attached to my kamstrup 162 smart meter. This is configured in home assistant and I can see the data and display it on the ui. What I want to do is make a function: Start measuring gas usage on 0:00 and end at 23:59, and display this on the ui on daily basis. Calculate the costs from the start at 0:00 and also display that. e.g. 0:00 gas meter: 10000m3 0:20 gas meter: 10030m3 calc delta, multiply by costs per m3, display usage …

> [@Electricity buy/sell logic](https://discourse.nodered.org/t/electricity-buy-sell-logic/65841/4):
>
> I do something very similar here in Australia with a company called Amber electric They expose us to the Wholesale spot price market on a 5 minute basis with 30 minute settlement periods. We have a large Solar and battery system and arbitrage the grid with the batteries. During winter (now in Australia) we actually change to a fixed price provider and then in Spring Change back to Amber again Basically their API provides pricing data similar to what you have outlined. What i did was work o…

> [@Energy calculation](https://discourse.nodered.org/t/energy-calculation/11851):
>
> 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 e…

I think there are many more. I searched just for "cost" but "energy cost" probably better.

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [11 August 2022 19:56 UTC](https://discourse.nodered.org/t/cost-calculation/66321/5 "2022-08-11T19:56:18Z")

</div>

> [@swanside](#):
>
> This is my current flow.

Unfortunately your flow includes modbus & influx nodes which are not included by node-RED by default. Which means that anyone trying to help you would need to install & config those 4 extra nodes to load your flow (which we don't like doing on our 'live' systems!)  
You are much more likely to get support if you removed them from your flow and replaced them with inject & debug nodes, to simulate the inputs & outputs.

---

<div class="post-metadata">

### Author: ![Patrick\_UK](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Patrick\_UK](https://discourse.nodered.org/u/Patrick_UK)
#### Post date: [12 August 2022 06:40 UTC](https://discourse.nodered.org/t/cost-calculation/66321/6 "2022-08-12T06:40:50Z")

</div>

In my feed from my meter I get a cumulative value contained within the payload as well as the current usage. Do you have a sample of what data you are receiving?

---

<div class="post-metadata">

### Author: ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)
#### Post date: [12 August 2022 07:28 UTC](https://discourse.nodered.org/t/cost-calculation/66321/7 "2022-08-12T07:28:59Z")

</div>

Thanks for the, a couple are based on getting the API from the supplier, but your idea has me going in another direction. Will report back later today. Thank you

---

<div class="post-metadata">

### Author: ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)
#### Post date: [12 August 2022 07:29 UTC](https://discourse.nodered.org/t/cost-calculation/66321/8 "2022-08-12T07:29:49Z")

</div>

Thanks for that, I will reconfigure with injects and edit the original post, once I have worked out what I am exactly after.  
Thank you

---

<div class="post-metadata">

### Author: ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)
#### Post date: [12 August 2022 07:58 UTC](https://discourse.nodered.org/t/cost-calculation/66321/9 "2022-08-12T07:58:28Z")

</div>

This is the Modbus table of information available.  
What meter do you have please? If you have a working solution that gives me the Kwh over an hour and 24 hours and I can compare daily, it maybe better for me to get a meter the does just that. Thank you

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d25b98c5732421d84e7dd69b7ed3469e392522db.png)

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [12 August 2022 10:52 UTC](https://discourse.nodered.org/t/cost-calculation/66321/10 "2022-08-12T10:52:36Z")

</div>

So a couple of things - based on what you have asked - we would assume you are on a flat rate electricity tarriff ? 0r is it a TOU tarriff - and hence you would need to monitor WHEN the usage occurred and total within those periods ?

What level of granularity do you want (minute, second etc ?)

What is your meter able to provide and process ?

I.e. does the data stream from it not include total kwh today ?

---

<div class="post-metadata">

### Author: ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)
#### Post date: [12 August 2022 11:14 UTC](https://discourse.nodered.org/t/cost-calculation/66321/11 "2022-08-12T11:14:13Z")

</div>

Yeh I am on a flat rate, but the end project is to monitor the consumption of a Hot Tub via an energy meter. So in current conditions it will bring the heater on about 3 times a day which is a 3Kw heater, it can run for 10 - 30 minutes depending on the outside air temperature, so I just want to plot a history, over a day, week and say a month.  
Once I have how many Kwh it used over the last 24h period, I can manually multiply this by 28.175 pence per Kwh so it will give me a running cost of the Hot Tub.  
My Modbus can give me the below data, unfortunately it cant give me cumulative data, so I need a way of adding up the Kwh it is using. If not I will look at a different type of meter with more options

Phase voltage V1  
Phase current I1  
Split phase active powerp1  
System active power psum  
Split phase reactive power Q1  
System reactive power qsum  
Split phase apparent power S1  
System apparent power ssum  
Split phase power factor PF1  
System power factor pf  
Current total active power  
Current rate 1 active power  
Current total reactive power  
Current rate 1 reactive power  
Last month demand  
Last two month demand

---

<div class="post-metadata">

### Author: ![Patrick\_UK](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Patrick\_UK](https://discourse.nodered.org/u/Patrick_UK)
#### Post date: [12 August 2022 16:57 UTC](https://discourse.nodered.org/t/cost-calculation/66321/12 "2022-08-12T16:57:37Z")

</div>

My solution is the feed from the electricity / gas meters for the whole usage not for a particular appliance.  
Looking at one of the examples given above they have used a contrib node aggregator, maybe that might be an option if you don't want to store in a database and then calculate the daily total?? Link to take a look : [node-red-contrib-aggregator (node) - Node-RED (nodered.org)](https://flows.nodered.org/node/node-red-contrib-aggregator)

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [12 August 2022 19:58 UTC](https://discourse.nodered.org/t/cost-calculation/66321/13 "2022-08-12T19:58:47Z")

</div>

How are you converting power data (kW's) to energy (kWh's)?  
If it's not something that you have considered, I wrote a contrib node to do the calculation.  
See [node-red-contrib-watt2kwh (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-watt2kwh)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 August 2022 20:47 UTC](https://discourse.nodered.org/t/cost-calculation/66321/14 "2022-08-12T20:47:11Z")

</div>

You might well be better to store the raw data in influx and then use influx queries to sum the values for you, or to use the Integrate function in influx if appropriate, depending on what the raw data is.

---

<div class="post-metadata">

### Author: ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)
#### Post date: [13 August 2022 06:37 UTC](https://discourse.nodered.org/t/cost-calculation/66321/15 "2022-08-13T06:37:57Z")

</div>

Thansk Paul.  
That is something I need, Thanks

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [12 October 2022 06:38 UTC](https://discourse.nodered.org/t/cost-calculation/66321/16 "2022-10-12T06:38:41Z")

</div>

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