Skip to content

Expose now-playing, album colours and tempo as switch attributes#2

Merged
engabd11 merged 2 commits into
mainfrom
feat/expose-now-playing-attributes
Jun 10, 2026
Merged

Expose now-playing, album colours and tempo as switch attributes#2
engabd11 merged 2 commits into
mainfrom
feat/expose-now-playing-attributes

Conversation

@engabd11

Copy link
Copy Markdown
Owner

What

While an area is syncing, the area's switch now publishes extra state
attributes describing what's playing, so a dashboard card can recolour itself to
the album and lock a visualizer to the song:

Attribute Meaning
album_colors The engine's extracted album palette as #rrggbb (when Colour = Album colours).
bpm Detected tempo, once the rhythm model locks.
media_title / media_artist / entity_picture Now-playing from the followed player.
source_player The media_player the sync is following.

Why

The companion Hue Music Sync Card
colours itself from what's playing. It can extract album colours client-side from
the art, but the integration already extracts a vivid palette (k-means) and
tracks tempo — exposing those lets the card use the exact colours driving the
lights and run its bars at the real BPM, instead of approximating.

How

  • SyncSession computes a public_state snapshot (coordinator.py) in its
    render loop and stores the latest BeatGrid and extracted album palette.
  • _maybe_publish() runs ~1 Hz and only fires a state write when the values
    change
    (per track / on tempo lock), so it stays quiet for the state machine
    and recorder. Album colours also publish immediately when extraction completes.
  • SyncManager.area_attributes() returns the active session's snapshot (empty
    when idle); HueMusicSyncSwitch.extra_state_attributes surfaces it, so the
    attributes appear only while syncing and disappear on stop.

No changes to the audio/effects/DTLS core. README updated with the attribute
table.

Notes / review points

  • Attributes are excluded automatically when an area isn't active (switch returns
    None).
  • bpm is rounded to an integer and gated on BeatGrid.locked, so it doesn't
    churn while the tempo estimate settles.
  • If you'd prefer these kept out of the recorder entirely, I can add them to an
    exclude recommendation or move them behind a homeassistant.helpers.entity
    recorder filter — they're already change-gated so the volume is low.

🤖 Generated with Claude Code

engabd11 and others added 2 commits June 11, 2026 02:35
While an area is syncing, the switch now publishes extra state attributes so a
dashboard card can reflect what's playing -- recolour to the extracted album
palette and lock a visualizer to the song:

- album_colors: the engine's extracted album palette as #rrggbb (when
  Colour = Album colours)
- bpm: detected tempo once the rhythm model locks
- media_title / media_artist / entity_picture: now-playing from the followed
  player
- source_player: the media_player being followed

The session computes this snapshot in its render loop and only fires a state
write when the values actually change (per track / on tempo lock), so it stays
quiet for the state machine and recorder. The attributes disappear when the area
stops syncing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@engabd11 engabd11 merged commit 3564430 into main Jun 10, 2026
2 checks passed
@engabd11 engabd11 deleted the feat/expose-now-playing-attributes branch June 10, 2026 16:40
engabd11 added a commit that referenced this pull request Jun 10, 2026
PR #2 exposes album colours, tempo and now-playing on the switch, but not
the playback position. The companion Hue Music Sync Card's visualizer locks
a beat grid to the song from media_position + media_position_updated_at, and
reads them off the switch when no media_player is configured in the card.

Mirror those two anchors from the followed player into the published state.
They re-anchor only on seek / play-pause / track-change, so the recorder
isn't spammed and the card extrapolates the live position between updates.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant