How to LG TV power off via KODI power off

Scope:

  • This script will turn off LG TV (> 2011) when you turn off the TV box (via KODI power menu, remote controller or button on the box).
  • LG smart TVs are very known for their very bad implementation of HDMI CEC protocol, at least old TV models <2015 (does not support power off via CEC command)

Requirements:

  • LG TV >2011
  • TV connected to the same network as TV BOX
  • Mecool KIII PRO (S912), CoreELEC 8.90
  • Putty or similar SSH software

Integration process: scripts.zip (1.4 KB)

  1. Copy service file shutdown_with_net.service to folder /storage/.config/system.d/
  2. Put your shutdown script shutdown_with_net.sh to folder /storage/.config/
  3. Put your python script lg_tv_control_lan.py to folder /storage/.config/
  4. Edit python script lg_tv_control_lan.py and set TV ip address and paring key
  5. Pairing key could be found also by running script sh shutdown_with_net.sh with TV IP address and pairing random key, once executed in the shell, TV displays pairing your key
  6. Set permissions for the service and scripts chmod 755 shutdown_with_net.sh and chmod 755 lg_tv_control_lan.py and chmod 755 shutdown_with_net.service
  7. Start the service, systemctl enable shutdown_with_net.service
  8. Restart the box

Reference readings which lead to functional script:

3 Likes

Does this mean I can press the power off button on the remote control, while in kodi, and it will also power off my LG TV? If so, will it also power on my LG TV when I press the power key on my remote control to power on my CE box?

Did you read the first line in the How To?

Yes and I saw that line clearly says it will turn OFF the LG TV. However, where will I find the information if it will turn ON the TV.

It will not (or it would say power on and off )
Once the box is off, how can this shutdown script (hint) do anything else? :thinking:

@Habibie, as Poida said, script is just for powering OFF LG TV. It has no influence to power on sequence.

For power ON LG TV via TV BOX, this does not work now for me in CoreELEC but it does work with Android stock 7.1.1 firmware KIII PRO. So I am expecting either wrong config of CEC driver for LibreELEC / CoreELEC or wrong system setup on my side (I was not able to power on the TV even by using cec client commands). I am planning to make a test to go back to Android image again and re-run clean CoreELEC and LibreELEC from SD card in order to verify if it works or not.

I did mention the issue in the forum but no feedback so far. https://discourse.coreelec.org/t/lg-tv-power-on-issue-via-hdmi-cec/1034

OK and that is understood.

@anon88919003 please, don’t you want to integrate this into the CE Kodi settings? :slight_smile:

Integrate what? A script that was designed for a subset of LG TVs?
With that said, our CEC support has been improved a lot since this post was originally made, and CEC is pretty much spot-on on SBCs with our custom u-boot.

There is a lot of these TVs, I have the 2nd LG with not working TV Off. My parents have one too. LG 3D TVs are simply the best. I’m pretty sure it would be easily possible. But I understand it’s your decision like codec improvements for LG TVs you have done. Just tried to help more people, I’ve already implemented that :slight_smile:

Ive got this on my 2nd TV and dont know what to do, so please:

CoreELEC:~/.config # sh shutdown_with_net.sh
Traceback (most recent call last):
  File "/storage/.config/lg_tv_control_lan.py", line 42, in <module>
    theSessionid = getSessionid()
  File "/storage/.config/lg_tv_control_lan.py", line 25, in getSessionid
    conn.request("POST", "/roap/api/auth", pairCmd, headers=headers)
  File "/usr/lib/python3.7/client.py", line 1229, in request
  File "/usr/lib/python3.7/client.py", line 1275, in _send_request
  File "/usr/lib/python3.7/client.py", line 1224, in endheaders
  File "/usr/lib/python3.7/client.py", line 1016, in _send_output
  File "/usr/lib/python3.7/client.py", line 956, in send
  File "/usr/lib/python3.7/client.py", line 928, in connect
  File "/usr/lib/python3.7/socket.py", line 727, in create_connection
  File "/usr/lib/python3.7/socket.py", line 716, in create_connection
ConnectionRefusedError: [Errno 111] Connection refused

Simplink is ON, LAN connected but still not showing the pairing code on my LG.

Hi msider, have you followed integration process i.e. set your IP ? Are you able to ping your TV ? What pythion version you have ? Script requires python3…

yes, Ive already made it working with another TV. I just use CE (MeCool K3 pro), dont know if python3 is ok but it works with another LG.

My TV is 70LB650V, the other working TV is 60LA620S.