Music Player Tile - TrackData not being pulled

I’m trying to get a music player tile working with Hubitat and a device driver I wrote for integrating with Volumio. But I’m having trouble getting the SharpTools music player tile to display the track info. The controls and volume are working, but none of the track info.

The driver is invoking the MusicPlayer capability, which includes the trackData attribute. According to the linked post below, trackData is used by SharpTools to get the track information and album art.

https://community.sharptools.io/t/advice-on-custom-text-display-through-hubitat/5388/6

I am able to update the trackData attribute in the device properties on my hub, but it is either not being passed to SharpTools or it’s structured wrongly somehow. To troubleshoot, I statically defined trackData as an array according to the linked post above, but when I update the device attribute, the SharpTools tile never changes. I also tried passing the entire JSON return from the Volumio player to trackData (it contains mostly the same key names), but that didn’t work.

    def trackData = [
        artist: "ArtistName",
        title: "Track Title",
        album: "AlbumName",
        image: "https://i.ytimg.com/vi/v2e2avfPUMA/maxresdefault.jpg",
        source: "YouTube",
    ]
    ( updateAttribute("trackData", trackData) )
    log.debug trackData

I’m at a loss for what else to try, so any suggestions would be appreciated.

Can you clarify how you are testing? It’s not clear what tile type you’re looking at or where you aren’t seeing what you expect.

After adding new attributes to a device, you would want to proceed through the authorization process again so it syncs the new device details over (capabilities, attributes, etc). Then you would want to add the device to a dashboard and, assuming it has the right capabilities/attributes, change the tile layout to use the Album Art tile layout.

If the device was added to a dashboard before a capability/attribute was added and before being resynced, you might try refreshing the page while viewing the dashboard as that performs a series of healthchecks including one that can clean up any missing event subscriptions.

Yeah, I’ll try to clarify. On the Hubitat side, I have a device created that interfaces with an API on the Volumio music player to pull status, artist, title, album, volume, etc and make them available as attributes. The driver for this device includes the MusicPlayer capability, which in turn make the attribute trackData. The trackData attribute is visible in Hubitat in the device details, and my understanding is that SharpTools pulls from this attribute to populate music player tiles.

On the SharpTools side, I have a tile for my Volumio device, configured as a Music Player Tile. The play/pause, next/prev, mute/unmute, and volume attributes show correctly in the tile, but no track information is displayed along the bottom. When I click on “details” within the tile, no track information is present there either. Clicking “Refresh” when in details doesn’t pull any new data.

I just tried re-adding the device to a dashboard, refreshing the webpage while the dashboard was open, and re-authorizing the hub with SharpTools. No luck.

My main question is whether I’m constructing the content for the trackData attribute correctly. The Hubitat documentation wants it to be a JSON object, but it accepts and displays a string array on the device page just fine. I’m in the process of modifying the driver now, so this is a good time to fix whatever is going on with trackData.

Can you PM me the Doc ID of the device in question?

It needs to be a valid JSON object with those properties. It can either be a properly formatted object or a valid JSON stringified object.

JSON Object

{artist: "ArtistName", title: "Track Title", album: "AlbumName", image:"https://i.ytimg.com/vi/v2e2avfPUMA/maxresdefault.jpg", source: "YouTube" }

JSON Stringified Object

'{"artist":"ArtistName","title":"Track Title","album":"AlbumName","image":"https://i.ytimg.com/vi/v2e2avfPUMA/maxresdefault.jpg","source":"YouTube"}'

or

"{\"artist\":\"ArtistName\",\"title\":\"Track Title\",\"album\":\"AlbumName\",\"image\":\"https://i.ytimg.com/vi/v2e2avfPUMA/maxresdefault.jpg\",\"source\":\"YouTube\"}"

It cannot be a Groovy stringified object stored in the attribute:

[artist:"ArtistName", title:"Track Title", album:"AlbumName", image:"https://i.ytimg.com/vi/v2e2avfPUMA/maxresdefault.jpg", source:"YouTube"]

Of course what you defined for use within Groovy doesn’t necessarily correspond to what gets stored in the attribute as there are some implicit translations that occur, so pay close attention to the output that ultimately gets stored in the attribute.


Edit: I haven’t tested in a Hubitat driver to see what format the system outputs an object as when stored in an attribute: (1) JSON Object (2) JSON Stringified Object (3) Groovy Stringified Object… but it looks like you could explicitly JSON stringify things if you need to.

From a quick search, it looks like you can import JsonOutput and use that to properly JSON stringify your output:

import groovy.json.JsonOutput;
def trackData = [
        artist: "ArtistName",
        title: "Track Title",
        album: "AlbumName",
        image: "https://i.ytimg.com/vi/v2e2avfPUMA/maxresdefault.jpg",
        source: "YouTube",
    ]
def formattedOutput = JsonOutput.toJson(trackData)

That was the missing piece. I had tried using JsonOutput.toJson() and couldn’t figure out why it was failing. I didn’t realize I had to add the class first.

The tile is working properly now. Thanks for the help.

1 Like