Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: KEF LS50W on/off button (Read 1116 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 = '192.168.0.5'
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
    s.sendall(MESSAGE)

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.

Cheers

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:
[PATH OF PYTHON SHELL] [PATH OF PYTHON SCRIPT.PY] [SPEAKER IP] 50001 setting

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\KEF_LS50_light.py" 192.168.0.5 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:
      return
   host=str(sys.argv[1])
   port=int(sys.argv[2])
   input_var=int(sys.argv[3])
   
   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:
      message=messages['Wifi']
   if input_var == 2:
      message=messages['Bluetooth']
   if input_var == 3:
      message=messages['Aux']
   if input_var == 4:
      message=messages['Opt']
   if input_var == 5:
      message=messages['Usb']
   if input_var == 0:
      message=messages['Off']
   try:
      with socket(AF_INET, SOCK_STREAM) as s:
           s.connect((host, port))
           s.sendall(message)
   except:
        return

if __name__ == "__main__":
    main()