Support for pre 2012 models LG Nestcast TV's needed

No luck still.

pi@Livingroom:~/.homeassistant/pylgnetcast-master$ sudo python3 setup.py install
running install
running bdist_egg
running egg_info
creating pylgnetcast.egg-info
writing dependency_links to pylgnetcast.egg-info/dependency_links.txt
writing pylgnetcast.egg-info/PKG-INFO
writing top-level names to pylgnetcast.egg-info/top_level.txt
writing manifest file 'pylgnetcast.egg-info/SOURCES.txt'
reading manifest file 'pylgnetcast.egg-info/SOURCES.txt'
writing manifest file 'pylgnetcast.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/pylgnetcast
copying pylgnetcast/__main__.py -> build/lib/pylgnetcast
copying pylgnetcast/pylgnetcast.py -> build/lib/pylgnetcast
copying pylgnetcast/__init__.py -> build/lib/pylgnetcast
creating build/bdist.linux-armv7l
creating build/bdist.linux-armv7l/egg
creating build/bdist.linux-armv7l/egg/pylgnetcast
copying build/lib/pylgnetcast/__main__.py -> build/bdist.linux-armv7l/egg/pylgnetcast
copying build/lib/pylgnetcast/pylgnetcast.py -> build/bdist.linux-armv7l/egg/pylgnetcast
copying build/lib/pylgnetcast/__init__.py -> build/bdist.linux-armv7l/egg/pylgnetcast
byte-compiling build/bdist.linux-armv7l/egg/pylgnetcast/__main__.py to __main__.cpython-34.pyc
byte-compiling build/bdist.linux-armv7l/egg/pylgnetcast/pylgnetcast.py to pylgnetcast.cpython-34.pyc
byte-compiling build/bdist.linux-armv7l/egg/pylgnetcast/__init__.py to __init__.cpython-34.pyc
creating build/bdist.linux-armv7l/egg/EGG-INFO
copying pylgnetcast.egg-info/PKG-INFO -> build/bdist.linux-armv7l/egg/EGG-INFO
copying pylgnetcast.egg-info/SOURCES.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying pylgnetcast.egg-info/dependency_links.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying pylgnetcast.egg-info/not-zip-safe -> build/bdist.linux-armv7l/egg/EGG-INFO
copying pylgnetcast.egg-info/top_level.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
creating dist
creating 'dist/pylgnetcast-0.3.1-py3.4.egg' and adding 'build/bdist.linux-armv7l/egg' to it
removing 'build/bdist.linux-armv7l/egg' (and everything under it)
Processing pylgnetcast-0.3.1-py3.4.egg
creating /usr/local/lib/python3.4/dist-packages/pylgnetcast-0.3.1-py3.4.egg
Extracting pylgnetcast-0.3.1-py3.4.egg to /usr/local/lib/python3.4/dist-packages
Removing pylgnetcast 0.3.0 from easy-install.pth file
Adding pylgnetcast 0.3.1 to easy-install.pth file

Installed /usr/local/lib/python3.4/dist-packages/pylgnetcast-0.3.1-py3.4.egg
Processing dependencies for pylgnetcast==0.3.1
Finished processing dependencies for pylgnetcast==0.3.1
pi@Livingroom:~/.homeassistant/pylgnetcast-master$ sudo python3 -m pylgnetcast --host 192.168.0.104 --protocol hdcp
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py", line 138, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/connection.py", line 98, in create_connection
    raise err
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/connection.py", line 88, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 594, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 361, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1086, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 924, in _send_output
    self.send(msg)
  File "/usr/lib/python3.4/http/client.py", line 859, in send
    self.connect()
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py", line 163, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py", line 147, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.HTTPConnection object at 0x762931d0>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 643, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/retry.py", line 363, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.0.104', port=8080): Max retries exceeded with url: /hdcp/api/dtv_wifirc (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x762931d0>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/pi/.homeassistant/pylgnetcast-master/pylgnetcast/__main__.py", line 61, in <module>
    sys.exit(main())
  File "/home/pi/.homeassistant/pylgnetcast-master/pylgnetcast/__main__.py", line 37, in main
    args.protocol) as client:
  File "/home/pi/.homeassistant/pylgnetcast-master/pylgnetcast/pylgnetcast.py", line 134, in __enter__
    self._session = self._get_session_id()
  File "/home/pi/.homeassistant/pylgnetcast-master/pylgnetcast/pylgnetcast.py", line 172, in _get_session_id
    self._display_pair_key()
  File "/home/pi/.homeassistant/pylgnetcast-master/pylgnetcast/pylgnetcast.py", line 186, in _display_pair_key
    self._send_to_tv('auth', self.KEY)
  File "/home/pi/.homeassistant/pylgnetcast-master/pylgnetcast/pylgnetcast.py", line 195, in _send_to_tv
    timeout=DEFAULT_TIMEOUT)
  File "/usr/local/lib/python3.4/dist-packages/requests/api.py", line 110, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 487, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.0.104', port=8080): Max retries exceeded with url: /hdcp/api/dtv_wifirc (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x762931d0>: Failed to establish a new connection: [Errno 111] Connection refused',))

