How to "count the value above x and make sum over time"?

Hi,
I’m using Grafana with Prometheus to monitor some smart outlets (like the microwave or TV) with watt consumption, but I also want to monitor the time that they are ON. But they’re “on” also when they are in standby, because they drain few watts but for the metrics, 0 off, 1 on. And if I simply use

(switch_outlet_in_use[$__range])

They appear always ON, instead I’m trying to do something like

sum_over_time(switch_current_consumption_w{name=~"Lavatrice|Microonde|Phon|Ferro stiro|Computer|TV"}[$__range])

But I can’t find a way to pick only the queries above 5 (watt of standby i.e.) and then make the sum. Because if I use the above query they appear also always ON, because of the few watt of standby, instead my goal is to have a 0 value for all the metrics below 5 watt.

This is possible?
Thanks a lot!

@giuliomagnifico

I am not experienced with PromQL, but have you tried something like this?

@grant2 thanks for the reply, yes this was the first thing I tried but for some reasons don’t works and it returns no sense values:

Weird, it should works because the same metric, but with values only 1 and 0 works fine with the same query:

Maybe because using sum_over_time(homebridge_switch_current_consumption_w{name=~"Computer|Ferro stiro|Lavatrice|Microonde|Phon|Server|TV|iPhone"}[$__range]) > 100

doesn’t return only 0 and 1 but the numbers (of wattage in use), and then it fails to calculate the sum_over_time because it finds lots of values?

There’s a way to say to the query something like “consider all the values as number 1 or 0 (boolean) and not 12345”?