laut.fm Data Collector
Background app that provides data for "laut.fm Listeners" and "laut.fm Current Song"
| System | AWTRIX NG Scripts |
|---|---|
| Firmware | AWTRIX NG |
| Topic | Miscellaneous |
| Built by | eXiratA |
| File | 6VoTP8J4MYWj.ax · 3.2 KB |
| Icons | — |
| Published | 19 Aug 2026 · updated 19 Aug 2026 |
| Downloads | 1 |
In line 5, the entry "HIER_DEINEN_SENDER_EINTRAGEN" must be changed to the desired station name.
To do this, open the station of your choice in your web browser. (Example: "https://laut.fm/music4nerds" – the station name here is "music4nerds". Enter this in line 5.)
(The image is for illustrative purposes only. The script runs in the background and does not display anything on the screen; that is handled by the "laut.fm Listeners" and "laut.fm Current Song" scripts.)
6VoTP8J4MYWj.ax
# @name LautFM Data
# @desc Zentrale laut.fm-Abfrage für Song und Hörerzahl
# @headless true
# @config station text "laut.fm Sender" default="HIER_DEINEN_SENDER_EINTRAGEN" maxlen=64
# @config every number "Aktualisierung" default=60 min=30 max=3600 unit=s
import json
class LautFmData
var station
var url_song
var url_listeners
var period
var ticks
var in_flight
var song
var listeners
def init()
self.station = store.get("station")
self.period = store.get("every")
self.url_song = "https://api.laut.fm/station/" + self.station + "/current_song"
self.url_listeners = "https://api.laut.fm/station/" + self.station + "/listeners"
self.ticks = 10
self.in_flight = false
self.song = ""
self.listeners = nil
end
def setup()
self.fetch_song()
end
# ================================================
# Aktuellen Song holen
# ================================================
def fetch_song()
if self.in_flight
return
end
self.in_flight = true
http.get(
self.url_song,
/body, status -> self.on_song(body, status)
)
end
def on_song(body, status)
if body == nil || status < 200 || status >= 300
self.in_flight = false
self.ticks = 10
return
end
var data = json.load(body)
if data == nil
self.in_flight = false
self.ticks = 10
return
end
var title = data.find("title", "")
var artist = ""
var artist_data = data.find("artist", nil)
if artist_data != nil
artist = artist_data.find("name", "")
end
if artist != "" && title != ""
self.song = str(artist) + " - " + str(title)
elif title != ""
self.song = str(title)
elif artist != ""
self.song = str(artist)
else
self.song = "Kein Titel"
end
# Danach Hörerzahl abfragen
http.get(
self.url_listeners,
/listener_body, listener_status -> self.on_listeners(listener_body, listener_status)
)
end
# ================================================
# Hörerzahl holen
# ================================================
def on_listeners(body, status)
self.in_flight = false
if body != nil && status >= 200 && status < 300
# Die listeners-Antwort ist eine Zahl/Text,
# kein JSON-Objekt.
var value = num(body)
if value != nil
self.listeners = value
end
end
# ============================================
# Ergebnisse veröffentlichen
# ============================================
shared.set("song", self.song)
if self.listeners != nil
shared.set("listeners", self.listeners)
end
shared.set("ok", true)
# Nächste Aktualisierung
self.ticks = self.period
end
# ================================================
# Polling
# ================================================
def loop()
if self.ticks <= 0
if !self.in_flight
self.fetch_song()
end
else
self.ticks -= 1
end
end
end
return LautFmData()
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.