Last active
April 27, 2020 05:37
-
-
Save henrik/2824551d69e8e7f35ae61bd35ca08456 to your computer and use it in GitHub Desktop.
Ruby script to turn on a LGTV running WebOS 3, using "wake on LAN".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# Based on: https://gist.github.com/dgv/2865897 and https://gist.github.com/zunda/187139 | |
# Idea from: https://github.com/efpe/amazon-alexa-lg-tv | |
# In order for this to work, first go to the TV "General" settings and turn on "Mobile TV On". | |
# Change this to the actual value. | |
# First find the TV IP, e.g. from your router's list of connected devices. | |
# Then run "arp -a" on a computer and you'll see the MAC by its IP. | |
# Maybe you need to "ssh <the ip>" before it will turn up in arp. Not sure. | |
TV_MAC_ADDRESS = "xx:xx:xx:xx:xx:xx" | |
require "socket" | |
def send_wake_on_lan_packet_to_mac_address(mac_address) | |
addr = ['<broadcast>', 9] | |
socket = UDPSocket.new | |
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true) | |
data = "\xFF".force_encoding(Encoding::ASCII_8BIT)*6 + [ mac_address.gsub( /:/, '' ) ].pack( 'H12' )*16 | |
puts("Wake-On-Lan packet sent to MAC address "+ mac_address) | |
socket.send(data, 0, addr[0], addr[1]) | |
end | |
send_wake_on_lan_packet_to_mac_address(TV_MAC_ADDRESS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello good afternoon!
How do I turn the TV off and send "click", "right", "left", ie remote control commands?