I have a custom temperature sensor to which I've written a pretty basic device driver.
I would like to add temperature history. I'll probably start with Min and Max over different periods (24h, 48h, 1 week etc)
Is it more efficient to use state.temp24 and state.temp48 etc or use local variables or JSON?
I know I can store both the min and max in state.temp24 where local variables would need two variables.
I will need to compare "older" max and min's for each reading.
If I use a JSON I'm not sure if repeated reading and writing is an issue. Also Where would the JSON be stored?
You can't use a local variable if you need to persist across executions (a field variable, yes, to some extent, but also with care needed for multiple devices using the driver).
The state object is usually a good first choice for this and would be my recommendation,especially for data this simple.
I'm not sure how to answer the question about JSON (it's just a data format, not a way to actually keep it anywhere), but I suppose whatever format you need works. However, that's likely overcomplicating things if you could use a simple number or Groovy List or Map directly, all of which are generally easier to work with if you're not leaving the Groovy environment, as you're likely not with this driver (as opposed to say, an app with HTTP endpoints).