I have following data in InFluxDB:
Charge current
Discharge current
Time
I know my battery capacity. Would it be possible to create Coulomb counter? Or is it too much for Grafana?
Thanks,
I have following data in InFluxDB:
Charge current
Discharge current
Time
I know my battery capacity. Would it be possible to create Coulomb counter? Or is it too much for Grafana?
Thanks,
I have following data in InFluxDB:
Charge current
Discharge current
TimeI know my battery capacity. Would it be possible to create Coulomb counter?
Well, given that one coulomb is one amp second, surely all you need to do is
subtract discharge current from charge current and then multiply the result by
time?
Or is it too much for Grafana?
It’s not a question for Grafana - it’s question for InfluxDB, since the
calculation would end up in the query that Grafana performs.
Some maths as simple as this, though, is well within InfluxDB’s capabilities.
Regards,
Antony.
Hey, I know it’s 2 years later but I see this question has a lot of views and I have come up with my own solution for this on a raspberry pi connected to an Tracer 3210AN. I just thought you and others may like to know how I created a “coulomb counter” for my dashboard.
I am using Telegraf (with RS-485 on serial port), Influxdb and Grafana to generate a dashboard with various gauges and charts. One of them is a “Battery Energy” gauge that reads in Watt-hours (Wh) for my battery.
The two measurement values I use are named B_P (battery power, in) and L_P (load power, out). In my gauge panel I put the following influx query:
select sum("BE")-sum("LE")+600 from (select integral(B_P)/3600 as "BE",integral(L_P)/3600 as "LE" from modbus where time >= $lastfull and time <= now() group by time(1m))
The constant 600 is the maximum (full) battery capacity in Wh. It’s actually a bit more but I reduced it a bit due to being a year old. The variable $lastfull is created in the dashboard settings as a “query variable”. It connects the csv plugin to read a local file with a few values - only one is used.
$lastfull is the last timestamp that the battery was full. In my case I call it full when it is over 14.5 volts (LiFePO4), but you may want to use a different criteria. I do this because if you don’t “calibrate” the “full” value then your “energy” value will drift due to small reading errors.
In order to get the timestamp into a local csv file I put in a cronjob that does an influx query. I do this once a day but it could be done more often. It only uses a timestamp, which only changes when a “full” event happens anyway.
Here is the command which updates the csv file:
sudo -u grafana influx -database solar -execute "select last(B_V) from modbus where B_V >= 14.5" -format csv | sudo -u grafana tee /var/lib/grafana/csv/solarvars >/dev/null
Where “solar” is my database name, and “grafana” is the usual user that grafana runs as. I put this in a bash script file, eg. /usr/local/bin/lastfull
(be sure to chmod +x the file) and call that in a (root) cronjob. For example, at 4pm every day:
# m h dom mon dow command
0 16 * * * /usr/local/bin/lastfull
In summary, the dashboard query variable gets pulled from the /var/lib/grafana/csv/solarvars
file, which becomes the “from” time in the gauge query. The query adds solar input and subtracts load output starting from FULL at $lasttime until “now”. This is working well for me so far. Resetting the time range every day stops it from drifting too far off base.
If you have questions, feel free to post, but I may not be around that often. Will try to respond.