Calculate energy per heating session


I have boiler which is heated up by burning logs. I've just installed heat meter which I can read by RS-232, or actually meter transmits data periodically to Node-Red, such as current heating power (kW), inlet and outlet temperature (C), flow (m3/h) and total amount of produced energy (kWh). Total energy is increasing number from day 0, cannot be reset.

GOAL: To save & show last 5 heating sessions total amount of energy (kWh).


  • How to automatically decide, when new session is started (SOLVED: Flow <> 0)
  • Save previous "total" energy to database or file.
  • Visualize last 5 values

Easy way to see when heating is stopped is the flow. Boiler charging system pump will be stopped after heating sessions. Next time it will be started at new heating session.

Total produced heat could be something like "current total energy - total energy before current session". Another way could be by reading current power, but resolution might be problem. 5 mins is shortest upload interval I can set into heat meter

My function block or JavaScript knowledge is really low, sorry :frowning:. I don't have any database set up and running, could I save information into variable? Or file-based would nice, because there are power blackouts from time to time?

If intention is only for short term statistics and to display, then there is no need for database. By using presistable context memory you can store info about the sessions (in array) into global context and and it will be reachable anywhere anytime in Node-RED.

Actually collected data of every session can hold much more valuable info than just the produced energy so the more you collect, the more you can get out from later analysis. LIke session start time, session end time, relevant temperatures (as the main reason of heating after all) and similar.

For data collecting:
You will need to figure out best structure of your heating session object. Then by listening your incoming data, determine new session start. On that moment create new session object and start updating/adding data to that object. Same time you observe incoming data against session end. If session end is considered to happen, you store that object into collection and by keep listening incoming data be prepared to start new session.

If you already have some data collected than it is relevantly easy to present it by using ui-dashboard elements in the best suiting manner. Totally up to you what and how it will look like. Also you can present current state of your equipment, is there is currently session running and what are the current values of measurements.

To start with this kind of project, it takes just to be started. Put some nodes into your flow, add debug node to see what is coming in and start experimenting. Ask specific question when you stuck. Happy community is always ready to help :slight_smile:

1 Like

Have a look at this great video it shows how to setup a time series influx db database and visualise the data with Grafana. There is a link to a Raspberry pi image that works great. You would need to customise with a Node Red flow for you specific requirements

That's exactly what I'm using, with the data being generated & processed by node-RED.

I'm sure that you are already aware that to calculate energy(kWh), it is simply not a case of adding together the current heating power feed.
I use a calculation similar to the attached flow to convert power to energy. You will see that no matter how many times that you inject 3600 (watts) into the flow, in a 1 minute period the sum of the payloads should always equal 60 W/seconds (or 60 joules).
The payload value could then be saved to a database, or added to a running total using context.

Before loading the flow, you will need to add @BartButenaers node-red-contrib-interval-length node to your palette.

[{"id":"1de65c61.d67ab4","type":"interval-length","z":"31e18edc.98bdc2","format":"mills","bytopic":false,"minimum":"","maximum":"5","window":"","timeout":false,"msgTimeout":"","minimumunit":"msecs","maximumunit":"mins","windowunit":"msecs","msgTimeoutUnit":"msecs","reset":false,"startup":false,"msgField":"interval","timestampField":"timestamp","repeatTimeout":false,"name":"Calc time between readings","x":340,"y":770,"wires":[["84282466.b98bb8"],[]]},{"id":"4069e211.fc968c","type":"inject","z":"31e18edc.98bdc2","name":"Simulate 3.6kW/h (1W per second)","topic":"","payload":"3600","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":720,"wires":[["1de65c61.d67ab4"]]},{"id":"b61935d7.7731a8","type":"debug","z":"31e18edc.98bdc2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":700,"y":820,"wires":[]},{"id":"84282466.b98bb8","type":"function","z":"31e18edc.98bdc2","name":"convert power to energy","func":"var interval = msg.interval;\nvar power = msg.payload;\n\nvar energy = (interval*power)/3600000;\n\nmsg.payload = energy;\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":820,"wires":[["b61935d7.7731a8"]]}]
1 Like