The commands you seek are these:

Supported Models Information
LCD/LED TV LZ9800, LZ970*, LZ9700, LZ9600\nLW9600, LW950*, LW9500, LW770*, LW7700, LW7500, \nLW650*, LW6500, LW570*, LW5700, LW5600, LW550*, LW5500\nLV570*, LV5700, 
LV550W, LV550T, LV5500(except size 26&apos;&apos;, 22&apos;&apos;, and Hong Kong), LV5400\nLV375*, LV373S, LV372S, LV3700\n\nNorth America Only \nLK550, LK530\n\n\n- 
PDP TV\nKorea, Australia, New Zealand, Asia\nPZ950, PZ570\n\nCentral Asia\nPZ950\n\nNorth America\nPZ950, PZ750, PZ550, PZ540\n\nLatin America\nPZ950\nPZ570 (Brazil, 
Peru, Chile Only)\n\nEurope\nPZ950, PZ750

key_code_power_on_off = 8
key_code_num_0 = 16
key_code_num_1 = 17
key_code_num_2 = 18
key_code_num_3 = 19
key_code_num_4 = 20
key_code_num_5 = 21
key_code_num_6 = 22
key_code_num_7 = 23
key_code_num_8 = 24
key_code_num_9 = 25
key_code_mute = 9
key_code_menu = 67
key_code_dash = 76
key_code_flashback = 26
key_code_chlist = 83
key_code_enter = 68
key_code_ch_up = 0
key_code_ch_down = 1
key_code_vol_up = 2
key_code_vol_down = 3
key_code_arrow_up = 64
key_code_arrow_down = 65
key_code_arrow_left = 7
key_code_arrow_right = 6
key_code_return = 40
key_code_exit_cancel = 91
key_code_confirm = 68
key_code_cursor_ok = 2
key_code_quick_menu = 69
key_code_red_button = 114
key_code_green_button = 113
key_code_yellow_button = 99
key_code_blue_button = 97
key_code_mm_live_tv = 158
key_code_mm_stop = 177
key_code_mm_play = 176
key_code_mm_pause = 186
key_code_mm_skip_backward = 143
key_code_mm_skip_forward = 142
key_code_mm_record = 189
key_code_epg = 169
key_code_energy_saving = 149
key_code_av_mode = 48
key_code_input = 11
key_code_fav = 30
key_code_simplink = 126
key_code_ratio = 121
key_code_info = 170
key_code_netcast = 89
key_code_guide = 169
key_code_subtitle = 57
key_code_teletext = 32
key_code_t_opt = 33
key_code_ad = 145

Looks like lg_netcast is still using 0.2.0 and not the 0.3.1?

Seems to be a minor change to support the latest version and supply an additional protocol parameter?

Is that all I need to do? Or do I also need to map the commands across? I think the commands are handled in pylgnetcast.

Cheers,

Has there been any update on this? I have a 2011 LG 42LV5400 with Netcast.
I know @dennisaion created a workaround here: [WORKAROUND] LG TV Remote but I am using the latest Hass.io 0.64.3 and the netcast component doesn’t work for me. Any way to get around this? I tried the CEC component and the kodi JSON-RPC CEC, which is the closest I’ve gotten but works only to turn on the TV. Thanks so much.

