Using the LG webOS source value to trigger events

As of 27.0 where the LG webOS entity now has a source value, I’m working on automations for when you switch the TV to sources like NetFlix, Amazon, Hulu, etc.

Basically, I’m trying to mirror to the best of my ability some automations I already had in place for Plex. So far to accomplish this I have a custom entity that’s state is the current source value of the webOS TV so that I can trigger automations based on the state change.

Will probably include some examples later, but if anyone has a better method or suggestions for improvement it’d be appreciated!

2 Likes

Do you mean that hass could potentialy detect that I have started the Netflix app on my lg tv? :grin:

That’s right! I’ve technically already gotten that bit to work. The only annoying thing is that you obviously can’t tell it to do things if you pause/stop Netflix. You could only do triggers based on switching to different sources (e.g. Hulu Plus, Amazon, cable box).

Sorry I didn’t add this before, but as promised here’s the “sensor” I added that stores the current value of the TV source for the LG webOS TV:

sensor:
  - platform: template
    sensors:
      living_room_tv_source:
        value_template: '{{ states.media_player.lg_webos_tv_remote_2.attributes["source"] }}'
        friendly_name: 'Living Room TV Source'

And here’s a sample automation that’s triggering a scene when the TV source changes to Netflix:

automation:
  - alias: "LR Playing Night Netflix"
    trigger:
      platform: state
      entity_id: sensor.living_room_tv_source
      to: 'Netflix'
    condition:
      - condition: state
        entity_id: sun.sun
        state: 'below_horizon'
      - condition: state
        entity_id: media_player.lg_webos_tv_remote_2
        state: 'playing'
    action:
      service: scene.turn_on
      entity_id: scene.livingroom_dim
9 Likes

Amazing work! :grin: I was actully thinking about how cool it would be if this was possible since I need the TV app for 4k I cant trigger HA with chromecast and I was sad about that until I found this. Can’t wait to try it out but I wont be able to test it since I am far from home for a couple of weeks…

1 Like

Hi @jobe! I finally got time to try this out. Should I not need to specify IP for the Tv anywhere?

Also can you show how the sensor should be added to the file? I keep getting errors.

Oh, Im so sad now, I realised I dont have webOS but Netcast wich seems to be able to fetch source and change source though… You think this is possible?

Can you paste your entity information so I can see the attributes?

The sources are only TV channels that I dont use, I wonder if it would be possibly to change actual source to for Example HDMI 2 or the Netflix app… That would be cool. With this the only useful thing right now could be to turn the TV off.

entity_picture: /api/media_player_proxy/media_player.lgtv?token=2989885968&cache=003f1
friendly_name: LGTV
is_volume_muted: false
media_channel: Eurosport 2
media_content_type: channel
media_title: Bundesliga Half-Time
source: Eurosport 2
source_list: S 06,S 08,TV3 NORRLAND MITT,C 05,TV4 Östersund,C 06,Kanal 5 Norrland Mitt,TV6,C 08,C 10,Sjuan,C 11,Kanal 9,S 13,TV10,Kanal 11,S 14,TV12,S 15,FOX,SVT,MTV,S 17,S 18,TNT,Comedy Central,TLC,BBC Brit,National Geographic HD,Animal Planet,Discovery Channel,BBC Earth,TV4 Fakta,Axess TV,CNN,BBC World News,Viasat Explore,History,Horse & Country TV,Travel Channel,Nickelodeon,Nick Jr,Boomerang,Cartoon Network,Disney XD,TV4 Film,TCM,TV4 Sport HD,Eurosport 2,C More Series,C More Fotboll/Hockey/Emotion,C More Live HD/Hits HD,Al Jazeera
supported_media_commands: 3385
volume_level: 0.02

So this should still work. You want the source value. In your case, you’d change

value_template: '{{ states.media_player.lg_webos_tv_remote_2.attributes["source"] }}'

to

value_template: '{{ states.media_player.<YOUR_NETCAST_ENTITY>.attributes["source"] }}'

Hi @jobe,
What’s the easiest way to get the sources the WebOS TV can switch to?
Are we able to control Live TV channels with HASS for the WebOS TV?

Hi !!!
I am trying to put a notify on LG TV with the value of Efergy ( energy monitor)
But i dont know how to put the value instant_readings on the screeen.

Help me please

sensor:

  • platform: efergy
    app_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    utc_offset: UTC_OFFSET
    monitored_variables:
    • type: instant_readings
    • type: budget

media_player:

  • platform: webostv
    host: 10.10.1.56
    name: TV
    customize:
    sources:
    - livetv
    - youtube
    - makotv

notify:

  • platform: webostv
    host: 10.10.1.56
    name: livingroom_tv

automation:

  • alias: Consumo Geral
    trigger:
    platform: numeric_state
    entity_id: sensor.energy_usage
    above: 0.450
    action:
    service: notify.livingroom_tv
    data:
    message: states(‘sensor.energy_usage’)

Haven’t done this myself, but I assume it would be

states.media_player.<YOUR_NETCAST_ENTITY>.attributes[“source_list”]

If instant_readings is an attribute of the sensor that it would be:

states.sensor.energy_usage.attributes[‘instant_readings’]

Hi jobe…

i change the file and the result is the same…please help me

automation:

  • alias: Consumo Geral
    trigger:
    platform: numeric_state
    entity_id: sensor.energy_usage
    above: 0.200
    action:
    service: notify.livingroom_tv
    data:
    message: states.sensor.energy_usage.attributes[‘instant_readings’]

Can you attach a snippet of the sensor attributes and values

I did it…

automation:

  • alias: Consumo Geral
    trigger:
    platform: numeric_state
    entity_id: sensor.energy_usage
    above: 0.200
    action:
    service: notify.livingroom_tv
    data:
    message: ‘O consumo atual da casa e {{states.sensor.energy_usage.state}} kw’

Ah, yes I wasn’t sure if you meant an attribute called instant_readings.

@jobe
Tried your little change for a Netcast TV but only ever shows something when a TV channel is selected, not an input source or application.
Maybe a change needs to be made to the Netcast component to pull more useful information from the TV. It must be there as the android remote can tell you all this extra information

Hey everyone, until a few weeks back when my tv got a software update the source currently on display was working perfectly and triggering events correctly. Now, the value is never updated but does goto NULL when the TV is turned off.

Anyone else having this issue?