Counting the number of repeat events in influx and grafana

Hi,
I’m tracking power consumption for receivers using influx and grafana. I’d like to count recurring events that have very similar (but not identical) patterns on the power graph. This would allow me to know how many times a process occurred during a given period.

Do you have any idea how to do this? Influx v1 or v2 version (influxql or flux query) - it doesn’t matter.

Best regards
Łukasz

Hi Łukasz,

Can you share the query you created that produces the graph above?

Also, you wrote “…very similar (but not identical) patterns on the power graph”. Can you quantify the pattern with a math expression?

The graph shown is simply a power graph for a receiver. In this case, a washing machine :slight_smile: but the intentions are higher. As you can see, the graph has 5 repeating - but not identical sequences. In our case, these are subsequent washes and the power graph depends on how long the washing machine takes in electricity. Each time, the graph is a bit different - probably depending on the load, etc.

The query for this graph looks very simple.

SELECT mean(“Watts”) FROM “Revoline” WHERE (“sensor” =~ /^$Obwody$/) AND $timeFilter GROUP BY time($__interval) fill(none)

Is there a way to count how many such washes there were for a given period? I imagine that (for this case - this receiver) you have to filter how many times there was a rising edge in power, but only such that reached a power of at least 1kW.

Maybe the query below will be a good starting point (I normally use Flux and not InfluxQL).
Try adjusting the power threshold (1500W) and time window (30m) based on your specific washing machine’s characteristics. You might need to fine-tune these parameters by examining a few known cycles first.

Also, just realized that InfluxQL does not have a HAVING clause, but there are workarounds. See here: InfluxQL Continuous Queries | InfluxDB OSS v1 Documentation

The key is finding the right balance between the power threshold and time grouping to avoid counting multiple spikes within the same wash cycle while catching each distinct cycle.

SELECT COUNT(*) as wash_count
FROM (
  SELECT MEAN(power) as avg_power
  FROM your_measurement
  WHERE time >= '2024-06-01T08:00:00Z' AND time <= '2024-06-02T08:00:00Z'
    AND power > 1500  -- Threshold above baseline
  GROUP BY time(30m)  -- Group into 30-minute windows
  HAVING avg_power > 1500
)

Thank you very much! it works! I really have to choose the power/time window parameters for extreme cases but the way is brilliant.
Regards and thanks for your help!

Great to hear @wasik10

Please mark the above as Solution so others can find it going forward.