Hope to add support for 42LM7600 too.

1 Like

For all others searching for LG Netcast TV (pre 2012 models) component: I rewrote the component and overrided the original one (used for 2012+ models). Everything is working except the turning the TV on (Power Off is working well), because oldest models does not support wake on lan. I also disabled the power button when the TV is off. There is HDMI CEC option to power the TV, but it is a different question with different answer. There is a functionality to switch to concrete channel. In order this to happen you should add all channels you want in to the FAV list (it doesn’t matter which - A,B,C or D). All channels you want to be able to switchto directly (without arrows, next and prev buttons of the player) should be added in one of the FAV lists.

Edit: Sorry for the external links to the files, but I have not enough time to format it with the preformatted text button (</>). If the text on the links is in Russian, like it is when I open them, press the “Скачать” labeled link (download in Russian :slight_smile: ).

Steps to do it yourself:

  1. In your config folder create a new folder called custom_components

  2. In the custom_components folder create a new folder called media_player

  3. In the media_player folder create a new file called lg_netcast.py

  4. Add the following code in to the file lg_netcast.py
    lg_netcast.py (customised)

  5. In your config folder create a new folder called www and inside of it upload a picture called livetv.jpg - this image will be displayed when the TV is ON
    livetv.jpg (from webos)

  6. In your configuration.yaml add your TV as this:

     media_player:
     - platform: lg_netcast
       host: 192.168.1.101
       access_token: DLHSLF
       name: Kitchen TV
    

Change the host with the IP of your TV (you can see it from the ‘network’ menu or the in your router). Leaving blank access_token should show your access token on the TV then fill it on the place of mine. Write the name of your TV and save the configuration.yaml
Finally restart home assistant.

Maybe this is the place to thank to @dennisaion for helping me to understand some python script things and for the list of the wi-fi remote codes … :slight_smile:

1 Like

No probleem :grin:

UPDATED!!! 13.12.2018

lg_netcast.py (customised) 13.12.2018

The links in previous post are updated too.

I implemented an optional ‘turn_on_action’ in case you can find a way to wake up your TV somehow. I found an option for me - I bought a cheap hdmi miracast device and Sonoff SV Switch (with tasmota uploaded), then I made the following connection:
Phone Charger (With USB output) -> Sonoff SV -> HDMI Miracast -> TV HDMI
I added the Sonnof SV Switch to HA config and named it ‘Netcast TV Switch’, this way its entity id is: switch.netcast_tv_switch
After that I added turn_on_action part to the end. With the latest edition if you add it, the power on button of the media player will be available and will call the service you’ve populated (Idea: it could be even a service call to IR Blaster to turn the TV on). One notice - if you make it like me, with HDMI CEC device (the miracast for example), you will have to write an automation to turn the device off after 8 or 9 seconds in order to avoid further switching to the HDMI input of the waking up HDMI device itself. This way after the TV is powered on it will switch to the latest source used.

media_player:
  - platform: lg_netcast
    host: 192.168.1.101
    access_token: DLHSLF
    name: Kitchen TV
    turn_on_action:
      service: homeassistant.turn_on
      data:
        entity_id: switch.netcast_tv_switch

The script and automation from my use case (with the Sonoff SV and HDMI Miracast device) to auto turn off the switch after 8 seconds:

scripts.yaml entry:

kitchen_tv_turn_off_timer:
    alias: "Kitchen TV turn off timer"
    sequence:
        - delay: '00:00:08'
        - service: homeassistant.turn_off
          data:
              entity_id: switch.netcast_tv_switch

automations.yaml entry:

- alias: "Kitchen TV switch auto turn off"
  trigger:
      - platform: state
        entity_id: switch.netcast_tv_switch
        to: 'on'
  action:
      - service: script.turn_on
        entity_id: script.kitchen_tv_turn_off_timer

Link to the exact brand and model of the Miracast HDMI device, that I have and I know it is working for the purpose of auto waking up the TV via HDMI-CEC

Link to the Sonoff SV device. That was the best price I’ve found before 3 months. Now there might be even cheaper offer…

