Graph data from/to database: making it non-volatile

No. (Apart from setting the window wider which then has consequences on amount of data in memory etc. )

Or database plus queries as mentioned

If you want to do more sophisticated graphs with long term persistence, scrolling, zooming etc then the easiest way (I believe) is to use influxdb with grafana. Many node red users use that.

1 Like

Yep, my suggestion is unnecessary complicated, is enough to use a Delay node configured for rate limit and I have to correct myself, you won’t lag behind

No it isn't. The data is saved to RAM after each message. You add your desired 'sd card' save interval in the node config.
Example; If you set the interval to 60 minutes, it will save 60 minutes worth of chart data to RAM, then save it to disk and flush the RAM data, and repeat. So it only makes a 'sd card' write every 60 minutes.
Also, the saved data would only be used to restore chart data after a system reboot, crash or flow re-deployment.

You can also dictate where the data is written to in the node config, so you could save it to a cheap USB stick inserted in your raspberry.

persist

Paul

2 Likes

Thank you, @Paul-Reed .
Tested all the methods above in this thread except database.
Concluded that usage of “persist” nodes is the most generic, resource saving, reliable, and simple method for making graphs non-volatile.

2 Likes

Don't know if you are aware (I wasn't initially) but you can use the same chart data file for a number of data sources.
For example, if you are charting 'house power', 'solar power & 'diverted power', you can use the same data file for all 3 sources, you don't need 3 separate data files, just one, and let the persist nodes share it.

1 Like

My concern was whether the persist can treat separated topics in a single file. This is why it took me some time to test different approaches.
Apparently, persist is pretty sophisticated data save/restore method. A little pity, its documentation does not describe all the goodies well enough.
Thank you for another good hint.

Update: keeping different inputs in one persist file works well. Reading from one persist file to different charts doesn’t work out of the box: all the key values are flushed into all charts. Data from reading persist need to be filtered and separated to charts. Or keep in separated persist files. All keys of the same chart restore the data properly.

The interval of saving data is in seconds, not in minutes (thanks to github).

2 Likes

I’m sure the author of the node would be happy to receive a pull request which improves the documentation

1 Like

Hi, i have an chart, which is saved to file. everthin worsk fine, but i dont know how to create graph with value and time only. my grpah generate full of msg.topic. can you help me please? here is my nodes

