I want to have a table in dashobard, which shows the actual battery level of all sensors and devices. The information of the battery levels come in different times and I want to replace the previous value with the actual. My first thought was to use influxdb. But as I'm not interested in the history, this will be an overkill. Has anyone an idea, how I can feed the values into a table and show them at once in the dashboard?
Msg format is different. So previous of storage I have to convert it into format for the table anyway (e.g. topic=name, payload=value). Thats the easy thing. If I will use a flow variable, how can I replace an existing value of a specific topic with the new value.
I find the easiest way to handle this sort of data is with a function context storage as an object.
Like this
let batteries = context.get("batteries") ?? {} // If it doesn't already exist, initialise as object
batteries[msg.topic] = msg.payload
context.set("batteries", batteries)
// Now format msg.payload to feed to table (or in this case, a debug node)
msg.payload = batteries
return msg;
I prefer a function over Zenofmud's change node because it is easy to initialise the context store. Probably you can do that in a change node too.
Edit: Yup, very easy except you have to use flow. instead of context.