Support for pre 2012 models LG Nestcast TV's needed

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 "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/config/custom_components/media_player/lg_netcast.py", line 279, in <module> 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!

Where did you put the lg_netcast folder?
It should be placed inside custom_components folder …
If it is there and the platform is not found, then you should restart hassio.
If you have restarted hassio, then you should search in the log for some error that occurs during initialization process.

I also don’t update HA until I need something that is presented in the newer version. I’m tired of this breaking changes an rewriting all my code again, and again … And reading (or searcing) about all the things I should change. :slight_smile: If someone from Home Assitant dev team want to include my code in home assistant and support it - I ave no problem wit that. This was the only reason I removed all my custom components I’ve made - I don’t have so much time to be on the edge on the software changes made in HA and rewrite my code so everyone be happy immediately after a new version is out. :slight_smile: I had that feeling that I’m a slave of HA instead of the opposite. :slight_smile: And as a developer I know one thing for sure - If it works, don’t update it! :smiley: That rule kinda gave me soooo much time for beer with friend, relaxing, personal life, etc. … :slight_smile:

Hello!

Yes, I’ve placed on the custom_components folder. I already have a version of this netcast component (attached above) and it works, the only problem is I don’t have the turn on action.

Media player component in general really needs an overhaul, these old TVs also needs some love :slight_smile:

I really like the latest and greatest. I’ve learn that with HA if you don’t update often, there will be so many breaking changes to track back that it might take a lot longer to get it back running again. Off course, only if you need to update it, but there are so many cool new features and patches that helps on running HA better and better over time.

Thanks!

If my custom component works for you, then were is this error coming from? For the turn on action - I’ve explained how I did it, but you can use any king of valid scripts that may start the TV. Actually the early described method will work too. You will just have to make a script that will call a service “turn on” to the sonoff and pass the script to the turn_on_action. If you need more info how to make IR remote device like mine, and works with the scripts from above, I can help you too. :slight_smile:

Sorry, I think I was not able to express myself correctly.

I already use a custom netcast component, it is a different one that you’ve created and it works on the latest version of HA (https://1drv.ms/u/s!Ar2LwsQ7-lg6iZhaOY98p_18hrGC1w?e=FWagbN) but it lacks of a turn on action, like yours.

That is why I’ve tested your code but I get an error when trying to check config or restart HA.

Thanks.

Ahaaaam … this is one of the catches in hassio … First you have to put the plugin in the custom_components, then restart, and then add the media_player entry for lg_netcast. If you add the files, add the yaml entry and then try to restart ,you’ll get this error, because hassio needs restart, to know that there is such platform. :slight_smile:

Try it this way, and the will see what will be the end result. :slight_smile:

Thanks for your suggestion! I’ve actually tough of that and tried with no luck. Removed the media player entity, replace the custom component folder, restarted, configured, restarted and the component os not loaded.