Verify if historical state value are already there from a binding,

Hello @all,

I’m not sure my title is very clear, so let me explain.

I’ve got an addon that exposes water consumption data retrieved from an API.
The API only allows retrieving 3 months of data per call.

Ideally, I would like to loop through multiple calls to initialize the historical data.
But of course, I don’t want to do that every time the binding starts.

My first idea was to verify if item has allready historical data.
But as far as I understand, it’s not good practice to request item states directly from a binding.

What would be a good way to handle this case?

Thanks,
Laurent

You can store in the properties of the thing the last timestamp retrieved

Hello Gael,

This can be an idea, but properties seems not to be persists after restart of openhab.
I use code like this one:

Map<String, String> props = this.editProperties();
props.put(“lastUpdate”, currentDate.toString());
this.updateProperties(props);

Do I miss something ? Try to search, but don’t find info about this.

Laurent.

Hello Laurent,
You might be right that properties may not persist for unmanaged things. I remind that some binding use local storage for such topics. I found at least thinq on my system storing data in /var/lib/openhab/thinq

Yes, already do this on another biding to store metadata information.
Will try like this.

Laurent.