JPersson77 / LGTVCompanion

Power On and Off WebOS LG TVs together with your PC
MIT License
965 stars 40 forks source link

Documentation of how to wake TV on different subnet #34

Open rkellogg9 opened 2 years ago

rkellogg9 commented 2 years ago

In your guide you mentioned its possible to wake the TV even if its on a different subnet. Mind sharing how??

JPersson77 commented 2 years ago

Hi, it's not trivial because it requires having network equipment (router or level 3 switch) which can "relay" packet from one separate subnet to another separate subnet. There is tons of information on the internet, but if you try to describe how your network is set up and what hardware you are using, maybe I can help.

dechamps commented 2 years ago

If you configure LGTVCompanion to use Unicast ("Device IP address" mode), then in theory WoL might work out of the box even if the TV is on a different subnet, as long as the TV is reachable of course (i.e. proper routes are in place).

I say "in theory" because that assumes the TV will respond to ARP requests while off. In my experience with a G1 over WiFi, that is not always the case. YMMV. If the TV doesn't respond to ARP requests then things get more complicated as you will either have to set up a static ARP entry on the last router, or you will need to set up broadcast relaying on every hop (a feature most routers don't even support).

rkellogg9 commented 2 years ago

I have my C1 connected via ethernet and have a unifi network (unifi dream machine pro and 48 port switch). Currently the LG is on my main lan but i wanted to put it on my IOT VLAN. I have a bunch of firewall rules in place that allow devices like my PC to reach the VLAN. Ill give the static IP address setting a try

joebeem commented 2 years ago

I am actually attempting to setup something similar except I have a unifi dream machine standard version. I have vlans set up, but I have not enabled firewall rules to isolate yet (an entire separate issue). However, I am able to wake the tv on a different subnet without any further tweaking - I just specify the ip and mac address and it worked. I have a feeling when i setup the firewall to isolate, I won't be as lucky.

dechamps commented 2 years ago

WoL should work with a firewall as long as it is configured to let LGTVCompanion send packets to the TV on UDP destination port 9. (And for the rest of the control commands it needs Websocket access which happens on TCP port 3000.)

Amoeba00 commented 1 year ago

Been trying to do this for a while now and just now got it to work. LGTV Companion app needs to have the network options set to "Broadcast address according to device IP-address and subnet mask" (the 3rd option).

On the router/firewall - Set both External and Internal Port to 9 pointing to the LAN IP of the TV, and make sure both TCP AND UDP are enabled on that rule. For me, it wouldn't work with either - only when I set it to "Both" would the packet get to the TV and turn it on.

(Also worth mentioning, that while port 3000 is used to send the command to turn it off, if you have other commands being sent then you would also need 3001 to be forwarded as well.)

JPersson77 commented 1 year ago

Thanks @Amoeba00 for the feedback and the tips that might help more users trying to achieve the same. Port 3001 is for SSL communication, i e the default for LGTV Companion v2.0 and later versions

Amoeba00 commented 1 year ago

Of course, I did run into an issue - where if the TV has been off for a while, but computer not asleep and running - then it won't wake up the screen. Works just fine when on same LAN, but not through the firewall. If I can figure out what's going on, I'll update here - unless someone has suggestions. Thanks!

yourfriendaaron commented 6 months ago

I have an LG C9 and been struggling to port forward / make firewall rules on Unifi (Cloud Gateway Ultra) for a couple hours now. I forwarded ports 9, 3000, and 3001 from my PC where the Companion is running through to the TV's IP on another VLAN. Not sure what I'm doing wrong.

JPersson77 commented 6 months ago

Hi, I can confirm that 3000 and 3001 are the ports used for most communication with the TV. If you have that set up correctly you should be able to for example turn the TV off from the test function.

To be be able to also turn the TV on with the app you need to ensure that wake-on-lan magic packets (according to the method configured in the app) can reach the TV.

I am no expert on how to set that up though in Unifi so I hope someone else can help you further.

Amoeba00 commented 6 months ago

Yeah - it's definitely the WOL magic packet that's the issue. Knowing how to port forward those packets is key to having full control on a different subnet. Unfortunately, I haven't been able to get that to work. Of course, if could just be the router I am using that's not able to process those packets properly.

So while you can get the TV to turn off - turning it back on won't work unless you are on the same subnet so the TV can get that packet to wake back up and then receive the controls on 3000-3001 (LG C1 uses 3001). If I ever figure that part out - I'll certainly share.