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.
- Hammerspoon
- Python 3
- LGWebOSRemote (version 2023-01-27 or newer)
This assumes that you already have Homebrew installed. If you don't, get it first.
brew install --cask hammerspoon
# 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
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.
- Copy
lgtv_init.lua
from this repo to~/.hammerspoon
- Run the following
mkdir -p ~/.hammerspoon
touch ~/.hammerspoon/init.lua
echo "require \"lgtv_init\"" >> ~/.hammerspoon/init.lua
- Change the HDMI input at the top of the Lua script, if needed.
Thanks to @greyshi for extending upon my initial Wake On LAN gist and introducing LGWebOSRemote.