Absolute Beginner

Absolute beginner, as ever diving in at the deep end! I am trying to make a remote control for my LGTV. The TV runs webOS version 7.5.7-24.
I have got the buttons etc to work surprisingly well and easily then i turned my attention to PowerOn and PowerOff. I installed Wake On Lan and matched it to the TV MAC address. Having checked the tv quick start settings are disabled, the button works both on (wake Up) and off BUT only when the tv is set to its Netflix source. Any other source, and there is no highlighted button on the remote, and nothing works, the second i switch to Netflix, the illuminated button comes on and hey presto it works, shuts the TV down, and press once more and it starts up.
The code i am using is:

type: picture-elements
elements:
  - type: conditional
    title: PowerOn
    conditions:
      - condition: state
        entity: media_player.lg_webos_tv_uq80006lb
        state: "off"
    elements:
      - type: image
        style:
          left: 35%
          top: 94.5%
          width: 14%
        entity: media_player.lg_webos_tv_uq80006lb
        title: PowerOn
        tap_action:
          action: perform-action
          perform_action: wake_on_lan.send_magic_packet
          target: {}
          data:
            broadcast_port: 9
            mac: AC:5A:F0:F7:7A:A7
        image: local/TVRemote/power.png
  - type: conditional
    title: PowerOff
    conditions:
      - condition: state
        entity: media_player.lg_webos_tv_uq80006lb
        state: "on"
    elements:
      - type: image
        style:
          left: 35%
          top: 94.5%
          width: 14%
        entity: media_player.lg_webos_tv_uq80006lb
        title: PowerOff
        tap_action:
          action: toggle
        image: local/TVRemote/powerON.png
        state_image:
          "on": local/TVRemote/powerON.png
image: local/TVRemote/Base.png

If anyone has any pointers i would be most grateful… remember i am a newbie… be gentle!

Please post your code formated as code according to forum rules.

Hint: use the Preformatted Text </> option.

Corrected, sorry

check the media player state in developer tools when on the other inputs, if its ‘idle’ or anyting else, thake that into account too.

I don’t know the hardware, but it could have several discrete states even beyond “unknown” or “unavailable.” For example, my Apple TV box has “idle” and “playing”. It’s conceivable that in some modes your LG reports those or other states.

One reliable way to probe it is to use the Template tool in the Development menu and see what the following output yields in different use cases:

{{ states("media_player.lg_webos_tv_uq80006lb") }}

You should also check the documentation for the Media Player integration to understand what the set of possible states is.

Hope this helps.

yes, thanks, that seems to work! Mostly the other channels were set to “idle”, so when set to “on”, they started to work, the one exception was my smartTV source, which shows as “playing”, i set it to “on” but each time it is refreshed, it returns to “playing”
Many thanks for the help… if you have any ideas about this “playing” item,would be appreciated.

Not sure if this what you are looking for, but for my recently acquired LG TV, I used the wake–on-lan platform to create a switch which reliably reports the power state of the TV (with a slight delay for ‘on’ admittedly, but acceptable enough in use).

      - platform: wake_on_lan
        mac: "blah blah"
        name: "LG webOS TV UA73"
        host: "192.168.0.211"
        turn_off:
          action: media_player.turn_off
          target:
            entity_id: media_player.lg_webos_tv_ua73