Air Quality Index (AQI)
Air Quality Index (AQI) of your city on your AWTRIX NG display
| System | AWTRIX NG Scripts |
|---|---|
| Firmware | AWTRIX NG |
| Topic | Miscellaneous |
| Built by | zap21 |
| File | gbQeQbwacDNh.ax · 3.1 KB |
| Icons | — |
| Published | 14 Aug 2026 |
| Downloads | 5 |
Air Quality Index (AQI) of your city on your AWTRIX NG display.
You need a TOKEN from https://aqicn.org/api/ and the station name
from the AIQ map https://aqicn.org/ ...
You also have to upload the icon 74824 from https://developer.lametric.com/icons
(or any other icon you like) to your AWTRIX NG.
The token, station, icon and request interval can be configured in the
web UI configuration dialog.
This script is based on the AIQ AWTRIX 3 flow from Dmytro Sudakevych (megadimich).
gbQeQbwacDNh.ax
# @name AQI Air Quality
# @desc AQI Value from aqicn.org (WAQI API)
# @author zap21 / claude
# @version 1.2
# @config station text "Station Code" default="germany/hamburg/flughafen"
# @config token text "API Token" default="YOUR_TOKEN" maxlen=64
# @config every number "Request Interval" default=10 min=1 max=1440 unit=min
# @config ic text "Icon ID" default="74824"
# get TOKEN from https://aqicn.org/api/
# get Station Code (or name) from https://aqicn.org/
class Waqi
var url, period
var aqi # last known AQI value, nil until first successful request
var label, tint
var ic
var ticks, in_flight
var last_status # last HTTP error code
def duration()
return 3000 # linger for 3 s (durationMS)
end
def init()
self.url = "http://api.waqi.info/feed/" + store.get("station") +
"/?token=" + store.get("token")
self.period = store.get("every") * 60
self.ic = store.get("ic")
#self.aqi = store.get("aqi")
self.tint = self.aqi == nil ? 0xFFFFFF : self.color_for(self.aqi)
self.label = self.aqi == nil ? nil : "qi:" + str(self.aqi)
self.ticks = 0
self.in_flight = false
self.last_status = 0
end
def color_for(v)
if v < 0 return 0xFFFFFF
elif v <= 50 return 0x009966
elif v <= 100 return 0xFFDE33
elif v <= 150 return 0xFF9933
elif v <= 200 return 0xCC0033
elif v <= 300 return 0x660099
else return 0x7E0023
end
end
def on_body(body, status)
self.in_flight = false
self.last_status = status
if body == nil return end # no success, show old value
var m = re.search("\"aqi\":([0-9]+)", body) # "aqi":6,... -> 6
if m == nil return end
var v = int(num(m[1]))
self.aqi = v
self.tint = self.color_for(v)
self.label = "qi:" + str(v)
#store.set("aqi", v) # store if valid
end
def loop()
if self.ticks <= 0
self.ticks = self.period
if !self.in_flight
self.in_flight = true
http.get(self.url, / b, st -> self.on_body(b, st),
{'find': "\"aqi\":", 'keep': 16})
end
end
self.ticks -= 1
end
def draw()
clear()
if self.label == nil
if self.last_status != 0
text(1, 6, "e:" + str(self.last_status), 0xFF0000) # show error code
else
text(1, 6, "...", 0x666666) # no value yet
end
return
end
if !icon(self.ic, 0, 0)
rect_fill(0, 0, 8, 8, 0x222222) # fallback if icon is missing
end
var area = width() - 9 # width minus icon size
var x = 9 + (area - text_ink_width(self.label)) / 2 # centered text
if x < 9 x = 9 end # stay away from the icon
text(x, 6, self.label, self.tint)
end
def on_button(btn)
if btn == "select" self.ticks = 0 end # force refresh
end
end
return Waqi()
Install it on your AWTRIX NG
Your browser writes the script straight to the device on your network. It joins the app rotation right away.
Some browsers refuse to talk to a device on your network from a public page. Download the flow and paste it into the Scripts tab of your device, or install it from a terminal:
More flows for AWTRIX NG Scripts or Miscellaneous
Something wrong with this flow? Report it.