I’m assuming you’re doing this in a workflow? If so, I would use workflow storage to set and retrieve those values. This can be done using the Storage: Set Value and Storage: Get Value Nodes.
I managed to do this, have another question, to me the new keys look like global varables. Is there a way to put them as an attribute to devices and read them before writing them over with new values?
Is there a way to put them as an attribute to devices and read them before writing them over with new values?
It’s possible but I wouldn’t recommend it. Records written to the time series database count as billable payloads; on top of that, depending on how fast these operations are occurring, you may run into race conditions regarding when the state values are sent and if they have actually been written to the time series database by the next time you try to read.
to me the new keys look like global varables.
You can put a unique identifier in the key. For example, if this workflow is handling these previous values for multiple devices, and you have the ID of the device on the payload at a path of working.deviceId, you could set and retrieve that specific device’s value using a string template path of device-{{working.deviceId}}.