Struggling to filter out specific time windows in joined time series

(Using Grafana 10.0 on Home Assistant OS)

Hello, fairly new to Grafana, I’m trying to calculate the energy efficiency of my electric vehicle.

I have the following sensors as time series:

  • Battery state of charge in percent
  • odometer in miles
  • charge power in kW.

I’m trying to get two visualisations:

  • total energy consumed and corresponding mi/kW for the current time range
  • bar charts of consumed energy and average mi/kW per month for the last 12 months

I know I can trivially turn my state of charge series into a kWh used series by multiplying it by the battery’s total capacity, but what I’m struggling with is manipulating the state of charge series to remove unwanted data points.

My instinct was to join the 3 queries using the timestamp field and then filter out any rows where the charge power is positive and then add all the rows to get the energy consumed during the observed window.

Because values might be changing at different times, I often end up with rows where at least one value is missing after the join (data source is InfluxDB), meaning the filter doesn’t correctly filter out state of charge gains due to charging the vehicle.

Grouping values using a larger time interval does help to some extent, but a time interval that’s large enough to fill all the columns risks incorrectly including data from a charging session and either way, I have to deal with the jump in state of charge difference at the end of a session.

What are my options to achieve this?

Thanks!