Hi, I have several temperature sensors sending data to gauges on a dashboard, the data is put into a variable in a function node, what i want to do is write a file automatically at the right time of the month with all the temperatures on it, would this be easy to do ? any help appreciated.
It sounds easy enough, but exactly why do you want to do this?
Have you considered a simple database, eg SQLite?
You could save each temperature reading to the database as it arrives in Node-red (I think you are using MQTT?).
Then if you need a monthly summary for emailing or similar you can create it with an SQL query, outputting to a file.
I run Node-red, Mosquitto and SQLite together quite comfortably on a Raspberry Pi Zero 2 so certainly no problem on a beefier Pi such as the Pi 5.
A Pi is perfect for an mqtt broker and db server too since it can easily be left running 24/7
I have about 20 gauges and they are updated every 30 seconds so I would end up with a massive database really, a simple file once a month as a recording would suit me better I think, I am just not sure how to do it, I already have some nodes that send an email if the temperatures become out of range so maybe I could modify this ?
It is far easier and more resource efficient to use InfluxDB (or a similar Time Series DB) for this. That's what most of us do.
InfluxDB has the tools built right in to do all the work for you. Here is what I do:
Write the detailed environment data into a table. Each of my sensors outputs roughly once per minute.
I tell InfluxDB to only keep the details for one week.
I also tell InfluxDB to summarise the per-minute data to per hour data - turning each aggregated measurement into a max, min, and avg measure per hour.
I finally tell InfluxDB to keep the hourly data for 5 years.
I track a LOT of data in InfluxDB since it isn't only environmental data but also system performance data. I can dig out the DB sizes if you like but I used to run all of this and a lot more on a single Pi3b.
If you really don't want a database, you probably need to retain the readings in a persistent context variable until you write them to a file, whether you write the file once a month or write a new line every 30 seconds.
The context variable might be json format. I'm not really sure since as I said, I prefer to use a database.
There is a Write-file node which can be set to overwrite it's target file or to append to it if it exists.
Yes, it is free, at least for non-commercial support. Do yourself a favour and stick to the v1.8 style queries and don't use the v2 queries.
There is an article I wrote here on the forum (in FAQ's?) some years ago about the terminology and configuration that works well with Node-RED. It takes a little getting used to, especially if you know SQL. But once set up and running, you'll never need to touch it.
The other advantage is that - with the v1.8 queries - you can get full point-and-click query building and graphical output by also using InfluxDB with Grafana.
Hmm it may well be more efficient but I'd argue with the far easier bit.
While SQL databases are hardly straightforward, at least the INSERT SELECT & DELETE queries are logical.
I find Influx distinctly odd with it's measurements and buckets.
Hi Jbudd,
I am just looking at options really, I work for a charity and so I am classed as commercial I suppose so not looking to buy any licenses, Is the SQL database free to use ?
That's why I wrote the article. Done once and forgotten about until needed - which is pretty much never.
The important part is that you don't have to worry about getting aggregations right, a very simple query gives you aggregations over time periods. And if you use Grafana, it is even easier.
I see you are leaning towards Influx and it's a perfectly sound choice.
A quote from sqlite.org:
The core SQLite database software is in the public domain. No license is necessary to use SQLite or to build SQLite into your products.
Hi,
They both look a little over the top for what i need, I think I need to get my head around variables first and find out how they work in node-red, I have variables in my function flows and was told if I go to context data in the menu that the current values of the variables would be displayed but it shows nothing so I will have to post about that.