Hi all,
Goal:
For multiple datasets, I want to go through all orders and find the latest filled order (where “filled: 1”). Then from that specific order, I want to take the “sum”, then add it to the next datasets sum value for as long as there might be datasets.
I receive the following JSON structure from a REST call:
{
"date": "2024-12-19T10:54:28.116Z",
"data": [
{
"active": true,
"date": "2024-12-16T21:55:15.022Z",
"status": 0,
"orders": [
{
"orderNo": 1,
"orderId": 1944875176,
"amount": 15.48,
"sum": 15.48,
"filled": 1,
"dateFilled": "2024-12-16T21:55:15.981Z"
},
{
"orderNo": 2,
"orderId": 1944976052,
"amount": 15.24,
"sum": 30.72,
"filled": 1,
"dateFilled": "2024-12-16T22:37:53.530Z"
},
{
"orderNo": 3,
"orderId": 1945133844,
"amount": 16.75,
"sum": 47.47,
"filled": 1,
"dateFilled": "2024-12-16T23:35:39.312Z"
},
{
"orderNo": 4,
"orderId": 1945243976,
"amount": 18.42,
"sum": 65.89,
"filled": 1,
"dateFilled": "2024-12-17T00:07:56.709Z"
},
{
"orderNo": 5,
"orderId": "",
"amount": 57.58,
"sum": 123.47,
"filled": 0
},
{
"orderNo": 6,
"orderId": "",
"amount": 57.58,
"sum": 181.05,
"filled": 0
}
],
"createdAt": "2024-12-16T21:55:15.024Z",
"updatedAt": "2024-12-16T21:55:15.024Z"
}
]
}
In this example, the result should be 65.89. If there were more entries with results X and Y, my overall result should be 65.89 + X +Y.
I am okay with finding a specific set in the JSON like this:
value_template: "{{ value_json.0.data[0].orders[3].sum }}"
But I have absolutely no clue how to iterate through this while summing up. Can anyone help out?
Thanks!