Counting number of values of an item in influxDB?

The persistence extensions don’t provide a way to do this, but you can query the persistence data through the REST API. I rely on this for…

You could do something like this to get the number of times the switch switched…

val String persistenceResult = executeCommandLine("/bin/sh@@-c@@/usr/bin/curl -s http://localhost:8080/rest/persistence/items/Virtual_Switch_1?starttime=" + now.minusDays(5).toString + "&endtime=" + now.toString,10000)
logDebug("Rules","Test1: persistenceResult=[{}]",persistenceResult)
val Integer numSwitches = Integer::parseInt(transform("JSONPATH", "$.datapoints", persistenceResult)) / 2
logDebug("Rules","Test1: numSwitches=[{}]",numSwitches)

You would need the JSONPATH transformation service instaled for this. You may wonder why I’m dividing by two… for items of OnOffType, the REST API will add in an additional state for each change to improve charting. If you look at the data, before every ON you’ll see an extra OFF, and vice-versa.

And as @rlkoshak pointed out, this would only work correctly if you are persistence strategy is everyChange.