IMPORTANT: If you want to make the same power on scheme (with the HDMI Miracast and Sonoff SV) you will need SOLDERING SKILLS AND SOLDERING IRON. Also you’ll need one USB to MicroUSB cable, that you’ll have to cut in to pieces in order to solder it to the input and the output of the Sonoff SV board (the red wire is +5V, the black wire is Ground, White/Yellow is Data + and not needed, the green one is Data - and not needed too. See the image below.) . The cable part with the USB end has to be solder to the Sonoff SV input and the part with the MircoUSB has to be soldered to the Sonoff SV output. If you choose different HDMI device, please check what USB cable you will need.

USB-cable-wiring1

I’ve spent quite a bit of time on this as using standard HA I can turn off the TV but not turn om but just adding the lg_netcast.py stops any control in HA. The HA panel shows but I can’t even turn off theTV, when I remove the script and restart HA and I get the standard HA control back.

TV is 42LM620-TZE
Software version is 04.62.12

I don’t know if it works in standard HA. I’m using hass.io. The file that I uploaded is structured the same as the original, with small change on the API requests to be usable with older netcast TVs. I’m not sure if I understand what you mean with " adding the lg_netcast.py stops any control in HA." What control is stopped when you add it? Can you post the configuration from config.yaml?

Everything seems to work just fine even on the latest hass.io v0.86.3

yes using hassio

To be honest its must easier for on/off on this tv just to use a smart plug.

Not true! I have HDD added for time machine. If I turn it off with smart plug it will ham my hard disk. I can’t help you if you don’t show me your config. LG smart TVs are the smartest from all of the smart TVs. They offer great functionality and if something isn’t available (like Wake On Lan) it is easier to be achieved with periferial devices. This is why I modified the the lg_netcast.py. My old TV is quite enough for my needs and I didn’t wanted to buy a new TV just for integrating it in HA. So it works perfect now. :slight_smile:

Hey!
So I’ve been using your custom component for about a week or two and it had been working amazingly well.
I had been trying to figure out a way to achieve this for such a long time and it looked like dennisaion got close for my LG TV version, but yours was the only one that actually worked so thanks!

Unfortunately, 0.88.0 broke your custom component for me.
The LG media_player always shows as off now.
I use the turn_on_action:

  - platform: lg_netcast
    host: 192.168.85.27
    access_token: ABCDEF
    name: LG TV
    turn_on_action:
      service: homeassistant.turn_on
      data:
        entity_id: switch.tv_power

switch.tv_power is a Broadlink RM Pro IR code to send the power button to the TV.

Here’s the output from my HA logs:

Error loading custom_components.media_player.lg_netcast. Make sure all dependencies are installed

Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/homeassistant/loader.py", line 147, in _load_file module = importlib.import_module(path) File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "&lt;frozen importlib._bootstrap&gt;", line 1006, in _gcd_import File "&lt;frozen importlib._bootstrap&gt;", line 983, in _find_and_load File "&lt;frozen importlib._bootstrap&gt;", line 967, in _find_and_load_unlocked File "&lt;frozen importlib._bootstrap&gt;", line 677, in _load_unlocked File "&lt;frozen importlib._bootstrap_external&gt;", line 728, in exec_module File "&lt;frozen importlib._bootstrap&gt;", line 219, in _call_with_frames_removed File "/config/custom_components/media_player/lg_netcast.py", line 279, in &lt;module&gt; from homeassistant.components.media_player import ( ImportError: cannot import name 'SUPPORT_TURN_OFF' from 'homeassistant.components.media_player' (/usr/local/lib/python3.7/site-packages/homeassistant/components/media_player/__init__.py)

I assume that there are 2 things that need to be changed but wanted to ask just in case.
1 is referenced here (I think):


And 2, it looks like turn_on~action has been deprecated.

From my logs:

Your configuration contains extra keys that the platform does not support.
Please remove [turn_on_action].  (See /config/configuration.yaml, line 117).

Thanks again for this awesome work!

I FIGURED IT OUT!
A little google search sent me here:

It’s a 2 step fix to get this working as it did before:

Step 1: Change the following lines on lg_netcast.py:
Starting at line 279.
Old code:

