Displaying the car battery consumption as calculation from battery percent and milage

  • What Grafana version and what operating system are you using?

8.2.1 - Docker

  • What are you trying to achieve?

I want to display a graph with a temporary battery consumption for my PHEV vehicle,
And a metric with max, min, median, percentile consumption for a given dashboard period.

  • How are you trying to achieve it?

I have a time series of battery % left and total mileage.
I’m using derivative function to get the difference in last 5 minutes (this is how often car updates the details on cloud while travelling)
Using this queries for calculating the mileage and used battery for every time series:

# kWh
SELECT derivative(mean("value"), 5m) *15 / 100 FROM "%" WHERE ("entity_id" = 'remaining_battery_percent') AND $timeFilter GROUP BY time(5m) fill(null)
# km
SELECT derivative(mean("value"), 5m) FROM "km" WHERE ("entity_id" = 'mileage') AND $timeFilter GROUP BY time(5m) fill(null)
  • What happened?

I was trying to do some transformation on both queries from the series, but unable to find division as I would like to do kWh/km and some scaling to get kWh/100km as a result

  • Question

Is there a way to do the division transformation, or do I need another device that will do calculation every 5 mins and push already ready to use kWh series into the InnoDB?