[HomeAssistant] Gasprice / Spritpreis
![[HomeAssistant] Gasprice / Spritpreis shown on an AWTRIX display](/storage/covers/AQLCqj6HxCc7/versions/bzc5dysmr65sadzmqhm3/cover-960.jpg)
Use with Home Assistant
Current Fuel Prices from HomeAssistant Entity(ies) / Aktuelle Spripreis aus HomeAssistant-Entität(en)
- Works with
- Home Assistant
- Topic
- Miscellaneous
- Includes
- Flow · 1 icon
Flow description
Eine deutsche Anleitung befindet sich weiter unten.
HomeAssistant_Gasprice
Version 1.2
English
Instructions
The app displays the price from one or two Home Assistant entities with exactly two decimal places and a configurable currency symbol.
The 8×8 gasoline_pump icon is displayed on the left side. The price and currency symbol are centered together in the remaining area to the right of the icon. The display remains static and does not scroll.
All settings can be changed using the app's settings menu without modifying the source code.
Requirements
- An AWTRIX NG device with Berry script support. The layout is designed for a 32×8 pixel display.
- Home Assistant must be reachable from the AWTRIX device using its HTTP or HTTPS address.
- One or two Home Assistant entities with a numeric state, for example
1.759. The price is read directly from the entity state, not from an attribute. The app does not perform currency or unit conversions. - A Long-Lived Access Token from your Home Assistant profile. Enter the token only in the app settings and do not include the
Bearerprefix.
Settings
| Setting | Default | Description |
|---|---|---|
| Home Assistant - URL | https://homeassistant.local | HomeAssistant-URL with http(s):// |
| Home Assistant - Long-lived access token | Empty | HomeAssistant - Long-lived access token. Enter it without the Bearer prefix. |
| HomeAssistant-Entity 1 | sensor.XXX |
First Numerical Entity. Replace the example with your actual entity ID. |
| HomeAssistant-Entity 2 (optional) | Empty | Second Numerical Entity. If left empty, only the first entity is displayed. |
| Update Interval | 10 minutes | Time between requests for each entity. The minimum is 10 minutes and the maximum is 1440 minutes. |
| Currency symbol | € |
Choose between €, $, £, ¥, and ¢. The selected symbol does not modify the numeric value. |
| Entity color | White, #FFFFFF |
Color of the price, decimal separator, and the -- and ## placeholders. |
| Currency symbol color | Green, #008A09 |
Color of the currency symbol. |
| Decimal separator | Comma | Choose between comma and dot. This affects the display only. |
Icon
The 8×8 gasoline_pump icon must be available on the AWTRIX device.
If the icon is missing or cannot be displayed, the app shows NO! in the reserved icon area instead. The price display continues to work normally.
Display and Entity Switching
-
Two decimal places:
For example,1.759is displayed as1,76 €, while2is displayed as2,00 €when the comma separator is selected. -
Six-pixel-high font:
On a 32×8-pixel display, one empty pixel row remains above and below the numbers and currency symbol. -
Comma descender:
When Comma is selected, the upper pixel of the comma is positioned on the number baseline. Its lower part extends one pixel row further down into the bottom row of the display. Only the comma uses this bottom row. When Dot is selected, the bottom row remains unused in the text area. -
Fixed space for the icon:
Eight pixel columns are reserved for the icon on the left, followed by one empty pixel column. The text is centered in the remaining area. -
No scrolling or clipping:
If a price does not fit completely within the available width, the app displays##together with the selected currency symbol instead.
For example,99,99 €fits on a 32×8-pixel display, while999,99 €does not.
If both entities are configured, they are displayed in the following order each time the app is shown:
Entity 1 → Entity 2 → Entity 1 → Entity 2 → …
The displayed entity changes only after the app has been left and is shown again. During a continuous display session, the same entity remains selected.
After a restart or after saving the settings, the sequence starts again with Entity 1.
Both values are requested in the background at the configured interval, even while another app is being displayed. Simply opening the app does not trigger an additional Home Assistant request.
If a response arrives late, it is always assigned to the correct entity.
Troubleshooting
| Display or problem | Meaning and next step |
|---|---|
NO! |
The icon is missing or cannot be displayed. Check the name, file format, and size of the installed icon. |
-- at startup |
No valid price has been received yet. Wait for the first response from Home Assistant. |
-- remains displayed |
Check the Home Assistant address, token, entity ID, and numeric entity state. States such as unknown or unavailable, units included in the state, or connection errors also result in --. |
## |
The price does not fit completely within the available width or is too large to display. |
| Only one price is displayed | Check whether the second entity has been entered and saved. The entity changes the next time the app is shown. |
| Price does not update immediately | Each entity is queried only after the configured interval has elapsed. The minimum interval is ten minutes. |
HTTP 401 in the log |
Check that the complete token is correct and still valid. Enter it without Bearer. |
HTTP 404 in the log |
Check the entity ID and the Home Assistant base URL. |
HTTP 0 in the log |
No HTTP response was received. Check whether the Home Assistant address is reachable from the AWTRIX network. |
Red ERR: |
Read the complete error message shown next to the script in the Scripts tab. When reporting an issue, copy and include the full message. |
Installation rejected with 507 |
The available script storage is insufficient or fragmented. Restart the AWTRIX device and, if necessary, remove custom scripts that are no longer required. |
An error affecting one entity replaces only that entity's price with --. A previously received valid value from the other entity remains unaffected.
Changelog
2026-09-24
- 1.0: Initial release.
- 1.1: Hardcoded the
gasoline_pumpicon; added theNO!fallback indicator when the icon cannot be loaded; adjusted the price display; added support for an optional second entity that alternates when the app is shown again. - 1.2: Adjusted the comma rendering; changed the
NO!fallback indicator color to red.
Deutsch
Anleitung
Die App zeigt den Preis aus einer oder zwei Home-Assistant-Entities mit genau zwei Nachkommastellen und einem frei wählbaren Währungszeichen an.
Auf der linken Seite wird das 8×8-Icon gasoline_pump dargestellt. Preis und Währungszeichen werden gemeinsam im verbleibenden Bereich rechts neben dem Icon zentriert. Die Anzeige bleibt statisch und verwendet keine Laufschrift.
Alle Einstellungen können über das Zahnrad der App geändert werden. Eine Anpassung des Quellcodes ist nicht erforderlich.
Voraussetzungen
- Eine AWTRIX NG mit Unterstützung für Berry-Skripte. Das Layout ist für ein 32×8-Pixel-Display ausgelegt.
- Home Assistant muss von der AWTRIX aus über seine HTTP- oder HTTPS-Adresse erreichbar sein.
- Eine oder zwei Home-Assistant-Entities mit einem numerischen Zustand, beispielsweise
1.759. Der Preis wird direkt aus dem Zustand der Entity gelesen, nicht aus einem Attribut. Die App führt keine Währungs- oder Einheitenumrechnung durch. - Ein langlebiges Zugriffstoken aus deinem Home-Assistant-Profil. Das Token wird ausschließlich in den App-Einstellungen eingetragen – ohne den Zusatz
Bearer.
Einstellungen
| Einstellung | Vorgabe | Bedeutung |
|---|---|---|
| Home Assistant - URL | https://homeassistant.local | HomeAssistant-URL mit http(s):// |
| Home Assistant - Long-lived access token | Leer | Langlebiges Home-Assistant-Zugriffstoken. Ohne den Zusatz Bearer eintragen. |
| HomeAssistant-Entity 1 | sensor.XXX |
Erste Preis-Entity. Ersetze den Beispielnamen durch deine tatsächliche Entity-ID. |
| HomeAssistant-Entity 2 (optional) | Leer | Zweite Preis-Entity. Bleibt das Feld leer, wird ausschließlich die erste Entity angezeigt. |
| Update interval | 10 Minuten | Zeitraum zwischen den Abfragen einer Entity. Zulässig sind mindestens 10 und höchstens 1440 Minuten. |
| Currency symbol | € |
Auswahl zwischen €, $, £, ¥ und ¢. Das Währungszeichen verändert den Zahlenwert nicht. |
| Entity color | Weiß, #FFFFFF |
Farbe des Preises, des Dezimaltrennzeichens sowie der Platzhalter -- und ##. |
| Currency symbol color | Grün, #008A09 |
Farbe des Währungszeichens. |
| Decimal separator | Comma | Auswahl zwischen Komma (Comma) und Punkt (Dot). Dies betrifft ausschließlich die Anzeige. |
Icon
Auf der AWTRIX muss das 8×8-Icon gasoline_pump vorhanden sein.
Fehlt das Icon oder kann es nicht dargestellt werden, zeigt die App stattdessen NO! im reservierten Iconbereich an. Die Preisanzeige funktioniert weiterhin.
Anzeige und Wechsel zwischen Entities
-
Zwei Nachkommastellen:
Beispielsweise wird1.759als1,76 €und2als2,00 €dargestellt, wenn als Dezimaltrennzeichen das Komma gewählt wurde. -
Sechs Pixel hohe Schrift:
Auf einem 32×8-Pixel-Display bleibt oberhalb und unterhalb der Zahlen sowie des Währungszeichens jeweils eine Pixelreihe frei. -
Komma mit Unterlänge:
Bei Auswahl von Comma liegt der obere Pixel des Kommas auf der Grundlinie der Zahl. Der Ausläufer reicht eine Pixelreihe tiefer bis in die unterste Displayzeile. Nur das Komma verwendet diese unterste Zeile. Bei Dot bleibt sie im Textbereich frei. -
Fester Platz für das Icon:
Auf der linken Seite sind acht Pixelspalten für das Icon reserviert. Danach folgt eine freie Pixelspalte. Der Text wird im verbleibenden Bereich zentriert. -
Kein Scrollen und kein Abschneiden:
Passt ein Betrag nicht vollständig in den verfügbaren Bereich, zeigt die App stattdessen##zusammen mit dem gewählten Währungszeichen an.
Beispielsweise passt99,99 €auf ein 32×8-Pixel-Display,999,99 €dagegen nicht.
Sind beide Entities eingetragen, wechseln sie bei jedem erneuten Einblenden der App in folgender Reihenfolge:
Entity 1 → Entity 2 → Entity 1 → Entity 2 → …
Der angezeigte Preis wechselt erst, nachdem die App verlassen und anschließend erneut eingeblendet wurde. Während eines durchgehenden Anzeigezeitraums bleibt dieselbe Entity ausgewählt.
Nach einem Neustart oder nach dem Speichern der Einstellungen beginnt die Reihenfolge wieder mit Entity 1.
Beide Werte werden im Hintergrund im eingestellten Intervall abgefragt – auch wenn gerade eine andere App angezeigt wird. Das Einblenden der App selbst löst keine zusätzliche Home-Assistant-Abfrage aus.
Trifft eine Antwort verzögert ein, wird sie immer der zugehörigen Entity zugeordnet.
Fehlerbehebung
| Anzeige oder Problem | Bedeutung und nächster Schritt |
|---|---|
NO! |
Das Icon fehlt oder kann nicht dargestellt werden. Prüfe Namen, Dateiformat und Größe des installierten Icons. |
-- beim Start |
Es wurde noch kein gültiger Preis empfangen. Warte auf die erste Antwort von Home Assistant. |
-- bleibt bestehen |
Prüfe Home-Assistant-Adresse, Token, Entity-ID und den numerischen Zustand der Entity. Auch unknown, unavailable, Einheiten innerhalb des Zustands oder Verbindungsfehler führen zu --. |
## |
Der Betrag passt nicht vollständig in die verfügbare Breite oder ist für die Anzeige zu groß. |
| Nur ein Preis erscheint | Prüfe, ob die zweite Entity eingetragen und gespeichert wurde. Der Wechsel erfolgt erst beim nächsten Einblenden der App. |
| Preis aktualisiert sich nicht sofort | Eine reguläre Abfrage erfolgt für jede Entity frühestens nach Ablauf des eingestellten Intervalls. Das Mindestintervall beträgt zehn Minuten. |
HTTP 401 im Log |
Prüfe, ob das vollständige Token korrekt und weiterhin gültig ist. Trage es ohne Bearer ein. |
HTTP 404 im Log |
Prüfe die Entity-ID und die Home-Assistant-Basisadresse. |
HTTP 0 im Log |
Es wurde keine HTTP-Antwort empfangen. Prüfe, ob die Home-Assistant-Adresse aus dem Netzwerk der AWTRIX erreichbar ist. |
Rotes ERR: |
Lies die vollständige Fehlermeldung neben dem Skript im Tab Scripts. Kopiere sie bei einer Fehlermeldung oder Supportanfrage vollständig mit. |
Installation wird mit 507 abgelehnt |
Der verfügbare Skriptspeicher reicht nicht aus oder ist fragmentiert. Starte die AWTRIX neu und entferne gegebenenfalls nicht mehr benötigte eigene Skripte. |
Ein Fehler bei einer Entity ersetzt ausschließlich deren Preis durch --. Ein bereits erfolgreich empfangener Wert der anderen Entity bleibt davon unberührt.
Changelog
24.09.2026
- 1.0: Erste Veröffentlichung.
- 1.1: Icon fest auf
gasoline_pumpgesetzt; Fallback-AnzeigeNO!hinzugefügt, falls das Icon nicht geladen werden kann; Preisdarstellung angepasst; optionale zweite Entity mit Wechsel beim erneuten Einblenden der App hinzugefügt. - 1.2: Darstellung des Kommas angepasst; Farbe des Fallback-Symbols
NO!auf Rot geändert.
AQLCqj6HxCc7.yaml
# @name HomeAssistant_Gasprice
# @desc Current Fuel Prices from Home Assistant Entity(ies)
# @author Chiller
# @version 1.2
# @config ha_url text "HomeAssistant - URL" default="https://homeassistant.local" maxlen=256 help="HomeAssistant-URL with http(s)://"
# @config ha_token text "HomeAssistant - Long-lived access token" maxlen=512 help="HomeAssistant - Long-lived access token"
# @config entity text "HomeAssistant-Entity 1" default="sensor.XXX" maxlen=128 help="First Numerical Entity"
# @config entity2 text "HomeAssistant-Entity 2 (optional)" default="" maxlen=128 help="Second Numerical Entity (optional)"
# @config refresh_min number "Update interval" default=180 min=10 max=1440 step=1 unit=min help="Interval for fetching entities"
# @config currency select "Currency symbol" default=€ options=€,$,£,¥,¢ help="Displayed by price"
# @config number_color color "Entity color" default=#FFFFFF help="Price color"
# @config currency_color color "Currency symbol color" default=#008A09
# @config separator select "Decimal separator" default=Comma options=Comma,Dot
import string
class HAGasolinePrice
var urls, opts, period, last_poll, in_flight, pending
var labels, current, shown, missing_icon
var number_color, currency_color, separator
var glyphs, columns, split, xpos, ypos
def init()
var base = store.get("ha_url")
while size(base) > 0 && base[-1] == "/"
base = size(base) == 1 ? "" : base[0 .. size(base) - 2]
end
var token = store.get("ha_token")
var ready = re.match("^https?://[^/]+", base) != nil && size(token) > 0
self.urls = []
self.labels = []
self.last_poll = []
for entity : [store.get("entity"), store.get("entity2")]
if size(entity) > 0
var valid = ready && re.match("^[a-z0-9_]+\\.[a-z0-9_]+$", entity) != nil
self.urls.push(valid ? base + "/api/states/" + entity : nil)
self.labels.push("--")
self.last_poll.push(nil)
end
end
self.opts = {"headers": {"Authorization": "Bearer " + token},
"find": "\"state\"", "keep": 96, "cap": 96}
self.period = int(clamp(store.get("refresh_min"), 10, 1440)) * 60000
self.in_flight = false
self.pending = 0
self.current = 0
self.shown = false
self.missing_icon = [0x3F, 0x06, 0x18, 0x3F, 0x1E, 0x21, 0x1E, 0x2F]
self.number_color = store.get("number_color")
self.currency_color = store.get("currency_color")
self.separator = store.get("separator")
self.glyphs = {"0": 0x755557, "1": 0x111111, "2": 0x711747,
"3": 0x717117, "4": 0x557111, "5": 0x747117,
"6": 0x747557, "7": 0x711222, "8": 0x757557,
"9": 0x757117, ".": 0x000001, ",": 0x000012,
"-": 0x007000, "#": 0x575575}
var symbols = {"€": 0x346643, "$": 0x276372, "£": 0x346447,
"¥": 0x552722, "¢": 0x274472}
self.glyphs["@"] = symbols.find(store.get("currency"))
self.columns = []
self.split = 0
self.xpos = 9
self.ypos = (height() - 6) / 2
self.layout("--")
end
def loop()
if self.in_flight || size(self.urls) == 0 return end
var t = now_ms()
for i : 0 .. size(self.urls) - 1
if self.urls[i] != nil && (self.last_poll[i] == nil ||
((t - self.last_poll[i]) & 0x7FFFFFFF) >= self.period)
self.last_poll[i] = t
self.pending = i
self.in_flight = true
http.get(self.urls[i], / body, status -> self.on_body(body, status), self.opts)
return
end
end
end
def on_show()
if self.shown && size(self.urls) == 2 self.current = 1 - self.current end
self.shown = true
if size(self.labels) > 0 self.layout(self.labels[self.current]) end
end
def on_body(body, status)
self.in_flight = false
var value = nil
if status == 200 && body != nil
var m = re.match("^\"state\"\\s*:\\s*\"([^\"]*)\"", body)
if m != nil
if re.match("^[+-]?[0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?$", m[1]) != nil
value = num(m[1])
end
end
end
var label = "--"
if value == nil || value != value
log("HomeAssistant_Gasprice: No valid price; HTTP " + str(status))
elif value > 999999.99 || value < -999999.99
label = "##"
log("HomeAssistant_Gasprice: Price too large to display.")
else
value = round(value, 2)
if value == 0 value = 0.0 end
label = string.format("%.2f", value)
if self.separator == "Comma"
label = string.replace(label, ".", ",")
end
end
self.labels[self.pending] = label
if self.pending == self.current self.layout(label) end
end
def layout(label)
var w = 3
for i : 0 .. size(label) - 1
var ch = label[i]
w += (ch == "1" || ch == "." ? 1 : (ch == "," ? 2 : 3)) + 1
end
if w > width() - 9
label = "##"
log("HomeAssistant_Gasprice: Price doesn't match; Ad ##, no cropping or scrolling.")
end
label += "@"
self.columns = []
for i : 0 .. size(label) - 1
var ch = label[i]
var gw = ch == "1" || ch == "." ? 1 : (ch == "," ? 2 : 3)
var bits = self.glyphs.find(ch, 0)
if ch == "@" self.split = size(self.columns) end
for x : 0 .. gw - 1
var col = 0
for y : 0 .. 5
if ((bits >> ((5 - y) * 4)) & (1 << (gw - 1 - x))) != 0
col = col | (1 << y)
end
end
if ch == "," col = col << 1 end
self.columns.push(col)
end
if i < size(label) - 1 self.columns.push(0) end
end
self.xpos = 9 + (width() - 9 - size(self.columns)) / 2
end
def draw()
clear()
if width() < 20 || height() < 8 return end
var iy = (height() - 8) / 2
if !icon("gasoline_pump", 0, iy)
var x = 0
while x < 8
var y = 0
while y < 6
if (self.missing_icon[x] & (1 << y)) != 0
pixel(x, iy + 1 + y, 0xFF0000)
end
y += 1
end
x += 1
end
end
rect_fill(8, 0, width() - 8, height(), 0x000000)
var i = 0
while i < size(self.columns)
var c = i < self.split ? self.number_color : self.currency_color
var y = 0
while y < 7
if (self.columns[i] & (1 << y)) != 0
pixel(self.xpos + i, self.ypos + y, c)
end
y += 1
end
i += 1
end
end
end
return HAGasolinePrice()
These icons are attached to the flow. Send them to your AWTRIX separately; they are not included in the script installation.
8×8 px
Sign in to download these icons or send them to your AWTRIX.
Discussion 0
Ask a question, suggest a change or share how you use it.
No comments yet. Start the conversation.
More flows for Home Assistant or Miscellaneous
Something wrong with this flow? Report it.
Have an idea?
Sign in to ask questions and join the conversation.