Hello everyone,
I’m new working with Losant and am stuck at a problem, I’d think should be easy to solve.
I have multiple devices with 3 sensors each. Every few hours, they upload the sensorreadings of the passed time to a platform which I can access through an API. Unfortunately, I need to get the data column by column (each sensor at a time). I update my losant-devices and get the next cloumn. The resulting data looks like this:
Now, after updating the sensor-readings, I wanted to calculate the 2 missing attributes. E.g. if value1>value2, value5 = “ok”. Or value4=1-(value1/value2).
I thought I could iterate over the datapoints, starting by the latest, update each entry until I reach an entry that has value4 and value5 already set, but I cant figure out how. The “Data: Time Series” and “Data: Gauge” nodes only fetch one attribute at a time and I need all 5. I hope you can help me
![:frowning: :frowning:](https://emoji.discourse-cdn.com/twitter/frowning.png?v=12)
If you need additional info, please let me know.
Hi @Tamino_Schorcht and welcome to the Losant forums!
I’m working on an example of how to accomplish this. I’ll get back with you shortly!
I’m unsure of the considerations that need to be made in your initial workflow that fetches and formats this data, so I’m going to approach this from the perspective of a downstream process or a separate workflow that’s triggered after this data is in place.
In our next release, the Data: Time Series and Data: Gauge Query nodes are being updated to return multiple attributes.
In the meantime, for a single device, you can use the Losant API Node with the Device: Get State endpoint, which returns the most recent state reports for a given device. This can be set to return all state entries since a specified time value (since
, in epoch), or a specified number of the most recent entries (limit
). If you have a predictable number of device state reports (unique timestamp values) after each run of the initial workflow, you could use that number as your limit
value. Alternatively, you could utilize workflow storage to maintain an epoch time value from the last execution to use as your since
parameter.
For multiple devices, you can use the Losant API Node with the Data: Time Series Query endpoint. This would require formatting a request body in JSON format.
Given these values, you should be able to perform the calculations in question (using conditional block helpers or a Function Node formula) and then, within a loop, use the Device: Update Node to populate the remaining two attributes.
Please let us know if you have any further questions!
1 Like
Thank you for your response, it was very helpful! I was able to implement a solution using the Losant API Node with the Data: Time Series Query and a following Function Node as you suggested!
Your approach of a downstream process utilizing a seperate workflow was exactly what I was trying to achieve and it is great to hear, that this more complex approach won’t be necessary anymore, once the Data:… Nodes are updated ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=12)