Fuel Prices
Shows the cheapest nearby fuel price (Tankerkoenig.de)
| System | AWTRIX NG Scripts |
|---|---|
| Firmware | AWTRIX NG |
| Topic | Miscellaneous |
| Built by | Hank_the_Tank |
| File | A7qGCk8PzkFv.ax · 3.9 KB |
| Icons | 4 |
| Published | 8 Sep 2026 |
| Downloads | 1 |
Fuel Prices — AWTRIX NG App
Shows the cheapest nearby fuel price for one fuel type of your choice — Diesel, E5 or E10 —
together with the brand and street of that station, live from the free
tankerkoenig.de API.
What it shows
One scrolling line, right when the app comes up in your rotation:
2.299€ | ARAL | Brunnenstraße
The price is shown in green (configurable), the brand and street in white. A small pump icon
sits to the left of the text — either one you supply yourself, or a simple built-in fallback
shape if none is set or an icon fails to load.
Requirements
- An AWTRIX NG device (32×8 LED matrix) with network access.
- A free API key from creativecommons.tankerkoenig.de.
Registration is free; after signing up you may need to complete a short follow-up
confirmation step before the key becomes active. - Your own approximate coordinates (latitude/longitude), e.g. from
latlong.net or any map app.
Installation
- Open your AWTRIX web interface — its IP address, or
http://awtrixng-xxxxxx.local. - Go to the Scripts tab and create a new script, e.g. named
FuelPrices. - Paste in the code below and press Save.
- The app joins the rotation shortly after. Press the right button on the device to jump
straight to it. - Open Apps → the
⋯menu on theFuelPricesrow → Settings, and fill in your API
key and coordinates (see the table below). Saving restarts the app.
Settings
| Setting | Type | Default | Notes |
|---|---|---|---|
| API key | text | YOUR-API-KEY |
Paste your tankerkoenig.de key here — never share it publicly. |
| Latitude / Longitude | text | Berlin (52.5200 / 13.4050) | Use a dot as the decimal separator, e.g. 48.1374. |
| Radius | number, 1–25 km | 5 km | Search radius; the tankerkoenig API caps this at 25 km. |
| Fuel | select | Diesel | Diesel, E5 or E10 — one fuel type per app instance. |
| Refresh | number, 5–60 min | 10 min | How often prices are re-fetched. tankerkoenig prices themselves only update every 4–5 minutes, and the API asks that automated clients not poll faster than every 5 minutes. |
| Price color | color | Green (#00FF00) |
Colour of the price segment; brand/street are always white. |
| Icon ID | text | (empty) | Optional 8×8 icon ID already installed on your device. Leave empty for a drawn placeholder pump icon. |
To show more than one fuel type, install the script again under a different name and pick a
different fuel in its own settings — each installed copy keeps its own settings and state.
How it works (short version)
- Queries
list.phpsorted by price for the selected fuel type, so the first station in the
response is always the cheapest match in range. - Uses the device's
find/keepHTTP option to pull only a small window of the response
(the first station's record) instead of the whole reply, to stay light on the shared script
memory. - Refetches on a timer in the background (
loop()), so the panel always has something to
show the moment it's this app's turn — never a blank screen. - Pressing the middle/select button while the app is showing forces an immediate refresh.
Notes & limitations
- Needs a valid, activated API key — an invalid or not-yet-active key fails silently on the
panel (keeps showing...), but logs a line under Log in the AWTRIX web UI so you can
tell it apart from a real "no stations found" case. - Shows the single cheapest station in range for the chosen fuel — not a list of several
stations. - Respect tankerkoenig's fair-use terms: don't set the refresh interval below 5 minutes, and
don't share your personal API key.
A7qGCk8PzkFv.ax
# @name Fuel Prices
# @desc Cheapest nearby price, brand and street for one fuel type (tankerkoenig.de)
# @author Hank_the_Tank / Claude
# @version 1.5
# @config apikey text "API key" default="YOUR-API-KEY" help="Free key from creativecommons.tankerkoenig.de"
# @config lat text "Latitude" default="52.5200"
# @config lon text "Longitude" default="13.4050"
# @config radius number "Radius" default=5 min=1 max=25 unit=km
# @config fuel select "Fuel" default=diesel options=diesel,e5,e10
# @config every number "Refresh" default=10 min=5 max=60 unit=min
# @config tint color "Price color" default=#00FF00
# @config icon text "Icon ID" default=""
import string
import json
class FuelPrice
var url, find # request URL and search needle, built from settings
var ic, tint # icon name and price colour
var price, brand, street # last known values for the cheapest station
var label # the [text, color] pieces draw() paints
var period, ticks, in_flight # loop() pacing
def fmt() # builds the coloured display pieces
if self.price == nil return [["...", 0x666666]] end
var b = self.brand == nil ? "" : self.brand
var s = self.street == nil ? "" : self.street
return [[string.format("%.3f", self.price) + "€", self.tint],
[" | " + b + " | " + s, 0xFFFFFF]]
end
def init()
self.ic = store.get("icon")
self.tint = store.get("tint")
self.url = "https://creativecommons.tankerkoenig.de/json/list.php?lat=" +
store.get("lat") + "&lng=" + store.get("lon") +
"&rad=" + str(store.get("radius")) + "&sort=price&type=" +
store.get("fuel") + "&apikey=" + store.get("apikey")
self.find = "{\"id\":\"" # start of the first (cheapest) station object
self.period = store.get("every") * 60 # loop() runs ~1x/s
self.price = store.get("price") # survive a reboot
self.brand = store.get("brand")
self.street = store.get("street")
self.label = self.fmt()
self.ticks = 0
self.in_flight = false
end
def on_body(body, status)
self.in_flight = false
if body == nil
log("FuelPrices: no data (status " + str(status) + ") - check API key / coordinates")
return
end
var mp = re.search("\"price\":([0-9]+\\.[0-9]+)", body)
if mp == nil return end
var p = num(mp[1])
if p == nil return end
var mb = re.search("\"brand\":\"([^\"]*)\"", body)
var ms = re.search("\"street\":\"([^\"]*)\"", body)
# re-wrap each raw JSON string piece and let json.load decode escapes (umlauts etc.)
self.price = p
self.brand = mb == nil ? "" : json.load("[\"" + mb[1] + "\"]")[0]
self.street = ms == nil ? "" : json.load("[\"" + ms[1] + "\"]")[0]
self.label = self.fmt() # rebuild the coloured line
store.set("price", p) # only keep it once it is good
store.set("brand", self.brand)
store.set("street", self.street)
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': self.find, 'keep': 480})
end
end
self.ticks -= 1
end
def draw()
clear()
if !icon(self.ic, 0, 0) # no icon set, or unknown to the device
rect_fill(2, 1, 4, 6, 0x555555) # fallback: a small pump shape
rect_fill(1, 0, 2, 1, 0x555555)
line(6, 2, 7, 2, 0x555555)
line(7, 2, 7, 5, 0x555555)
end
scroll_text(9, 6, width() - 9, self.label, 0xFFFFFF)
end
def on_button(btn)
if btn == "select" self.ticks = 0 end # force an immediate refresh
end
end
return FuelPrice()
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:
These icons belong on the device, in /ICONS. Each one is at
most 32×8
pixels — shown here magnified, at their real proportions.
8×8 px
8×8 px
8×8 px
8×8 px
More flows for AWTRIX NG Scripts or Miscellaneous
Something wrong with this flow? Report it.