[{"id":"185dbfb1.489f88","type":"subflow","name":"MicrowaveChart","info":"","category":"","in":[{"x":20,"y":40,"wires":[{"id":"d81aab3b.dd17e8"}]}],"out":[{"x":600,"y":60,"wires":[{"id":"4443fa24.ae0ffc","port":0}]}],"env":[],"color":"#DDAA99"},{"id":"c89842bc.24aad","type":"file","z":"185dbfb1.489f88","name":"chart","filename":"homie/homey-5ac5f38e42b2c4296e150d77/microwaveplug/measure-power","appendNewline":true,"createDir":true,"overwriteFile":"true","x":510,"y":20,"wires":[[]]},{"id":"413659f1.91a29","type":"file in","z":"185dbfb1.489f88","name":"chart","filename":"homie/homey-5ac5f38e42b2c4296e150d77/microwaveplug/measure-power","format":"utf8","sendError":true,"x":390,"y":60,"wires":[["4443fa24.ae0ffc"]]},{"id":"55a78cfc.45e8fc","type":"json","z":"185dbfb1.489f88","name":"","property":"payload","action":"","pretty":true,"x":390,"y":20,"wires":[["c89842bc.24aad"]]},{"id":"ea685ecc.ce88c8","type":"switch","z":"185dbfb1.489f88","name":"Load data","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"load","vt":"str"},{"t":"eq","v":"load","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":260,"y":40,"wires":[["55a78cfc.45e8fc"],["413659f1.91a29"]]},{"id":"d81aab3b.dd17e8","type":"function","z":"185dbfb1.489f88","name":"LoadSave","func":"var strSafe=msg.topic;\nif(strSafe)\n{\n    strSafe=strSafe.replace(/[^a-z0-9]/gi, '_').toLowerCase();\n    var loaded=context.get(strSafe)||0;\n    msg.filename =\"/home/pi/charts/\"+strSafe+\".dat\";\n    //node.warn(loaded);\n    if(0===loaded)\n    {\n        //load chart!! \n        msg.payload=\"load\";\n        context.set(strSafe,1);\n        \n        //node.warn(\"Loading \" +strSafe);\n    }\n    else\n    {\n        //node.warn(\"Writing \" +strSafe);\n    }\n    return msg;    \n}\nreturn null;\n\n","outputs":1,"noerr":0,"x":120,"y":40,"wires":[["ea685ecc.ce88c8"]]},{"id":"4443fa24.ae0ffc","type":"json","z":"185dbfb1.489f88","name":"json","property":"payload","action":"","pretty":true,"x":510,"y":60,"wires":[[]]},{"id":"f5695153.605d9","type":"ui_chart","z":"dc26b425.e05be8","name":"consumption 6d","group":"1b2289fc.a46216","order":7,"width":5,"height":3,"label":"6d {{payload}}","chartType":"line","legend":"false","xformat":"dd HH:mm","interpolate":"bezier","nodata":"consumption 6d","dot":false,"ymin":"","ymax":"","removeOlder":"6","removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#ffaa00","#ffb5af","#5e30eb","#ffc677","#d357fe","#d29d00","#444444","#fffc41","#004d65"],"useOldStyle":false,"outputs":1,"x":400,"y":730,"wires":[["9ce2549b.d8c968"]]},{"id":"9ce2549b.d8c968","type":"subflow:185dbfb1.489f88","z":"dc26b425.e05be8","name":"","env":[],"x":620,"y":730,"wires":[["f5695153.605d9"]]},{"id":"f66891e2.1142a8","type":"ui_gauge","z":"dc26b425.e05be8","name":"microwaveplug power","group":"1b2289fc.a46216","order":5,"width":3,"height":1,"gtype":"gage","title":"","label":"W","format":"{{value}}","min":0,"max":"2000","colors":["#00b500","#fecb3e","#e32400"],"seg1":"50","seg2":"90","x":420,"y":670,"wires":[]},{"id":"7cf836cf.9c65c","type":"mqtt in","z":"dc26b425.e05be8","name":"microwaveplug/measure-power","topic":"homie/homey-5ac5f38e42b2c4296e150d77/microwaveplug/measure-power","qos":"2","datatype":"auto","broker":"f18ffc79.bc2648","x":130,"y":670,"wires":[["f66891e2.1142a8","f5695153.605d9"]]},{"id":"1b2289fc.a46216","type":"ui_group","z":"","name":"Microwave","tab":"57d4c334.8436d4","order":6,"disp":true,"width":"5","collapse":false},{"id":"f18ffc79.bc2648","type":"mqtt-broker","z":"","name":"Homey MQTT","broker":"192.168.1.4","port":"1883","tls":"","clientid":"","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""},{"id":"57d4c334.8436d4","type":"ui_tab","z":"","name":"Energy","icon":"fa-1x fa-bolt","order":3,"disabled":false,"hidden":false}]

and subflow:

[{"id":"413659f1.91a29","type":"file in","z":"185dbfb1.489f88","name":"chart","filename":"homie/homey-5ac5f38e42b2c4296e150d77/microwaveplug/measure-power","format":"utf8","sendError":true,"x":390,"y":60,"wires":[["4443fa24.ae0ffc"]]},{"id":"ea685ecc.ce88c8","type":"switch","z":"185dbfb1.489f88","name":"Load data","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"load","vt":"str"},{"t":"eq","v":"load","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":260,"y":40,"wires":[["55a78cfc.45e8fc"],["413659f1.91a29"]]},{"id":"d81aab3b.dd17e8","type":"function","z":"185dbfb1.489f88","name":"LoadSave","func":"var strSafe=msg.topic;\nif(strSafe)\n{\n    strSafe=strSafe.replace(/[^a-z0-9]/gi, '_').toLowerCase();\n    var loaded=context.get(strSafe)||0;\n    msg.filename =\"/home/pi/charts/\"+strSafe+\".dat\";\n    //node.warn(loaded);\n    if(0===loaded)\n    {\n        //load chart!! \n        msg.payload=\"load\";\n        context.set(strSafe,1);\n        \n        //node.warn(\"Loading \" +strSafe);\n    }\n    else\n    {\n        //node.warn(\"Writing \" +strSafe);\n    }\n    return msg;    \n}\nreturn null;\n\n","outputs":1,"noerr":0,"x":120,"y":40,"wires":[["ea685ecc.ce88c8"]]},{"id":"4443fa24.ae0ffc","type":"json","z":"185dbfb1.489f88","name":"json","property":"payload","action":"","pretty":true,"x":510,"y":60,"wires":[[]]},{"id":"c89842bc.24aad","type":"file","z":"185dbfb1.489f88","name":"chart","filename":"homie/homey-5ac5f38e42b2c4296e150d77/microwaveplug/measure-power","appendNewline":true,"createDir":true,"overwriteFile":"true","x":510,"y":20,"wires":[[]]},{"id":"55a78cfc.45e8fc","type":"json","z":"185dbfb1.489f88","name":"","property":"payload","action":"","pretty":true,"x":390,"y":20,"wires":[["c89842bc.24aad"]]}]