/lg-tv-control-macos

Automatically wake/sleep and change the input of your LG TV when used as a monitor on macOS

Primary LanguageLua

LG TV Control for macOS

Automatically wake/sleep and change the input of your LG TV when used as a monitor on macOS.

This script uses Hammerspoon to detect system events such as power off, sleep, and wake.

Requirements

Installing Requirements

This assumes that you already have Homebrew installed. If you don't, get it first.

Installing Hammerspoon

brew install --cask hammerspoon

Installing Python & LGWebOSRemote

# You can skip this if you already have Python installed and know what you're doing.
brew install python

# Then install LGWebRemote (version 2023-01-27 or newer)...
mkdir -p ~/opt
python -m venv ~/opt/lgtv
cd ~/opt/lgtv
source bin/activate
pip install git+https://github.com/klattimer/LGWebOSRemote

Configuring LGWebOSRemote

By now, you should be able to run

lgtv scan ssl

and see some info about your TV. Grab your TV's IP address from the output. Then:

lgtv auth <ip_address_here> MyTV ssl

and follow the instructions on your TV.

Now, try the following:

lgtv MyTV swInfo ssl
lgtv MyTV screenOff ssl

If everything is working as expected, your screen should turn off.

Installing the Hammerspoon script

  1. Copy lgtv_init.luafrom this repo to ~/.hammerspoon
  2. Run the following
mkdir -p ~/.hammerspoon
touch ~/.hammerspoon/init.lua
echo "require \"lgtv_init\"" >> ~/.hammerspoon/init.lua
  1. Change the HDMI input at the top of the Lua script, if needed.

Special Thanks

Thanks to @greyshi for extending upon my initial Wake On LAN gist and introducing LGWebOSRemote.