Guys, I have an MQTT message that comes in from a Arduino to my Node-red. This String when received is essentially a binary representation of the state of output pins on the Arduino - so i might see a value like 176, 160, 200 etc - Each of these cases represents a different state (on or off) of a group of 8 pins on my Arduino.
I am currently getting this info and using the change node to interpret these and subsitutue plain english for display on my dashboard. All works well.
These values come in once per minute - regardless of whether or not they have changed - so i could just see the same number over and over again during the day
I would now like to try and record when i see a transition of values - lets say 176 represents Solar On, Circulating Pump on and 160 represents Solar on No Circulating pump (house may have overheated for instance)
So i would like to track the last value received, compare that to the current value and if there is a change then store that information to give me essentially runtimes for pumps etc etc
My first stage is to detect the transition - would a reasonable approach be to set a global variable that represents the last received value and then compare that, if there is a change i could then write the relevant information to a DB of some type ? This would essentially be time sequence data when interpreted - so Solar on at 9:30, Solar off at 11:30 etc - would sqlite be the right engine for this ? There would be at most 7 entities to track and maybe 100 transitions (max) in the space of a day.
In Node-RED 0.19 you have persistent context meaning flow and global variables can persist across restarts. Since it doesn't represent a lot of data you could probably use this to store instead of a database.
As @dceejay suggests, an RBE node will do that for you, removing repeated values so will only get a message when it changes.
What do you want to do with the time series data? If you want to keep it and then later analyse it, view it on a graph or whatever then I suggest influxdb for saving the data and grafana for viewing it. There are inflluxdb nodes for writing to an influx db that make it easy to do, though there is a learning curve to get to grips with the concepts of influx.
Thanks Colin and @dceejay - so many cool nodes out there - so little time to find them all !!
Eventually i would like to report/graph on these state changes i.e. boiler on at 3AM until 4:30AM and be able to get elapsed run times for solar etc and then calculate how much electricity and gas we are using for the amount of heat output etc.
Do you think Influx is a good fit for this or would i be better off with something simpler like MySQL etc ?? I am running this on a Virtual machine so resources are not really an issue
I don't think influx is more difficult, it is just different. In fact in node-red getting the data into it is simpler than mysql. However, when it comes to getting data out of it to perform calculations I don't know, as I have only used it with Grafana for getting charts out. I haven't done any DIY interrogation of the data. I don't think it is difficult however. If you are already familiar with mysql or sqlite then that may be a better approach if you won't want to plot real time charts showing the data.
Thanks Colin, will have a look - may pump the data to both in parallel so i can play with what i know - MYSQL and then try and work out Grafana and Influx.