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.11
- LGWebOSRemote (version 2023-12-11 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 [email protected]
pip install pipx
# Then install LGWebRemote...
pipx install git+https://github.com/klattimer/LGWebOSRemote.git
pipx ensurepath
If you had previously installed LGWebOSRemote with pip (rather than pipx), you can remove the old version by running:
rm -fr ~/opt/lgtv
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 --name MyTV --ssl swInfo
lgtv --name MyTV --ssl screenOff
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.