Multiple counters on different modes

Hi guys,

Here I am again, as I was afraid already before trying to solve this issue..
Last time the help and guidance was great, so I'll give it 1 more shot on my issue.

I spent again a few evenings trying to get my mind around the below flow, but all I did is made some spaghetti on the wiring of the nodes.. Although it does partly seem to work now.

Thing is, I believe there should be a 100 times easier solution, or perhaps not without some coding into a function node?

What I am trying to do:
Input is the states of my heat pump at home. When it is in mode 2-3-4 or 5, I want to count the heat energy from another input and store it per mode. This input itself keeps counting up nevertheless the status (unless 1, that is " Stop" ). I am now that far that I store the start number into a context flow., together with the end number, and deduct this from each other. Just a few issues:
On start-up it gives an error due to no value(s) yet. Only once, because then the trigger is waiting for a reset.
I cannot seem to figure out how to count all single run values into a total value (once done I will also read into the function to store data better).
It got very messy with all the connections, is there an easier way to do this which I overlooked?

Just a push into the right direction would be awesome already!

Thanks a lot!

[{"id":"13936b55.057715","type":"trigger","z":"e48134ce.946038","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1020,"y":1720,"wires":[["16610f01.96e4a1"]]},{"id":"5e17cc5d.a00384","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1720,"wires":[["13936b55.057715"]]},{"id":"16610f01.96e4a1","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"swwtstart","pt":"flow","to":"payload.totalheatenergy","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1250,"y":1720,"wires":[[]]},{"id":"a72fdf81.4ca46","type":"change","z":"e48134ce.946038","name":"SWW calc T","rules":[{"t":"set","p":"payload.swwtstart","pt":"msg","to":"swwtstart","tot":"flow"},{"t":"set","p":"payload.swwt","pt":"msg","to":"(payload.totalheatenergy - payload.swwtstart)*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":1760,"wires":[["89f5ead9.0593d8"]]},{"id":"89f5ead9.0593d8","type":"join","z":"e48134ce.946038","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":1470,"y":1760,"wires":[["51aa100e.6955d"]]},{"id":"a224a5eb.1091e8","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1820,"wires":[["a9be45c3.599898"]]},{"id":"c814a831.4d5978","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"heatingtstart","pt":"flow","to":"payload.totalheatenergy","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":1820,"wires":[[]]},{"id":"f01d4895.76c168","type":"change","z":"e48134ce.946038","name":"Heating calc T","rules":[{"t":"set","p":"payload.heatingtstart","pt":"msg","to":"heatingtstart","tot":"flow"},{"t":"set","p":"payload.heatingt","pt":"msg","to":"(payload.totalheatenergy - payload.heatingtstart)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":1860,"wires":[["89f5ead9.0593d8"]]},{"id":"525a2e0e.c2985","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1920,"wires":[["87382041.5a83c"]]},{"id":"87382041.5a83c","type":"trigger","z":"e48134ce.946038","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1020,"y":1920,"wires":[["26ac73e8.7581fc"]]},{"id":"26ac73e8.7581fc","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"coolingtstart","pt":"flow","to":"payload.totalheatenergy","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":1920,"wires":[[]]},{"id":"d33d5ee5.7f7da","type":"change","z":"e48134ce.946038","name":"Cooling calc T","rules":[{"t":"set","p":"payload.coolingtstart","pt":"msg","to":"coolingtstart","tot":"flow"},{"t":"set","p":"payload.coolingt","pt":"msg","to":"(payload.totalheatenergy - payload.coolingtstart)*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":1960,"wires":[["89f5ead9.0593d8"]]},{"id":"872db087.9dbea","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":2020,"wires":[["2273432e.4309bc"]]},{"id":"2273432e.4309bc","type":"trigger","z":"e48134ce.946038","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1020,"y":2020,"wires":[["f57142a0.6a561"]]},{"id":"f57142a0.6a561","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"defrosttstart","pt":"flow","to":"payload.totalheatenergy","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":2020,"wires":[[]]},{"id":"5b265318.ed4bfc","type":"change","z":"e48134ce.946038","name":"Defrost calc T","rules":[{"t":"set","p":"payload.defrosttstart","pt":"msg","to":"defrosttstart","tot":"flow"},{"t":"set","p":"payload.defrostt","pt":"msg","to":"(payload.totalheatenergy - payload.defrosttstart)*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":2060,"wires":[["89f5ead9.0593d8"]]},{"id":"86ebed86.23e19","type":"comment","z":"e48134ce.946038","name":"Calculate thermal energy per run per mode","info":"","x":900,"y":1680,"wires":[]},{"id":"a9be45c3.599898","type":"trigger","z":"e48134ce.946038","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1020,"y":1820,"wires":[["c814a831.4d5978"]]},{"id":"75db2867.909cf8","type":"trigger","z":"e48134ce.946038","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1020,"y":1760,"wires":[["a72fdf81.4ca46"]]},{"id":"e40cf164.35702","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1760,"wires":[["75db2867.909cf8"]]},{"id":"2c32ca90.76cd06","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1860,"wires":[["bee62ff0.efd9"]]},{"id":"bee62ff0.efd9","type":"trigger","z":"e48134ce.946038","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1020,"y":1860,"wires":[["f01d4895.76c168"]]},{"id":"78d2e3d5.f2c05c","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1960,"wires":[["4403ca52.2913f4"]]},{"id":"4403ca52.2913f4","type":"trigger","z":"e48134ce.946038","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1020,"y":1960,"wires":[["d33d5ee5.7f7da"]]},{"id":"f5a7f392.f7e0e","type":"change","z":"e48134ce.946038","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":2060,"wires":[["41b59be0.e23ff4"]]},{"id":"41b59be0.e23ff4","type":"trigger","z":"e48134ce.946038","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1020,"y":2060,"wires":[["5b265318.ed4bfc"]]},{"id":"aee1976c.ac49b8","type":"switch","z":"e48134ce.946038","name":"Check operating mode","property":"mitsubishi.operation_mode","propertyType":"msg","rules":[{"t":"eq","v":"Stop","vt":"str"},{"t":"eq","v":"Hot Water","vt":"str"},{"t":"eq","v":"Heating","vt":"str"},{"t":"eq","v":"Cooling","vt":"str"},{"t":"eq","v":"Freeze stat","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":560,"y":1760,"wires":[["5e17cc5d.a00384","a224a5eb.1091e8","39165ba7.0370e4","525a2e0e.c2985","872db087.9dbea","75db2867.909cf8","bee62ff0.efd9","4403ca52.2913f4","41b59be0.e23ff4"],["13936b55.057715","a224a5eb.1091e8","525a2e0e.c2985","872db087.9dbea","e40cf164.35702","bee62ff0.efd9","4403ca52.2913f4","41b59be0.e23ff4"],["5e17cc5d.a00384","525a2e0e.c2985","872db087.9dbea","a9be45c3.599898","75db2867.909cf8","2c32ca90.76cd06","4403ca52.2913f4","41b59be0.e23ff4"],["5e17cc5d.a00384","a224a5eb.1091e8","872db087.9dbea","87382041.5a83c","75db2867.909cf8","bee62ff0.efd9","78d2e3d5.f2c05c","41b59be0.e23ff4"],["5e17cc5d.a00384","a224a5eb.1091e8","525a2e0e.c2985","2273432e.4309bc","75db2867.909cf8","bee62ff0.efd9","f5a7f392.f7e0e","4403ca52.2913f4"]]}]

I can't really follow what you are trying to do but looking at all the 'reset' nodes, they are all configured incorrectly; they are set to 'reset' with a type of number, should be string, hence the red outline.

Thank you for the reply! You are right.. Nevertheless, the reset does seem to work even though it is set wrong. But the result is not there yet anyhow.

I'll try to explain a bit better:
Input is from MQTT from 2 devices. 1 device has 5 different statussen, lets call it 1 to 5.
1 = stop, but for 2-5 I want to have different counters counting the following:
The 2nd device is a heat meter which continuesly keeps counting nevertheless the status of the first device.
E.g.: Each time it runs in status 2, I want it to count the total heat energy gained within this status, and add it to a total. So that I end up with individual cummulative counters for statusses 2 to 5. And later also add separate monthly values to that, but that should not be too difficult.

So lets say in status 2 it starts with 300kWh on the device, and when it ends its 320. 20kWh to be added to a total.
Tomorrow another 20 is added but with different start and end values, so total will be 40.
In meanwhile also status 3 will be used and runs e.g. from 320 to 330, then switch back to status 2.

I believe the way I try to solve it is way too difficult, but I am thinking the function node with some javascript code is probably the easiest to solve this?

Is it a bit more clear like that?

Isn't it much easier to just store the date/time, device, status, value into a database (something like influx) ? Querying will be much easier, same for the calculations.

You cannot limitless store information into context variables without performance impact, especially when storing data over "months".

1 Like

I thought this amount of storage (4 values with a few times a day will be summed up with others) would be ok to do.
But you mention something.. I am storing it in Influx, but have no clue yet how to query it, and if I can get the right data together.
It are separate " measurements", but since it is timeseries database I guess you can query for the value most close by. No knowledge about that kind of things unfortunately.

There are good docs for influx. Make sure you look at the 1.8 version docs, not the 2.0. Assuming you are using version 1.8 of influx that is.

1 Like

Hi Colin,

Indeed using 1.8 of Influx. I'll read into it!
Makes sense to use the data which is already there instead of trying to calculate it in node red :slight_smile:

The Influxdb In node allows you to run queries on the database.

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