No module Published on Offcanvas position

LG TV and Domoticz

I have this simple use case many other people probally have too. I wanted to change/dim the lights in the living room based on the fact if the tv is on and what i'm watching. 
I found out that people had made libraries to control and get the status of your LG TV using python. This of course makes it super easy to integrate this with your domoticz system.

I'm aware there is a plugin for Domoticz, but I don't need over half the features it has.

I figure this method works on most or all LG TV's dating 2015 and up. I have a 2017 model myself the 55UJ630V-ZA

To begin, you need Python3 and the library installed on your system. 

Python can be installed using sudo apt get install python3.8 if you don't already have it. 
To install the library use pip install pylgtv
I didn't write the library, you can find more about it here.

I highly recommend you to configure your TV with a static IP or configure a DHCP reservation. 
Otherwise it's kind of hard for the script to find your TV if your address keeps changing.

It's very easy to use, a small example from the github page. 

from pylgtv import WebOSClient

try:
     webos_client = WebOSClient('192.168.0.112')
     print(webos_client.get_current_app)
except:
     print("Error connection to TV")

This simply gets the current running app on your LG TV. On modern LG tv's everything is considered a app from your HDMI outputs to Netflix.
From what i've gathered, these are the command you can use:

  • send_message(arg)
  • send_delete_key()
  • send_enter_key()
  • play()
  • pause()
  • stop()
  • close()
  • rewind()
  • fast_forward()
  • get_channel_info()
  • set_channel(arg)
  • get_current_channel
  • get_channels()
  • channel_down()
  • channel_up()
  • get_input()
  • set_input(arg)
  • set_mute(False/true)
  • get_muted()
  • set_volume(int)
  • close_app(arg)
  • launch_app(arg)
  • get_inputs()
  • get_volume()
  • get_services()
  • get_current_app()
  • get_apps()
  • power_off()
  • check()
  • volume_down()
  • volume_up()

Yes, it's very possible to configure your domoticz in a way to control your TV. I havn't tested all functions myself, but I believe they should work fine. 
I only needed to get the current status of my TV so if you interessted you can check out the script here and modify it to your own needs.