Hello All,
I’m still missing something about timeseries functionnality, and how to handle the current state of an item with time series properly.
Let me explain my case:
I’ve got a monthly energy consumption data from an energy provider, with historical value for month M-2, M-1, and current Month.
If I push data to timeseries, using the sendTimeSeries function, I’ve got the following result in influx DB
0 Conso_Month value 2387.121 2025-01-01T03:40:04.046Z
1 Conso_Month value 2666.551 2025-02-01T03:38:46.296Z
2 Conso_Month value 1284.02 2025-03-01T04:12:09.610Z
And when asking the rest persistence service:
rest/persistence/items/Conso_Month?
serviceId=influxdb&
&starttime=2024-09-15T14%3A11%3A49.935Z
&endtime=2025-03-31T18%3A11%3A49.902Z
&boundary=false
&itemState=true
{
"name": "Linky_Melody_Monthly_Conso_Month",
"datapoints": "3",
"data": [
{
"time": 1735686000000,
"state": "2387.121"
},
{
"time": 1738364400000,
"state": "2666.551"
},
{
"time": 1740783600000,
"state": "1284.0230000000001"
}
]
}
So everything is ok in this case.
But if I try to display the current state of the item, I’ve got a null value because i’ve don’t do any updateState call.
If now, I’ve update my code to make an updateState call:
updateKwhChannel(MONTHLY_GROUP, CHANNEL_CONSUMPTION, values.monthValue[idxCurrentMonth].value);
updateTimeSeries(MONTHLY_GROUP, CHANNEL_CONSUMPTION, values.monthValue, true);
I’ve now have the following result in InfluxDB
0 Conso_Month value 2387.121 2025-01-01T03:40:04.046Z
1 Conso_Month value 2666.551 2025-02-01T03:38:46.296Z
2 Conso_Month value 1284.02 2025-03-01T04:12:09.610Z
3 Conso_Month value 1284.02 2025-03-16T13:12:57.446Z
Line 2 is coming from the sendTimeSeries.
Line 3 is coming from the updateState call.
If I try to display the current value, I’ve got the correct result : 1284.02 which is the currentState.
But if I call the rest persistence service:
rest/persistence/items/Conso_Month?
serviceId=influxdb&
&starttime=2024-09-15T14%3A11%3A49.935Z
&endtime=2025-03-31T18%3A11%3A49.902Z
&boundary=false
&itemState=true
{
"name": "Linky_Melody_Monthly_Conso_Month",
"datapoints": "3",
"data": [
{
"time": 1735686000000,
"state": "2387.121"
},
{
"time": 1738364400000,
"state": "2666.551"
},
{
"time": 1740783600000,
"state": "1284.0230000000001"
},
{
"time": 1742113051179,
"state": "1284.0230000000001"
},
{
"time": 1742113176648,
"state": "1284.0230000000001"
}
]
}
I’ve got 3 lines for the last month entry !
The first one is coming from the sendTimeSeries call.
The second one is coming from the updateState call, timestamp correspond to this call.
And for the last one, it is generated by the parameters “itemState=true” in the URL call.
When I refresh the rest call, the timestamp for the third entry change every time.
I’ve even try to not send the current month value to sendTimeSeries.
I Still have a duplicate line in rest call for the current itemState
{
"name": "Linky_Melody_Monthly_Conso_Month",
"datapoints": "3",
"data": [
{
"time": 1735686000000,
"state": "2387.121"
},
{
"time": 1738364400000,
"state": "2666.551"
},
{
"time": 1742113960507,
"state": "1284.0230000000001"
},
{
"time": 1742113993275,
"state": "1284.0230000000001"
}
]
}
First one is when I call the updateState, and the last one with updating timestamp on each refresh !
This is a little better because I’ve don’t have a duplicate entry in my graph, but the last entry displayed on the graph is with timestamp of the updateState called, so give a strange graph with a empty space between month -1 and currentMonth. So not very great !
So my question is why I have duplicate entries between entry 2 and entry 3.
For me openhab rest call should answer only the 3 entry, no ?
If someone can help me to understand what I missing there.
Full code is available there
Thanks,
Laurent.