LinkPlay Integration

What app do you use?

Started working to add support for the new media source feature in Home Assistant.
With it, it will be possible to natively access music files on a USB stick in a Linkplay device from Home Assistant.
(it is already possible through an input select and 3 automations, but the new media source way looks way better)

Hi @robi,

So sorry! I copied filter attribute info from another linkplay device that is not always on (bathroom), my apologies. I have updated my original post that has the correct info.

FYI my linkplays in the Den and Living Room are exactly the same and their configuration is the same.

Please post results of the following, while your speaker is playing from Spotify: http://spe.ak.er.ip/httpapi.asp?command=getStatusEx

{ "language": "en_us", "ssid": "LinkPlayA31_5AD4", "hideSSID": "1", "SSIDStrategy": "1", "firmware": "4.2.7717", "build": "release", "project": "a31imuzobox", "priv_prj": "a31imuzobox", "Release": "20191217", "branch": "stable\/wiimu-4.2", "group": "0", "expired": "0", "internet": "1", "uuid": "XXXXXXXXXX", "MAC": "XXXXXXXXXX", "STA_MAC": "XXXXXXXXX", "CountryCode": "CN", "CountryRegion": "1", "date": "2020:09:18", "time": "11:53:30", "tz": "-5.000000", "dst_enable": "1", "netstat": "2", "essid": "626C61636B62657474795F756E74727573746564", "apcli0": "XXXXXXXX", "eth2": "XXXXXXXXXXXXX", "hardware": "A31", "VersionUpdate": "0", "NewVer": "0", "mcu_ver": "0", "mcu_ver_new": "0", "dsp_ver_new": "0", "ra0": "10.10.10.254", "temp_uuid": "10747CBD7214AF91", "cap1": "0x500", "capability": "0x600080", "languages": "0x6", "dsp_ver": "0", "streams_all": "0x7ffffffe", "streams": "0x7ffffffe", "region": "unknown", "external": "0x0", "preset_key": "6", "plm_support": "0x0", "spotify_active": "1", "lbc_support": "0", "WifiChannel": "1", "RSSI": "-44", "battery": "0", "battery_percent": "0", "securemode": "1", "auth": "WPAPSKWPA2PSK", "encry": "AES", "psk": "XXXXXXXXX", "iot_ver": "1.0.0", "upnp_version": "1005", "upnp_uuid": "uuid:XXXXXXXXXXXXXX", "uart_pass_port": "8899", "communication_port": "8819", "web_firmware_update_hide": "0", "web_login_result": "-1", "ignore_talkstart": "0", "silenceOTATime": "", "ignore_silenceOTATime": "1", "iheartradio_new": "1", "security": "https\/2.0", "security_version": "2.0", "privacy_mode": "0", "user1": "278:524", "user2": "5959:6291", "DeviceName": "Den", "GroupName": "Den" }

Please post results of the following, while your speaker is playing from Spotify: http://spe.ak.er.ip/httpapi.asp?command=getPlayerStatus

{"type":"0","ch":"0","mode":"31","loop":"4","eq":"0","status":"play","curpos":"913503","offset_pts":"0","totlen":"1156049","Title":"556E6B6E6F776E","Artist":"556E6B6E6F776E","Album":"556E6B6E6F776E","alarmflag":"0","plicount":"0","plicurr":"0","vol":"100","mute":"0","iuri":"","uri":""}

I see no problem. Could it be perhaps that your Home Assistant and the audio players are not on the same network?
Metadata from Spotify is gathered by HA via UPnP protocol, from the Linkplays, they have to be on the same network with HA.
More and more functionality will be migrated to UPnP as time goes on.

Also: how do you exactly cast your spotify to Linkplay?

That is possible. I have the linkplay devices on a separate VLAN, however I have multicast DNS set up for the devices to be discoverable across separate networks.

There are two ways I can cast from spotify to linkplay. What I have been doing recently is loading Spotify app on my phone, selecting a playlist on the phone, and then selecting the linkplay device as the output (sort of bypassing HA, and only using HA for linkplay groupings and pause/play/next song controls).

Yesterday I set up the spotify HA integration, so I can now control spotify 99% from HA, including selecting the linkplay output. A couple screenshots are below. My ultimate goal is to be able to use HA app exclusively for media control.

Screenshot_20200918_083734

Screenshot_20200918_083759

As far as I read through how Spotify works, you cannot exclude their official app when you want to cast playback to another device (Spotify Premium feature) because the authentication and authorization between you and Spotify servers are done exclusively by the app, and when you select from within their app your Linkplays speaker, it only gets a temporary authentication passed over by the app to the speaker, so the speaker is able to download contents directly without the app. And thus the linkplay speaker is able to forward metadata via UPnP to Home Assistant.

If App disappears from this environment, after a while Linkplay’s authorization will expire and app is needed again to activate it. This is how Spotify works and it’s their intention to make users hard to exclude their official apps.
I also tried HA’s Spotify integration but I’ve found it to be limited in usage and it cannot replace the official app just because of the above. It will behave pretty much like another Linkplay device - in regards to the Spotify API. You still need Spotify’s official app to use HA’s Spotify integration nevertheless.

