'How to use data in a timerseries update message

I use a 'New update timeseries' widget to update a Temperature value. How can I extract the Temperature value from the Timeseries update message? f.e. I want to create a new value: msg.temperature2 = msg.temperature + 5

In the rule chain I intercept the update timeseries message with a "Timeseries update

Message: { "timeseries": [{ "ts": 1651399784349, "values": { "Temperature": 30 } }] }

Images: Rule chain Transformation script-test script function



Solution 1:[1]

It's just a matter of referencing the value correctly. See below for example.

let msg = {
  "timeseries": [{
    "ts": 1234,
    "values":{
      "Temperature": 30
    }
  }]
}

// The code
var newMsg = msg
newMsg.timeseries[0].values.Temperature2 = newMsg.timeseries[0].values.Temperature + 5

// Remove log, uncomment return
console.log({ "msg": newMsg, "metadata": {} })
//return { "msg": msg, "metadata": {} }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JacksonB