LinkPlay Integration

Grab the file again.

Regrabbed files.
Join/unjoin working.
Snapshot/restore working.
Seems fine regarding functionality.

I am using

    hide:
      icon_state: false

on mini-media-player and the icon is always yellow. Is this normal? It should be grayed on stopped and yellow when playing.

device_name issuse is still present

Configuration validation
Validate your configuration if you recently made some changes to your configuration and want to make sure that it is all valid
Configuration invalid

                          Invalid config for [media_player.linkplay]: [device_name] is an invalid option for [media_player.linkplay]. Check: media_player.linkplay->device_name. (See ?, line ?). 
Invalid config for [media_player.linkplay]: [device_name] is an invalid option for [media_player.linkplay]. Check: media_player.linkplay->device_name. (See ?, line ?). 

Thank you for your tests.

In my understanding of mini-media-player’s manual, icon_state if set to be hidden, actually means it shouldn’t change color. But to be honest I also don’t see any difference in color behavior of the speaker icon color. Maybe we misunderstand something, I don’t know. The color itself depends on the theme you’ve set in Lovelace frontend. The mini-media-player manual doesn’t specify what states should trigger the color change.
But as I’m writing these sentences now I think it may watch not the play/stop status, but the on/off status, which Linkplay modules do not support. These devices can only be on, they can never be off (if it’s off, it’s disconnected from the network -> no status is available and cannot be turned on -> device unavailable). So the usable statuses are ON, PLAYING, PAUSED, UNAVAILABLE. Strangely HA doesn’t support a STOPPED state at all. I guess ON is a state when the unit is available but not playing nor paused… (means stopped). We can’t use actively the UNAVAILABLE and the OFF states because these prohibit in HA sending some commands like you can’t press play while a device is OFF etc. as I’ve recently discovered.

device_name - delete it from your config is not needed anymore and will never be needed. The component reads out the correct device name from the module firmware.

I thank you for your work and time. My speakers are happier with this custom integration. Just received the third one :slight_smile:

I thought it is like on switches: yellow when on and gray when off.

Do your units have separate USB and SD card slots? Can you please test MP3 files playback from these sources?
Things to check are if your devices support reading out Id3 tags from MP3s (which: Id3v1, or v2 or v3) do they display in HA? In the new firmwares Id3 suppprt is broken (reports ‘unknown’) so I take the filename and try to split it in artist and title (as long as the file is named ‘Artist - Title.mp3’)
Check also skip track forward backward, shuffle, seek if you can, and both from USB and SD. What does the device do if you have both an USB and an SD plugged in? Can you configure as different sources in HA? Please run command httpapi.asp?command=getPlayerStatus in your browser when you play from USB and from SD separately.

Did you try to register for a last.fm API key? do you see coverart downloaded for recognized titles?

The original version of this compnent uses eyed3 python module to read out Id3 from the files directly. But it’s funny that HA can’t access the file directly because the USB stick is plugged into the speaker. It tries to download the file from the speaker to HA server but of course it always fails… It’s also incompatible with Icecast as live webstreams don’t employ Id3s and of course they are infinite long… I don’t know what was the intention of the original author with this procedure… as it will never work in real life…

Some multiroom fine-tuning done;
Device naming cleared up, now using the name key in the config you can give a different name to the player if you want to (old device_name key not used anymore), the correct device name (needed for multiroom in AP mode) will be gathered from the unit firmware anyway. This is useful if you want different structured entity names from the friendly names displayed.

Hey robi just wanted to say great job with resurrecting this integration. I have a bunch of Muzo cobblestones that I love and would love even more if I could control via Home Assistant. So far everything is working great for me. It would be awesome if, when a TTS notification is sent, Spotify playback could pause, TTS run, and then Spotify playback could resume but I understand this is quite difficult.

Keep up the good work!

Thanks for the feedback. I didn’t think yet of Spotify snapshot/restore, but I’ll investigate that later.

Further functionality in the testing branch: Browsing USB media files through Lovelace UI.

No, both. Show unknown in app.

Show title & artist in HA - working.

Selecting USB (udisk) is working.
Selecting SD (tfcard) - not working - goes to WIFI.

Seek is working

USB selected from HA:

