Turn on a LG television (WebOs) using Wake on Lan in Home Assistant

Hi All,

I am a proud owner of a new LG television, which I choose primarily for WebOs. Integrating it in Home Assistant seemed easy, all was working almost instantly, until I turned it off and was trying to turn it on again.

First stop are the Docs, nobody wants to be that RTFM guy. The Docs clearly describe that the way to go is using Wake_On_Lan. This is also what I have set up. From the description in the docs, all seemed fine. Next stop, Google, StackExchange, etc. and it was not easy to troubleshoot the problem. However, after three hours I found the problem:
I am running Home Assistant inside a Docker container and I am using Traefik as a reversed proxy, including a virtualized network in Docker.
This last thing is the problem. Wake On Lan (WOL) uses so called magic packages and these cannot be send directly from a virtualized docker Network to devices outside of that network. To solve this, you can:

  1. set Home Assistant to use the host network. This does however give problems with my reversed proxy (Traefik).
  2. Use some other computer to do the WOL call.

To help others, hopefully saving some time, I will describe here my solution which helped me turn on the LG television.

Add Wake On Lan RESTful service to the Docker compose:

  wol:
    container_name: wake-on-lan
    image: anjia0532/wakeonlan:latest
    restart: unless-stopped
    network_mode: host
    labels:
      - "traefik.enable=false"

This adds a server that is running on your Docker host, sharing the host network and serving a RESTful api to do WOL. This can now work:

curl -XPOST -d '{"macAddress":"AB:CD:EF:12:34:56"}' http://<your_server_ip>:8080/api/v1/wake

Now we can setup Home Assistant to use the restful call. I have added three entries into my secrets.yaml:

# wol tv control
wol_api: "http://xxx.xxx.xxx.xxx:8080/api/v1/wake"
wol_payload_tv: '{"macAddress":"xx:xx:xx:xx:xx:xx"}'
webostv_ip: xxx.xxx.xxx.xxx

And finally added the webostv to configuration.yaml:

rest_command:
  turn_tv_on:
    url: !secret wol_api
    method: POST
    payload: !secret wol_payload_tv

webostv:
  host: !secret webostv_ip
  name: LG Television
  turn_on_action:
    service: rest_command.turn_tv_on
  customize:
    sources:
      - HDMI 2
      - Netflix
      - Prime Video

Make sure that your TV has the Wake On Lan feature turned on. They are in:
Connection -> Mobile Connection Management -> TV On with Mobile

I hope that others, having the same troubles with their LG TV find this post useful and save them some time. I could add these to the manual, what do you guys think?

Cheers,
Dennis

I have a setup pretty similar to yours, Docker and it’s internal networking etc, thought I don’t have the reverse proxy set up.
I just had to specify the broadcast address of the network my TV was on and add wake_on_lan to my configuration.yaml to get WOL working back when I set mine up, I don’t know if that would work in your case?
Your solution looks like it would be usable by things other than home-assistant as well though, which might be handy :slight_smile:

I finally found out what the problem was, namely how I configured the networks in Docker. For WOL to work out of the box, so without any of the additional stuff, home assistant and the webos tv should be on the same network. The webos tv is of course directly connected to my home network, i.e. no virtualization between the network, but for Home Assistant it was in the virtual network t2_proxy. For WOL to work out of the box, Home Assistant should be on the host network. This makes a lot of stuff easier, except for the Traefik, the reversed proxy, I needed to configure separate. So in the end, my previous solution worked, as it had a separate container in the host-network with a rest-api, but configuring it slightly different in docker+traefik dropped the need of it.

I recently, shared my full config on my Github:

@FreelancerJ: Out of curiousity, why don’t you have a Reversed proxy? I found it tough to set up in the first place as it was relative new to me. But after spending a bit of time, having the automated SSL renewable and super-easy sub-domain assignment amazing. Really loving it now.

Oh man, looking through your config makes me ashamed of my config. You’ve got it all so neat and well structured!

My webOS tv is actually connected to a wifi network broadcast from my Home-Assistant host so that it and a few other IOT devices that I don’t expect will ever receive updates, let alone security updates, aren’t able to connect to the internet and become parts of botnets etc.

I never bothered with a reverse proxy as my current install is more for learning how it all works and deciding if Home Assistant was everything I needed. And seeing how it’s stability with updates was over a prolonged period.
When I set it up, I was moving from having an Air Conditioner, some lights and a couple Z-Wave sensors running through HomeBridge, and I was looking for something that could log history so I could add energy usage and a more thorough temperature sensing to my home.

It’s also not exposed to the internet, its just on my home network. I only have 3 things I want to be able to use/see remotely (temperature, the aircon, and the lamp I never remember to turn off before I leave home) and I have them bridged to home kit and can access them that way.

I do have a subdomain set up for it though, just using regular old DNS assignment on my router, and I have dehydrated running on the host for my SSL certificates so that I could use DNS challenges with LetsEncrypt without opening network ports at home (my modem doesn’t leave me a programatic way to do so, and my ISP actively blocks 80 and 8080 inbound traffic).

Over the next month though, I’m doing a “start from scratch with the lessons learnt” and moving it all into a new host, and making it more integrated to the whole home, so I’ll probably work more on having a reverse proxy set up (so I’ll probably be following in your learning journey steps :sweat_smile: )
It’s gonna be fun (but also ridiculous), includes wiring a ethernet network throughout the home for a bunch of sensors (which are POE) and smart switches (cause who wants to give up using the wall switch just to have remote control of your lights?).

Maybe once it’s all done, I’ll have a nice and tidy configuration like yours and I won’t be so ashamed of it anymore :rofl:

Of course the tidying of all the config files happened just before it got uploaded to Github ;-). Having a bit of a mess is all part of the learning journey. But starting from scratch, i.e. starting clean would probably help as well :slight_smile:

for people with letsencrypt or now SWAG. the only thing you have to do is this:

I am still struggling with this, and hoping one of you bright folks will help me out!

I followed all the documentation and the multiple topics on the issue, but once again it doesn’t work. Here is my code (in the automations.yaml file). I am running on Raspberry Pi, Docker container:

- id: '*************'
  alias: Turn On Living Room TV with WakeOnLan
  description: ''
  trigger:
  - platform: webostv.turn_on
    entity_id: media_player.lg_webos_smart_tv
  action:
  - service: wake_on_lan.send_magic_packet
    data:
      mac: "AA:BB:CC:DD:EE:FF"
      broadcast_address: "192.168.4.255"

I can see the button to turn on the TV from the Off state, but it won’t actually turn it on. What am I doing wrong?

  • container is set up to work on the same network as the host

  • The TV is running LG WebOS 4.1.5

  • Connected on ethernet, confirmed broadcast address

  • LG Connect Apps enabled in Network Menu

  • Option for “Mobile On” does not exist in General Settings on the TV