Using derivative functioin in Flux to monitor the life of solar battery

I’ve LoRaWAN data coming into my local InfluxDB database using Chirp Stack. I’ve integrated database with Chronograf and Grafana for visualization. I’ve battery voltage data stored in an individual measurement, visualization of sample data is shown here:

We can monitor the life of a battery in terms of number of cycles, for which we require charging and discharging pattern. Battery voltage acts as a proxy to determine the charging and discharging pattern. Basically, the battery voltage is increasing when it is in charge (CH) state, whereas it is decreasing when its in discharge (DC) state (there are exceptions in charge state though). So we can make use of the derivative function in Flux to classify whether the battery is charging or discharging, from the battery voltage data of two successive data points (dV/dt>0 for CH; dV/dt<0 for DC). Once the classification is done, the consecutive CH+DC cycles should be counted to estimate the number of cycles, and thus the life of battery.

Need help in writing flux query for this. Any help will be greatly appreciated. Thanks in advance.

Hello @samdanisms,

You’ll probably want to us a Task to write the output of the derivative and status to a new bucket and then use an if/esle statement statement with map.

from(bucket: “mybucket”)
|> range(start: 2020-05-15T18:50:34Z , stop: 2020-05-15T18:59:07Z)
|> filter(fn: ® => r["_measurement"] == “mymeasurement”)
|> filter(fn: ® => r["_field"] == “myfield”)
|> derivative(unit: 3s, nonNegative: false, columns: ["_value"], timeColumn: “_time”)
|> map(fn: ® => ({
r with
if r._value > 0.0 then “CH”
else “DH”
|> monitor.stateChanges(
fromLevel: “CH”,
toLevel: “DH”

Or you can set the levels to “ok” and “warn” and use stateChangesOnly to monitor the changes back and forth.

Thanks Anaisdg. I will test and share the feedback.

1 Like