{"type":"0","ch":"0","mode":"11","loop":"0","eq":"0","status":"play","curpos":"139083","totlen":"199000","Title":"4261737368756E746572202D2043616C63757474612E6D7033","Artist":"756E6B6E6F776E","Album":"756E6B6E6F776E","alarmflag":"0","plicount":"1","plicurr":"1","vol":"6","mute":"0"}

SD selected from speaker button:

{"type":"0","ch":"0","mode":"16","loop":"0","eq":"0","status":"play","curpos":"8417","totlen":"210000","Title":"416C65736861204469786F6E202D2054686520426F7920446F6573204E6F7468696E672E6D7033","Artist":"756E6B6E6F776E","Album":"756E6B6E6F776E","alarmflag":"0","plicount":"1","plicurr":"1","vol":"6","mute":"0"}

Yes.

Testing branch is not available on github.

Thanks. Testing is available again (merged it because HACS finally included this version too).
Posted a test version. Please grab all the files, enable debug for this component with:

logger:
  default: warn
  logs:
    custom_components.linkplay: debug

And send me all the debug messages containing “Source check” while you select SD card from your sources list.
Please post your config part where you specify your sources.

Edit: please remove the USB stick and leave only the SD card inserted, and then try to switch to USB source in HA. Does it play from SD? Also check if you can see the tracks through the input_select component in HA (as described in readme). Also run the command above and see if you get the same value for mode.

Edit2: put back both the USB and the SD card, and run these commands:

httpapi.asp?command=setPlayerCmd:switchmode:TFcard
httpapi.asp?command=setPlayerCmd:switchmode:tfcard

Does any of these switch to SD?

No speaker on HA after restart.

Log Details (ERROR)
Logger: homeassistant.bootstrap
Source: loader.py:322
First occurred: 7:48:49 PM (2 occurrences)
Last logged: 7:48:49 PM

Error setting up integration media_player - received exception
Error setting up integration media_extractor - received exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/discovery.py", line 183, in async_load_platform
    setup_success = await setup.async_setup_component(hass, component, hass_config)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 61, in async_setup_component
    return await setup_tasks[domain]  # type: ignore
  File "/usr/src/homeassistant/homeassistant/setup.py", line 68, in async_setup_component
    return await task  # type: ignore
  File "/usr/src/homeassistant/homeassistant/setup.py", line 137, in _async_setup_component
    await async_process_deps_reqs(hass, config, integration)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 318, in async_process_deps_reqs
    if not await _async_process_dependencies(hass, config, integration):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 92, in _async_process_dependencies
    results = await asyncio.gather(*tasks.values())
  File "/usr/src/homeassistant/homeassistant/setup.py", line 61, in async_setup_component
    return await setup_tasks[domain]  # type: ignore
  File "/usr/src/homeassistant/homeassistant/setup.py", line 68, in async_setup_component
    return await task  # type: ignore
  File "/usr/src/homeassistant/homeassistant/setup.py", line 154, in _async_setup_component
    hass, config, integration
  File "/usr/src/homeassistant/homeassistant/config.py", line 780, in async_process_component_config
    platform = p_integration.get_platform(domain)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 322, in get_platform
    f"{self.pkg_path}.{platform_name}"
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 724, in exec_module
  File "<frozen importlib._bootstrap_external>", line 860, in get_code
  File "<frozen importlib._bootstrap_external>", line 791, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/linkplay/media_player.py", line 1569
    except KeyError:
         ^
SyntaxError: invalid syntax

Oops. Sorry about that. Grab the file again.

No, it switches to wifi.

Yes, httpapi.asp?command=setPlayerCmd:switchmode:TFcard

No tracks
Untitled

Which one?

How to use WriteDeviceNameToUnit?

OK, good to know that it works! Nevermind for the mode, if setPlayerCmd:switchmode:TFcard swithces to SD card, make sure that in your config, that you have present the entry 'TFcard': 'SD card',. The part before “”:"" has to remain exactly TFcard.

As for the tracks, do they appear for USB?
Note that in the corresponding automations, you need to use the correct source name, which is the part after “”:"".

No. There is nothing in the dropdown list.

You have to be with the player set on the USB source.
In device attributes, what number do you see for track_count?

track_count: 0

In the app on Android (4Stream), are you able to see the tracks when you switch to USB?

As for the WriteDeviceNameToUnit, I’ve pushed an update to the testing branch. Grab all the files again, and use linkplay.command service with parameter:
command: 'WriteDeviceNameToUnit: My New Device Name'
The new device name should appear both in HA and in the Android app.