# Power consumption of a heatpump

**URL:** <https://discourse.nodered.org/t/power-consumption-of-a-heatpump/67978>\
**Category:** General\
**Created:** [20 September 2022 14:12 UTC](https://discourse.nodered.org/t/power-consumption-of-a-heatpump/67978 "2022-09-20T14:12:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nilpferd](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@Nilpferd](https://discourse.nodered.org/u/Nilpferd)\
**Post date:** [20 September 2022 14:12 UTC](https://discourse.nodered.org/t/power-consumption-of-a-heatpump/67978/1 "2022-09-20T14:12:11Z")

</div>

Hello

My heat pump sends once a day the accumulated power consumption. I want to write the power consumption of the last three days in a bar chart.  
So first of all I have to subtract the value from two days ago from the value from yesterday to get the daily consumption and store this fro three days. I don`t need to store all values in node red because I send them to KNX and a TWS also.

Can you help me how to subract the value 2 days ago from the value yesterday?

Best Regards  
Erwin

---

<div class="post-metadata">

**Author:** ![struland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/struland/32/58587_2.png) [@struland](https://discourse.nodered.org/u/struland)\
**Post date:** [20 September 2022 17:04 UTC](https://discourse.nodered.org/t/power-consumption-of-a-heatpump/67978/2 "2022-09-20T17:04:25Z")

</div>

Hello,  
first I would use the Parser "csv" and the "write file" node to store the data in a csv file.  
From there I would write a function to process the data.

```auto
PSEUDO CODE
length = getNumberOfRowsInCSVFile()
result = []
for i=0 to length do
   diff = valueOfLine[i]-valueOfLine[i-1]
   result.append({
      day: dateOfLine[i],
      value: diff}
    )

msg.payload = result
return msg

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [20 September 2022 19:07 UTC](https://discourse.nodered.org/t/power-consumption-of-a-heatpump/67978/3 "2022-09-20T19:07:10Z")

</div>

You can store the last 3 days in context storage with the last accumulated reading, then every day you get a new reading create a chart .

The inject simulates an input of accumulated value for testing, just connect to your daily power consumption input. Will take 3 inputs to fully build chart.

Change 1st rule in change node to increase number of days to display.

```auto
[{"id":"bb6ff273.d3e588","type":"inject","z":"9790f611.6dd06","name":"random rise","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$sum([$flowContext(\"heatpump.previous\")]) + $ceil($random()*20) + 5","payloadType":"jsonata","x":140,"y":640,"wires":[["5fb3fdbb.e5daec","d339ef33.7e1088"]]},{"id":"5fb3fdbb.e5daec","type":"debug","z":"9790f611.6dd06","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":260,"y":580,"wires":[]},{"id":"d339ef33.7e1088","type":"change","z":"9790f611.6dd06","name":"","rules":[{"t":"set","p":"display","pt":"msg","to":"3","tot":"num"},{"t":"set","p":"now","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"[$append(\t [$flowContext(\"heatpump.last3\")],\t [\t {\t \"timestamp\": $now(),\t \"value\": $$.payload - $sum([$flowContext(\"heatpump.previous\")])\t }\t ]\t)[[-$$.display..-1]]]","tot":"jsonata"},{"t":"set","p":"heatpump.last3","pt":"flow","to":"payload","tot":"msg"},{"t":"move","p":"now","pt":"msg","to":"heatpump.previous","tot":"flow"},{"t":"set","p":"payload","pt":"msg","to":"[\t {\t \"labels\": [$$.payload.timestamp.$split($, \"T\")[0]],\t \"data\": [\t [\t $$.payload.value\t]\t ],\t \"series\":[\"Power consumption\"]\t }\t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":640,"wires":[["363b4c50.e9ceec","7ce5a93d.95db28"]]},{"id":"363b4c50.e9ceec","type":"debug","z":"9790f611.6dd06","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":640,"wires":[]},{"id":"7ce5a93d.95db28","type":"ui_chart","z":"9790f611.6dd06","name":"","group":"2d4fe667.28f8ba","order":11,"width":0,"height":0,"label":"chart","chartType":"bar","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":590,"y":680,"wires":[[]]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":1,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Nilpferd](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@Nilpferd](https://discourse.nodered.org/u/Nilpferd)\
**Post date:** [21 September 2022 09:46 UTC](https://discourse.nodered.org/t/power-consumption-of-a-heatpump/67978/4 "2022-09-21T09:46:38Z")

</div>

Hello E1cid

thanks a lot. With the random rise it ist working fine and does exactly what I need. Doesnot matter when I cannot understand the expressions.

Still one problem exists: I don`t know where to connect the KNX device node from which the data will be recvd.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 September 2022 10:39 UTC](https://discourse.nodered.org/t/power-consumption-of-a-heatpump/67978/5 "2022-09-21T10:39:19Z")

</div>

The KNX device should connect where random rise connects, it should feed in the accumulated power consumption once a day and needs to be an integer.

[edit]  
The first expression takes the stored array (last3) and adds the new object, containing the time and value., it then removes the first array item if greater than 3 or msg.display.

The second expression creates the payload array for the bar chart.

---

<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:** [20 November 2022 10:39 UTC](https://discourse.nodered.org/t/power-consumption-of-a-heatpump/67978/6 "2022-11-20T10:39:58Z")

</div>

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