Yeah I understand… like I said that’s my ultimate goal is to control media fully through HA. Maybe there’s another service that will work better to get me to that goal in the future besides Spotify, I just haven’t had the time to dig into it.

One thing I will mention is that you may want to check out the Spotify HA integration again, there were just some major updates in 0.115 with the media player functionality that make it much more usable.

Just to be clear - even though I have mDNS working, UPnP metadata will not work across VLANs? So there is no fix for this?

Well that depends on how your routing between VLANs is set up. It’s not enough to just enable mDNS forwarding between them, you also have to create allow rules on the router’s firewall for normal traffic to also pass through between the hosts. mDNS is just for announcing and discovery, real data is transferred clasically via HTTP of whatever is required by the services.

Ah yes, again you’re correct. I have allow rules for HA to have full access to devices on the IOT VLAN and also for the media players’ IP to access HA IP so it should work.

While playing, I’m taking a look at the filter attributes of the device and I see certain attributes updating, such as media duration and media position. Are those also UPnP? Should I be seeing album/artist/song metadata as filter attributes for the linkplay device in HA?

I’ve tried the AudioCast, iEast and 4stream apps.

What do you mean by “filter attributes”?

The entity attributes in HA developer tools:

‘Media Duration’ and ‘Media Position’ attributes are updating as Spotify is playing, which is why I believe communication between the device and HA across VLANs is working fine. Should there be attributes here for media metadata too?

Yes it should. Media duration and position are queried via httpapi, media metadata is gathered through UPnP. You should first do a test when HA and Linkplays are on the same network, if they work fine like that, it’s likely a problem of firewalling between your vlans.

Added preliminary support for Home Assistant’s new Media Browser capability, for media files present on a USB stick plugged into the Linkplay device.

For devices with an USB port, make sure that in the sources configuration you have specified a udisk entry. Plug in a USB stick with MP3s on it, and switch to that source in Home Assistant. The Media Browser will populate with the list of files present on the stick, clicking a file will start playing it.

There may be cases when some models switch to USB and start playing automatically as soon as you connect a USB drive - it looks like the device doesn’t report the whole track list in that moment. In those cases, just select USB source again in HA and the list will be re-read from de device.
Currently working and tested with USB disks. SD/TF cards may work, I don’t have such a device to do tests with.

A quick tip : if you experience temporary Unavailable status on the slaves afer unjoining from a multiroom group in router mode, run once the Linkplay-specific command RouterMultiroomEnable. It’s described in the documentation.

Hey @robi,

Can you check to make sure that TTS is working on your end with linkplay media players? I haven’t been able to get TTS to work lately, and after troubleshooting today the only thing that works for me is downgrading the custom component to version 2.0.14 or earlier.

I have no errors in the logs (either TTS component or linkplay component). I know the issue is not with TTS because I was able to play TTS through a non-linkplay media player without error.

The ‘snapshot’ and ‘restore’ functions are also not working for me while playing spotify. I checked the list of presets after running snapshot and there are none saved.

Hi @robi - looks like this may be my error again. I set the logging to debug and it seems like, at least the snapshot error, is another UPnP issue. Let me see if I can get UPnP working like you previously mentioned.

I have to ask - what is the reasoning behind moving functionality to UPnP? My understanding is that this protocol is a severe security trade off for convenience. It’s not unheard of for system owners to segment networks into multiple VLANS for security. I do not want WiFi devices to have direct access to home assistant or other critical infrastructure like switches, web backend, etc.

The httpapi is incomplete and not functioning very well. It responds OK even for deliberately wrong commands, it’s missing functionality present in the UPnP api. It looks like the SOC manufacturer doesn’t really care about httpapi as the Android/Ios apps are all only working via UPnP and all the functionality is implemented there. It’s a mess to have some parts of the communication via one protocol and some parts via other. I think it’s better to have everything uniformized.

I myself have separated VLANs for all the stuff I use, but I prefer Linkplay devices with Ethernet connections thus they don’t connect via WiFi.

TTS broke by the recently introduced Media Browser functionality - I’m so sorry about this. Pushed an update with a fix for it.

Just tested snapshot and restore, with Spotify and they do work fine for me, when Linkplay device, Home Assistant and Android client are on the same VLAN. As I’ve explained earlier, this requires very special permissions to be synced between Linkplay device and the Spotify app. It might be very well possible that snapshot fails because the app is not present/running in the network at that moment, as the app also uses UPnP to discuss with the Linkplay module. The playlist name comes from the app, and Linkplay stores the preset by the playlist name… as the normal workflow is that both Spotify and 4Stream app are running on the same device or in the same time… you simply can’t exclude Spotify app from the ecosystem.

That’s a reason why I won’t renew my subscription with Spotify. It’s too closed system.