No state change if same value received -> not sent to InfluxDB

Hi,

First of all I have looked around and didn’t find a solution here.
I was already aware that if HA receives an update from an external sensor with the same value it isn’t considered a state change. I learned this the hard way by trying to create a template sensor to add the new value to a “total” sensor on state change. (In this case a gas sensor which sends the usage every minute added to a total_increasing “Gas_Total” sensor). I was able to solve this by using the Riemann integral integration which can now perfectly track the total usage.
However I have now added InfluxDB integration and have the same problem. I can get the graph (in grafana) to look the same as the history graph in HA but I’m at a loss on how I can integrate (as in integral) this graph.
Any help on solving this either in grafana, InfluxdB or by sending the state every minute to InfluxDB would be appreciated.
(Of course I could sent the “Gas Total” sensor to InfluxDB and find a way to derive the per interval usage from there…but again I wouldn’t know how)

Did you see this?

Thanks. This would work but would require another template sensor which is a copy of the original sensor and triggered every minute.
In the mean time I have been able to solve it by sending the total counter (it was easier than expected) and the solution will keep working when I move to a digital gasmeter because it returns a total counter anyway. So it works for now…until the next use case that requires forced state changes (e.g. battery monitor)
For those interested this is the flux query

from(bucket: "HomeAssistant")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["friendly_name"] == "gas_meter_m3")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["_measurement"] == "m³")
  |> difference(nonNegative: false, columns: ["_value"])
  |> aggregateWindow(every: 1h, fn: sum, createEmpty: false)
  |> yield(name: "sum")

Result