from homeassistant.components.media_player import (
    SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK, PLATFORM_SCHEMA,
    SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_STEP,
    SUPPORT_SELECT_SOURCE, SUPPORT_PLAY, MEDIA_TYPE_CHANNEL, MediaPlayerDevice)

New code:

from homeassistant.components.media_player import (
    MediaPlayerDevice, MEDIA_PLAYER_SCHEMA, PLATFORM_SCHEMA)
from homeassistant.components.media_player.const import (
    SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK,
    SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_STEP,
    SUPPORT_SELECT_SOURCE, SUPPORT_PLAY, MEDIA_TYPE_CHANNEL)

Step 2: Rename lg_netcast.py to media_player.py and move it from /custom_components/media_player/ to /custom_components/lg_netcast/.

Thanks again!

By the way, I have a 2011 42LV5400-UB that I’m using this with and I notice that the only things that work are: Power On/Off, Mute, & Volume Up/Down.
Although I don’t know much about python, looking into the lg_netcast.py file, it looks like there may be the ability to mimic other button presses (line 29 class LG_COMMAND(object):) and also the ability to choose input source? Right now, I can’t do any of those things. Is this normal behaviour?
I honestly won’t need to utilize many of the other functions as I have an HDMI splitter and use a cable box & Nvidia Shield TV, but I was just curious.

@RevelRob Thank You for self supporting yourself about this issue! :smiley: :wink:
Yesterday I found there is a new version of HA and that there are such breaking changes, so I din’t had enough time to do anything about it. Also I have 3 more custom components that I’ve shared across. I will have to find some time to rewrite them and change the instructions, but I lack free time. Also I still haven’t migrated to the newest version of HA (still using 86.3), because it works … :smiley: :smiley: :smiley: Actually, as I don’t need anything else I might stay on this version for a long time. I’m just tired fixing things. When I say things I mean “s**ts”. Some of the newest breaking changes are … Whatever … Before 2 years I wrote my own software for home automation, but I decided to leave it aside, while I experiment with HA. I’m just planning to migrate back to my software if things don’t get better. :\
Anyway … I’m not sure if there can be well implemented input source switching. There is a good documentation about all capabilities of each protocol LG is using, but I don’t have enough time to read it again. I don’t know a lot about python, but it looks like other programming languages, and it wasn’t hard to rewrite the original plugin to support older Netcast versions - at least for some basic features.

1 Like

hello, I can’t find your lg_netcast.py customized.
Was it removed ?

Works on 0.94.1

2 Likes

As I customize it for my needs, the turn_on_action should be a script that somehow turns your TV on (it is not required). In my case I wrote a script that sends IR commands in the room that it is configured via MQTT. The IR sender device is just a regular NodeMCU v3 with Tasmota, with IR diode attached to it. The scripr sends command to the topic of this node MCU passing the code and bits to be sent via tasmota’s irsend command.
configuration.yaml:

  - platform: lg_netcast
    host: 192.168.100.200
    access_token: GPZARU
    name: Kitchen TV
    turn_on_action:
      service: script.ir_code
      data:
        bits: 32
        data: 20DF23DC
        protocol: NEC
        room: kitchen

scripts.yaml:

ir_code:
  sequence:
  - data_template:
      payload: '{"Protocol":"{{ protocol }}","Bits": {{ bits }},"Data": 0x{{ data }}}'
      topic: 'cmnd/{{ room }}Multisensor/irsend'
    service: mqtt.publish
ir_raw:
  sequence:
  - data_template:
      payload: '0, {{ data }}'
      topic: 'cmnd/{{ room }}Multisensor/irsend'
    service: mqtt.publish

ir_code sends hex codes to the room
ir_raw sends raw codes

Amazing! Was also looking for this. Thank you!

Hello sir!

Sorry to bother you but I was not able to use your custom component.

I’m on version 97.2 and get this error:

2019-08-17 09:47:49 ERROR (MainThread) [homeassistant.components.hassio] Platform not found: media_player.lg_netcast

I am using this version for now: https://1drv.ms/u/s!Ar2LwsQ7-lg6iZhaOY98p_18hrGC1w?e=FWagbN

With this one, the component loads but there is major downside: it does not have the turn on action function, that is why I would like to use yours.

Do thing there is a way to update yours to suite the latest HA version?

Thanks!