Sonos - HA: What's playing?
Shows current track from a Sonos Mediaplayer
About this flow
| System | AWTRIX NG Scripts |
|---|---|
| AWTRIX version | AWTRIX NG |
| Topic | Smarthome |
| Built by | r2k |
| File | RN4Vq32sTYGt.ax · 4.2 KB |
| Icons | — |
| Published | 16 Aug 2026 · updated 16 Aug 2026 |
| Downloads | 38 |
Is this your flow?
If you created this flow, open your saved edit link to add it to your account. You can then manage it whenever you sign in. Adding it to your account replaces the edit link.
Flow description
Based on:
https://flows.blueforcer.de/flow/L7RQFN0Vptle
Purpose:
spotify_now_playing.ax displays the artist and title on AWTRIX as long as the configured media player entity in Home Assistant has the “playing” status.
The app only displays information if sufficient metadata is available:
Standard case: media_artist and media_title are set
Special case: media_artist is missing, but media_title already contains “Artist - Title” or “Artist ˗ Title”
If this information is missing, the app is skipped in the rotation.
Prerequisite:
The script requires the HAFlow from 10der: https://flows.blueforcer.de/flow/EuJbxQZhTQX9
A suitable media player entity must be present in Home Assistant, for example, media_player.spotify
If icons are to be displayed, the configured icon IDs must be available on AWTRIX
Settings:
ha_url: URL of your Home Assistant instance
ha_token: Long-lived access token from Home Assistant
entity: Spotify or media player entity
refresh_seconds: Polling interval
scroll_speed: Track playback speed
spotify_icon_id: Icon for Spotify playback, default 18207
airplay_icon_id: Icon for AirPlay playback
radio_icon_id: Icon for radio or other playback
Behavior:
Display only when state == playing
Output format: Artist - Title
Spotify is detected via source or media_content_id
AirPlay is detected via source == AirPlay
Everything else uses the radio icon
The text scrolls twice, and then AWTRIX returns to the app's normal rotation
Pressing the middle button (select / OK) triggers an immediate refresh
RN4Vq32sTYGt.ax
# @name SpotifyNowPlaying
# @desc Zeigt Interpret und Titel aus Home Assistant, wenn Spotify spielt
# @author r2k
# @version 1.1
# @config ha_url text "Home Assistant URL" default="http://homeassistant.local:8123" maxlen=128
# @config ha_token text "Home Assistant Token" default="PASTE_LONG_LIVED_TOKEN_HERE" maxlen=256
# @config entity text "Spotify Entity" default="media_player.spotify" maxlen=64
# @config refresh_seconds number "Refresh" default=15 min=5 max=120 unit=s
# @config scroll_speed slider "Scrolltempo" default=70 min=30 max=150 unit=%
# @config spotify_icon_id text "Spotify Icon ID" default="18207" maxlen=16
# @config airplay_icon_id text "AirPlay Icon ID" default="" maxlen=16
# @config radio_icon_id text "Radio Icon ID" default="" maxlen=16
import HAflow
class SpotifyNowPlaying
var ticks, in_flight
var label, text_color, icon_id
var entity, refresh_seconds, spotify_icon_id, airplay_icon_id, radio_icon_id, scroll_opts
def init()
HAflow.init(store.get("ha_url"), store.get("ha_token"))
self.entity = store.get("entity")
self.refresh_seconds = store.get("refresh_seconds")
self.spotify_icon_id = store.get("spotify_icon_id")
self.airplay_icon_id = store.get("airplay_icon_id")
self.radio_icon_id = store.get("radio_icon_id")
self.ticks = 0
self.in_flight = false
self.label = nil
self.icon_id = self.spotify_icon_id
self.text_color = settings.get("textColor")
if self.text_color == nil
self.text_color = 0xFFFFFF
end
self.scroll_opts = {
"mode": "loop",
"whenFits": "static",
"speed": clamp(store.get("scroll_speed"), 30, 150),
"gap": 8,
"holdMs": 400,
"repeat": 2
}
end
def set_inactive()
self.label = nil
end
def on_entity(data, error)
self.in_flight = false
if error != nil || data == nil || !isinstance(data, map)
self.set_inactive()
return
end
var state = data.find("state")
if state != "playing"
self.set_inactive()
return
end
var attrs = data.find("attributes")
if !isinstance(attrs, map)
self.set_inactive()
return
end
var artist = attrs.find("media_artist")
var title = attrs.find("media_title")
var source = attrs.find("source")
var media_content_id = attrs.find("media_content_id")
self.icon_id = self.radio_icon_id
if type(source) == "string" && source == "AirPlay"
self.icon_id = self.airplay_icon_id
elif type(source) == "string" && re.search("Spotify", source) != nil
self.icon_id = self.spotify_icon_id
elif type(media_content_id) == "string" && re.search("spotify:", media_content_id) != nil
self.icon_id = self.spotify_icon_id
end
if type(artist) == "string" && artist != "" && type(title) == "string" && title != ""
self.label = artist + " - " + title
return
end
if (artist == nil || artist == "") && type(title) == "string" && title != ""
var m = re.match("^(.+) ˗ (.+)$", title)
if m == nil
m = re.match("^(.+) - (.+)$", title)
end
if m != nil && m[1] != nil && m[1] != "" && m[2] != nil && m[2] != ""
self.label = m[1] + " - " + m[2]
return
end
end
self.set_inactive()
end
def loop()
if self.ticks <= 0
self.ticks = self.refresh_seconds
if !self.in_flight
self.in_flight = true
HAflow.entity(self.entity, / data, err -> self.on_entity(data, err))
end
end
self.ticks -= 1
end
def should_show()
return self.label != nil && self.label != ""
end
def draw()
clear()
var text_x = 0
if self.icon_id != nil && self.icon_id != ""
if !icon(self.icon_id, 0, 0)
rect_fill(0, 0, 8, 8, 0x222222)
end
text_x = 9
end
scroll_text(text_x, 6, width() - text_x, self.label, self.text_color, self.scroll_opts)
end
def on_button(btn)
if btn == "select"
self.ticks = 0
end
end
end
return SpotifyNowPlaying()
Install it on your AWTRIX NG
Add this flow to your AWTRIX NG. It will start appearing on your display after installation.
Unable to connect? Download the flow and add it in the Scripts section of your AWTRIX. Advanced users can also use this command:
Discussion 0
Ask a question, suggest a change or share how you use it.
No comments yet. Start the conversation.
More flows for AWTRIX NG Scripts or Smarthome
Something wrong with this flow? Report it.
Have an idea?
Sign in to ask questions and join the conversation.