Create Alert from InfluxDB boolean value

I am using Grafana v9.1.2 in a docker image, migrated from an older version I am trying to create an alert from an InfluxDB Query that returns a boolean value.
In the panel, it looks fine

But when trying to create an alert from it:

Consulting the log, I get:
msg="alert rule panic" error="interface conversion: interface {} is nil, not bool"

Is there any way to create an alert from a boolean?
May also be there is a problem with my Grafana.

Would you be willing to update to Flux? Looks easy acc. to this. I can try later if time allows.

Unfortunately I am not the only user. Many are “less proficient” when it comes to these queries. We also have to deal with a lot of alerts that are configured for InfluxQL (as well as lots of dashboards). The most workable way I have found so far is to duplicate the data source and change the query language there. Then use that data source for new alerts. But I haven’t looked into this too much and haven’t got it to work yet.

I quickly set up some test data and confirmed that the |> toInt() Flux function worked perfectly on the Grafana alerting.

from(bucket: "RetroEncabulator")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "BooleanData")
  |> filter(fn: (r) => r["Location"] == "FrontDoor")
  |> filter(fn: (r) => r["_field"] == "switch_state")
  |> toInt()
  |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
  |> yield(name: "boolean_state")
1 Like