Skip to main content
Topic: KEF LS50W on/off button (Read 278 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

KEF LS50W on/off button

Hi Fellow Enthusiasts!

I have recently acquired a set of KEF LS50w speakers. i figured out how to use the UPNP/DLNA mediarenderer output to use them. It can also control the volume and mute the speakers. I found out that it is relatively easy to switch them on with few python commands through the TCP/IP protocol.
I would like to do the following:
- Have a special button in foobar2000 which would turn on my speakers to wifi
- Have another button which would turn off my speakers
Both would be doing the same but sending different tcp/ip messages.

Would there be a way to program a new module/ special button for this purpose?

The python script is the following:
from socket import *

host = ''
port = 50001

with socket(AF_INET, SOCK_STREAM) as s:
    s.connect((host, port))
    MESSAGE = bytes([0x53, 0x30, 0x81, 0x12, 0x82]) #WIFI
    #MESSAGE = bytes([0x53,0x30,0x81,0x9b,0x0b]) #TURN off

Re: KEF LS50W on/off button

Reply #1
You might be able to run the python script with foo_run and assign the action to a toolbar button.

Re: KEF LS50W on/off button

Reply #2
^ Yes, I was going to suggest both foo_run or foo_scheduler can run external programs, but foo_scheduler might be preferred here, as it creates a main menu command, while foo_run needs tracks selected in the playlist context menu.


Re: KEF LS50W on/off button

Reply #3
Thank you very much guys, it is working!

 It took me a while to modify the script, but it works. If anyone is interested, here is how I did it:
- Install the foo_run component
- Add the following run service:

SPEAKER IP is the IP of the KEF LS50w, 50001 is the communication port.
The settings are the following: 0 - Off; 1 - Wifi; 2 - Bluetooth; 3 - AUX; 4 - OPT; 5 - USB

- Add a button next to the top buttons by Customize buttons / Context / Run service
- The icon is going to be a question mark. You can find some appropriate ones online, but it needs to be in the .ico format.
- Profit.

In my case the command is the following for Wifi:
C:\Users\lampee\Anaconda3\python.exe "C:\Users\lampee\Documents\Python Scripts\" 50001 1

I added two run services, one for Wifi and one for Turnning the speakers off. Wifi turns on the speakers if they are off (if you have the newer version of the speakers, I guess after August 2019)

This is the python script to be saved as a .py file. I am not uploading it into github, it's just too short. It could be shortened a whole lot more, but then it won't be so readable.

from socket import *
import sys

def main():
   if len(sys.argv) != 4:
   messages={'Wifi':bytes([0x53, 0x30, 0x81, 0x12, 0x82]),
             'Bluetooth':bytes([0x53, 0x30, 0x81, 0x19, 0xAD]),
           'Aux':bytes([0x53, 0x30, 0x81, 0x1A, 0x9B]),
           'Opt':bytes([0x53, 0x30, 0x81, 0x1B, 0x00]),
           'Usb':bytes([0x53, 0x30, 0x81, 0x1C, 0xF7]),
           'Off':bytes([0x53, 0x30, 0x81, 0x9b, 0x0b]),
   if input_var == 1:
   if input_var == 2:
   if input_var == 3:
   if input_var == 4:
   if input_var == 5:
   if input_var == 0:
      with socket(AF_INET, SOCK_STREAM) as s:
           s.connect((host, port))

if __name__ == "__main__":

SimplePortal 1.0.0 RC1 © 2008-2020