Giter VIP home page Giter VIP logo

lgtvdevicelistener's Introduction

LGTVDeviceListener: switch LGTV inputs based on Windows device changes

Brought to you by Etienne Dechamps - GitHub

If you are looking for executables, see the GitHub releases page.

Description

LGTVDeviceListener is a small Windows tool that makes it possible to switch inputs on a networked WebOS LG TV (e.g. G1), in response to a hardware device appearing or disappearing from the system.

This is especially useful to build a poor man's KVM switch, by combining LGTVDeviceListener with a USB switch. In this way the TV can be made to follow the presence of the USB device and automatically switch video inputs in lockstep when the USB device is switched.

Requirements

  • Windows Vista or greater
  • A WebOS LG TV that is accessible over the network (wired or WiFi)

How to use

LGTVDeviceListener is a command-line application. Pass --help to see all available options.

Preparation

After downloading the executable, run it with --url first. For example, if your TV is listening on 192.168.42.42:

LGTVDeviceListener.exe --url wss://192.168.42.42:3001

This will do two things:

  1. A new client key will be registered with the TV if not done already. Your TV will ask you to confirm the registration.
  2. LGTVDeviceListener will then start listening for device events and log them to the console.

While listening, add and remove the device you want to use as the trigger. (For example, if it's a USB device, disconnect/reconnect it.) You will see LGTVDeviceListener logging "Device added" and "Device removed" events. Take a note of the device name - the identifier that normally starts with \\?\.

In some cases there could be many devices shown, especially for composite devices such as USB hubs. In that case you can pick one at random, though it usually makes the most sense to use the device with the shortest name because that's typically the "root" device (i.e. the hub itself in the case of a USB hub).

Once that's done, kill LGTVDeviceListener by hitting CTRL+C and move on to the next step.

Running as a console application

For quick test runs you can run LGTVDeviceListener directly as a console application. You will need to specify the following parameters on the command line:

  • --url: see previous section.
  • --device-name: the device name you chose in the previous section.
  • --add-input: the input that the TV should switch to when the device is added.
    • This can be anything that the TV's switchInput API will accept. For example: HDMI_3.
  • --remove-input: the input that the TV should switch to when the device is removed.

Note that you don't have to specify both --add-input and --remove-input - it is possible to specify only one of them.

Here's an example of a complete LGTVDeviceListener command line:

LGTVDeviceListener.exe --url wss://192.168.42.42:3001 --device-name \\?\USB#VID_1234&PID_5678#foo&1&2#{bar} --add-input HDMI_1 --remove-input HDMI_2

With the above command, the TV at 192.168.42.42 will be switched to the HDMI 1 input when the \\?\USB#VID_1234&PID_5678#foo&1&2#{bar} device appears, and will be switched to the HDMI 2 input as soon as the same device disappears from the system.

This will happen for as long as LGTVDeviceListener is running. If you'd like to make this setup permanent, see the next section.

Running as a Windows service

If you'd like LGTVDeviceListener to run quietly in the background without having to run it as a console application, the cleanest way is to set it up as a Windows service:

  1. Move LGTVDeviceListener.exe to a permanent location that is accessible system-wide (e.g. in Program Files (x86)).
  2. Open a command prompt as Administrator.
  3. Run LGTVDeviceListener using the same command you used in the previous section, but add the --create-service option.

For example:

LGTVDeviceListener.exe --url wss://192.168.42.42:3001 --device-name \\?\USB#VID_1234&PID_5678#foo&1&2#{bar} --add-input HDMI_1 --remove-input HDMI_2 --create-service

LGTVDeviceListener will set itself up as a new Windows service called LGTVDeviceListener and start it. From this point on, LGTVDeviceListener will be operating silently in the background and will start with Windows. The parameters used for the service are the ones you included with the --create-service command.

When running as a service, messages that are normally logged to the console, including any errors, will be logged to the Windows Event Log (Application) instead. You can use the Windows Event Viewer to see them.

To delete the service, run the following commands:

sc.exe stop LGTVDeviceListener
sc.exe delete LGTVDeviceListener

You can then re-create the service with different command-line parameters if you so wish.

See also

  • LGTVCompanion is a tool for automatically turning LG TVs on and off in response to Windows power events.
  • bscpylgtv can be used to send arbitrary commands to LG TVs.

lgtvdevicelistener's People

Contributors

dechamps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sliceofbytes

lgtvdevicelistener's Issues

Client key file has nonsensical "CREATOR OWNER" ACL

Currently LGTVDeviceListener sets an ACE on the client key file that gives "CREATOR OWNER" full control.

The intent was to give the owner of the client key file full control, but that's not what happens in practice. Somewhat counter-intuitively, the "CREATOR OWNER" special SID does not affect the access modes of the owner of the object the ACE is attached to. Instead, a "CREATOR OWNER" ACE is used as a template to form an ACE that is automatically added to child objects (with the trustee being the creator of the child object).

Because files cannot have child objects, it doesn't make any sense to set a "CREATOR OWNER" ACE on a file. The ACE is a no-op.

Device events not logged to the console when only --url is used

The instructions state:

After downloading the executable, run it with --url first.

LGTVDeviceListener.exe --url ws://192.168.42.42:3000

This will do two things:

  1. โ€ฆ
  2. LGTVDeviceListener will then start listening for device events and log them to the console.

This is a lie - LGTVDeviceListener does not log device events if --url is passed (or, more specifically, it requires --verbose to be added as well). Either the instructions should be fixed, or LGTVDeviceListener should be changed to log device events in this case.

Cannot register a new client key - Failed to set ACL entries: No mapping between account names and security IDs was done

I've tried executing for the first time but it keeps failing with this message:

FATAL: Failed to set ACL entries: No mapping between account names and security IDs was done.

  1. I see the confirmation dialog on my TV, so I know it's connecting.
  2. I'm using Windows 11 with a microsoft account connected.
  3. Tried with normal and admin powershell.
  4. I searched the web and tried the fixes, but they all say it's caused when a username is changed. However, I never changed my username.

Thanks in advance!

WebSocket client error: Failed reading HTTP status line

After updating to version 03.30.16, this error comes up and no longer switches input. Verbose doesn't display any additional information.

[info ] Switching LGTV to input: HDMI_1
[ERROR ] In device event listener: WebSocket client error: Failed reading HTTP status line from ws://xxx.xxx.xxx.xxx:3000 (retries: 0, wait time: 0.000000 ms, HTTP status: 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.