Kef ls50 Wireless

already done it ;-). play/pause, next/prev are non-operational on USB - as to be expected. I believe streaming thru USB is uni-directional only.

For those with the old hardware version that can’t be turned on via the App i.e. models where WiFi goes off when the unit is off, if you don’t want to see the “Unavailable” state in the UI and prefer On / Off, this can be done by tweaking media_player.py in this custom component.

modded in various places

import subprocess

....

#in the KEFMediaPlayer class:

    # inside  the init constructor
    ...
        """Initialize the media player."""
...
        self._host = host


    def pingDevice(self):
        """ping DEVICE - AR MOD"""
        cmd = ['ping', '-c1', '-W2', self._host ]
        response = subprocess.Popen(cmd, stdout=subprocess.PIPE)
        stdout, stderr = response.communicate()
        if response.returncode == 0:   
            return True
        else:
            return False

    @property
    def state(self):
        """Return the state of the device."""
        if not self.pingDevice():
            self._state = STATE_OFF
        return self._state

    @property
    def available(self):
        """Return if the speaker is reachable online."""
        # avoid 'unavailable' by returnining TRUE
        # and also set the state based on ping
        if not self.pingDevice():
            self._state = STATE_OFF
        return True

I could just add this to the actual integration itself.

I would just copy this logic.

@basnijholt that would be much better than my quick hack :slight_smile:
Note that to get this to behave in the expected way, you will need to tweak the available() method based on ping response, and you want to do this only for the old hardware (e.g. for people that disable the on/off control) that is not “always connected”. For the new hardware, your current logic makes sense.

Another exciting thing is coming!

I have added options to change all DSP settings for the KEF speakers! :tada:

See this PR, when it’s merged, we can change all settings that one can change in the KEF Control App.

1 Like

I seem to have lost my integration with the upgrade to 108. Anyone else?

2020-04-08 13:10:42 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up kef platform for media_player
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 186, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 295, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 445, in _async_add_entity
    await entity.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/kef/media_player.py", line 381, in async_added_to_hass
    self.hass, self.update_dsp, DSP_SCAN_INTERVAL
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 293, in async_track_time_interval
    remove = async_track_point_in_utc_time(hass, interval_listener, next_interval())
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 284, in next_interval
    return dt_util.utcnow() + interval
TypeError: unsupported operand type(s) for +: 'datetime.datetime' and 'int'

That is correct! I made a mistake in the code, sorry.

I’ve already fixed it in this PR.

I also told balloob and he told me it will be in 0.108.1, which will be out very soon!

Ok, no worries. Thanks for the integration, it’s much better than using the KEF app. Much appreciated!

Not sure since when it happened, guess it came with the update to 0.108. I now see this frequently in the logs and given the function update_dsp() is mentioned it might have to do with the new feature to configure the KEF LS50 Wireless DSP.

async_track_point_in_utc_time.<locals>.point_in_time_listener(<Event time_c....008180+02:00>) at /usr/src/homeassistant/homeassistant/helpers/event.py:234
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 250, in point_in_time_listener
    hass.async_run_job(action, now)
  File "/usr/src/homeassistant/homeassistant/core.py", line 374, in async_run_job
    target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 291, in interval_listener
    hass.async_run_job(action, now)
  File "/usr/src/homeassistant/homeassistant/core.py", line 376, in async_run_job
    self.async_add_job(target, *args)
  File "/usr/src/homeassistant/homeassistant/core.py", line 308, in async_add_job
    task = self.loop.create_task(target(*args))
TypeError: update_dsp() takes 1 positional argument but 2 were given

Thanks for reporting!

That definitely a bug!

Could you perhaps open an issue here?

will do this pm. Thx for the instant response.

Now that I’ve added all these services in the kef integration I can do:

Screen Recording 2020-06-15 at 16.42.46.mov

See this commit range to see the code that does this.

See my entire config at github/basnijholt/home-assistant-config.

2 Likes

Awesome awesome awesome. I can change sub volume when watching films vs listening to music!

1 Like

@basnijholt thanks for this great integration. Using it daily in my home office

I was hoping the new Equalizer settings would be exposed in the Media Player details page. It seems you have to crate your own “expandable” card with this for now. Any chance this can be added to the Media Player card as well?

Does anyone use the KEF integration with a LSX?

I have them but every now and then they become Unavailable until I restart HA. Does any else observe this problem and has an idea?

I have tried a LOT. It gets here but then gets an exception forever.

I have a pair of KEF LSX, but I seem to need to power cycle my speakers to get them back once they become Unavailable. When they show up as Unavailable in Home Assistant, they are also not accessible via KEF Control. I do still however have the ability to stream to them using Spotify Connect, and control volume (through Spotify), and the physical remote control works. I also have access to their basic interface on port 80, where you can change some WIFI settings etc. It’s only the control interface that has crashed.

I raised this ticket:

I seem to have another issue with my KEF LSX, which is that they don’t remember the mode/DSP settings after wake-up from stand-by. They are back at default. If I send the “correct” DSP settings, settings which the speakers think they should already have, then they are still not applied. I have to change to a different DSP value, and then back to the desired value.

Both of these issues I have raised with KEF support, but so far they haven’t been very helpful.

My speakers are running firmware p20.4101909240.105243422.

1 Like

Hi @logan893, thanks for looking into this as well. I have struggled with this problem for some months. I can now verify that when disabling DSP settings updating, this speaker does not become unavailable.

Maybe it is because of some specific DSP setting, so I am iterating over all settings to find out whether there is a single culprit.

HA / 0.117 - one small issue I noticed is that if I restart HA and the LS50W are off, and I turn them on a while later, my .yaml configuration information (with the static IP address and other configuration options) gets ignored, and the KEF integration somehow auto-discovers the speakers again later assigning them a new name (kef_ls50w_2), hence breaking my front end configuration (media card)

In my setup, auto-discovery is off (I commented out the “Discovery:” entry. So not sure how is it possible that the KEF integration is ignoring this and auto-adding newly discovered speakers.

I think this has been going on since the first release of the KEF integration.

Every time this happens, I can see in the Entities browser that the entity name I defined in yaml (kef_ls50w) shows up in “not available” state (and the button to “Remove”/Delete it is enabled), and a second, new entity (kef_ls50w_2) is also listed and this one is active. Every time I have to delete the original entity, and then rename the new entity to mach the name I used in my lovelace UI yaml so my view work.

I wonder if this issue is related to the fact that my speakers are first-generation and their WiFi connection does NOT stay on while the speakers are off (hence I can’t do remote turn-on).

@basnijholt it seems that during initialization, this integration assumes that the KEF’s are always- reachable even while off, hence the first-gen speakers need to be on while HA is initializing, otherwise the KEF integration gets confused as per the above. Can you please add support for first-gen speaker intialization, so that the integration waits for as long as needed (e.g. a week or a month or forever) for the speakers to be turned on, before giving up and erroring out?

I have exactly the same problem!

Hi All
My LS50s have a serial number that is post the serial for which wake on lan should work (and have the latest firmeware), but it doesn’t. I’ve tried WOL via HA and my via my router, and media_player.turn_on doesn’t work either. All other funcitonality appears to work.

The only thing I can think of as being an issue is that when I first got the speakers and uploaded the latest firmware, I bricked them somehow. The service agent by memory said they had to change the network card to resolve the issue.
Any advice on how to test further?

And another question, what does this attribute mean: supported_features: 19901
Cheers