Cost Calculation

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.

[{"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}]

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

Trust me I tried the search before hand and thought hopefully somebody will remember it of know the solution. But thanks anyway
image

not looked at any of these but:

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

1 Like

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.

2 Likes

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?

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

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

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

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 ?

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

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)

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

1 Like

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.

1 Like

Thansk Paul.
That is something I need, Thanks