LG webOS change picture setting mode with scripts

Sorry if this is a very basic question, as relatively new to HA. Where does the script go, and how can it be triggered - for example in an automation? (I’ve tried adding to scripts.yaml but can’t find a way to trigger it). Thanks.

Edit: Ah I think all this code can be put into the automation itself when formatted correctly.

You can define scipts in scripts.yaml (thank you have to reaload script or restar HA).
Than you will be able to call the script as a service eg:

- service: script.living_room_lg_tv_picture_energy_saving
  data:
     energy_saving: 'max'

Or include whole script in automation but you won’t be able to reuse it.

2 Likes

I have root telnet enabled. I can connect via Putty, and send commands such as below which successfully changes picture mode.

luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{"category": "picture", "settings": {"pictureMode": "expert2"}}' & exit

However I’m unable to get the command_line switches code here to work. The switch simply resets to off. The logs show no error.


Edit:

Finally managed to get it working with below…

switch:
  - platform: command_line
    switches:
      lgtv_picture_bright_cl:
        unique_id: "lgtv_pict_bright_cl"
        command_on: >
            echo "luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{\"category\": \"picture\", \"settings\": {\"pictureMode\": \"expert1\"}}' & exit" | curl --raw --max-time 1 telnet://192.168.1.4:23
        command_off: >
            echo "luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{\"category\": \"picture\", \"settings\": {\"pictureMode\": \"expert2\"}}' & exit" | curl --raw --max-time 1 telnet://192.168.1.4:23
        command_state: > 
            echo "luna-send -n 1 luna://com.webos.settingsservice/getSystemSettings '{\"category\": \"picture\", \"keys\": [\"pictureMode\"]}' & exit" | curl --raw --max-time 1 telnet://192.168.1.4:23 | grep -c expert1
        friendly_name: "LG Picture Bright"
4 Likes

I still can’t manage to pass the parameter to my TV

Hey did you have any luck in the end? I have an oled b7 and having the same issue as you. I see the pop up but no change in picture mode.

No still no luck…

Dude, I just found your solution, this was so helpful to me, thanks a buch for this!

Here’s the updated version for the latest Home Assistant:

First: sudo apt-get install netcat-traditional

then add to configuration.yaml:

command_line:
  - switch:
      name: "LG Picture Mode ECO"
      unique_id: "lgtv_pict_eco"
      command_on: "echo \"luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{\\\"category\\\": \\\"picture\\\", \\\"settings\\\": {\\\"pictureMode\\\": \\\"eco\\\"}}' & exit\" | nc 192.168.0.120 23"
      command_off: "echo \"luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{\\\"category\\\": \\\"picture\\\", \\\"settings\\\": {\\\"pictureMode\\\": \\\"normal\\\"}}' & exit\" | nc 192.168.0.120 23"
      command_state: "echo \"luna-send -n 1 luna://com.webos.settingsservice/getSystemSettings '{\\\"category\\\": \\\"picture\\\", \\\"keys\\\": [\\\"pictureMode\\\"]}' & exit\" | nc 192.168.0.120 23 | grep -c eco"
  - switch:
      name: "LG Picture Mode Cinema"
      unique_id: "lgtv_pict_cinema"
      command_on: "echo \"luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{\\\"category\\\": \\\"picture\\\", \\\"settings\\\": {\\\"pictureMode\\\": \\\"cinema\\\"}}' & exit\" | nc 192.168.0.120 23"
      command_off: "echo \"luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{\\\"category\\\": \\\"picture\\\", \\\"settings\\\": {\\\"pictureMode\\\": \\\"normal\\\"}}' & exit\" | nc 192.168.0.120 23"
      command_state: "echo \"luna-send -n 1 luna://com.webos.settingsservice/getSystemSettings '{\\\"category\\\": \\\"picture\\\", \\\"keys\\\": [\\\"pictureMode\\\"]}' & exit\" | nc 192.168.0.120 23 | grep -c cinema"
1 Like

Hi Jacek,
i’m not able to get your script working with my 55C6V but the problem seems to come from HA having problem with calling the script from the automation.
I have also another automation+script for input selection that is working fine.

Automation:

- alias: lg_smart_tv_select_picture_mode_eco
  trigger:
  - platform: state
    entity_id: input_select.lg_smart_tv_picture_mode
    to: eco
  action:
  - service: script.lg_webos_smart_tv_picture_mode
    data:
    picture_mode: eco
  #----------------------------------------
  - service: script.turn_on
    target:
      entity_id: script.script_audio_input
    data:
      variables:
        audiofile: /share/Speech_On.wav
  #----------------------------------------
  mode: single

and script wich is yours:

lg_webos_smart_tv_picture_mode:
  sequence:
  #----------------------------------------
  - service: script.turn_on
    target:
      entity_id: script.script_audio_input
    data:
      variables:
        audiofile: /share/Speech_On.wav
  #----------------------------------------
  - service: webostv.command
    data:
      entity_id: media_player.lg_webos_smart_tv
      command: system.notifications/createAlert
      payload:
        message: >-
          {{ picture_mode }}
        modal: false
        buttons:
          - label: "ok"
            focus: true
            buttonType: "ok"
            onClick: "luna://com.webos.settingsservice/setSystemSettings"
            params:
              category: "picture"
              settings:
                pictureMode: >-
                  {{ picture_mode }}
        type: "confirm"
        isSysReq: true
  - delay: 0.6
  - service: webostv.button
    data:
      entity_id: media_player.lg_webos_smart_tv
      button: ENTER

Error message in logs when reloading automations:

** Automation with alias 'lg_smart_tv_select_picture_mode_eco' could not be validated and has been disabled: extra keys not allowed @ data['action'][0]['picture_mode']. Got 'eco' template value is None for dictionary value @ data['action'][0]['data']. Got None*

Thank you for any help :slight_smile:
Eddy, Belgium

PS: The audio script is just there temporarily to “ear” if the script runs…

Hi Eddy. I think the problem is about the indentation in you automation code.

it should be:

  - service: script.lg_webos_smart_tv_picture_mode
    data:
        picture_mode: eco

Now HA complains about missing picture_mode value, it’s caused by wrong formatting

Jacek, you saved me :slight_smile:
No more error in logs but i’ll have to wait a few hours to check with my LG TV, i’m still at work :wink:
Thanks !
Eddy

1 Like

The script with command and luna, as above, doesn’t work with my 55C6V.
Instead, i just tried with button and it’s ok. Example below. I usually just switch eco and cinema mode, so with a left or right button.

- alias: lg_smart_tv_select_picture_mode_eco
  trigger:
  - platform: state
    entity_id: input_button.lg_tv_mode_eco
  action:
  - service: webostv.button
    data:
      entity_id: media_player.lg_webos_smart_tv
      button: MENU
  - delay: 0.7
  - service: webostv.button
    data:
      entity_id: media_player.lg_webos_smart_tv
      button: DOWN
  - delay: 0.9
  - service: webostv.button
    data:
      entity_id: media_player.lg_webos_smart_tv
      button: ENTER
  - delay: 0.7
  - service: webostv.button
    data:
      entity_id: media_player.lg_webos_smart_tv
      button: LEFT
  - delay: 0.7
  - service: webostv.button
    data:
      entity_id: media_player.lg_webos_smart_tv
      button: BACK      
  mode: single
1 Like

Looks like the TV has to be rooted to pass luna commands… ?
Has someone a good tuto to root a LG without to much risk… ?
Ok, no way, my 55C6V is on 3.4.2 firmware so i can’t…
Thanks,
Eddy

I’ve been using this for a while now, and it’s been working really well.

I was wondering, is there an option to ‘get’ the current ‘picture_mode’.

The reason I ask is, I mainly use this to switch the LG C8 to game mode when I’m using the Xbox.

By default it works a treat on the dashboard. However if a game is in HDR or DV, I have to manually change to HDR or DV game mode as well.

My thinking is, if I can monitor the current picture more, I could do something like.

If picture_mode changes & input = xbox
if picture mode like Dolby Vision, call script, set Dolby Vision Game mode (or whatever the command is)
if picture mode like HDR, call script, set dolbyHdrGame

Edit: Looking through the API doc, there’s a batch example that has

{
“method”: “getSystemSettings”,
“params”: {
“category”: “picture”,
“keys”: [
“brightness”
],
“subscribe”:true
}
},

Which returns

{

“method”:“getSystemSettigns”,

“settings”: {

“brightness”: “50”

},

“category”: “picture”,

“dimension”: {

“input”: “comp1”,

“pictureMode”: “normal”,

“_3dStatus”: “2d”

},

Do you think it’s possible to make a call to ‘getSystemSettings’ with something like keys: [pictureMode]?

Hi. I think it isn’t possible using scripts or available services. Maybe when webostv.command service will be able to return values, so far it doesn’t support this.
Since HA 2023.7 it is possible but i wasn’t implemented so far in webos integration.

Thanks Jacek for responding. Good to know I wasn’t going mad, as I was struggling to get it to work :slightly_smiling_face:

Speaking of, is there a way to get info if currently playing content is HDR/DV or not? I’d like to control LED strip on the back of my TV depending on it.

Great tips in this post!

Does anyone know if we can turn on/off the “eye comfort mode” using the integration (without using UP, LEFT, RIGHT etc)? I’ve been searching the web but has not seen any mentionings of it.

1 Like

After scouring the web to find the right command for the “blue light filter,” I was finally able to get it working on my LG C1 with this script by setting eyeComfortMode

sequence:
  - service: webostv.command
    data:
      entity_id: media_player.lg_webos_smart_tv
      command: system.notifications/createAlert
      payload:
        message: Setting blue light
        modal: false
        buttons:
          - label: ok
            focus: true
            buttonType: ok
            onClick: luna://com.webos.settingsservice/setSystemSettings
            params:
              category: picture
              settings:
                eyeComfortMode: on
        type: confirm
        isSysReq: true
  - delay:
      milliseconds: 40
  - service: webostv.button
    data:
      entity_id: media_player.lg_webos_smart_tv
      button: ENTER

1 Like

Thanks for posting this @sblatz! This solved a long running problem for me, I’m now able to change to “Game” mode automatically when Android TV Remote integration see’s I’m running SteamLink or Moonlight.

That’s a weird hack to get it to run a luna command by making it part of an onClick event and then sending the click. Nothing even shows up on my screen, it just works!

Script to change TV picture mode based on a variable

alias: Living Room TV Change Picture Mode
sequence:
  - service: webostv.command
    data:
      entity_id: media_player.living_room_tv_webos
      command: system.notifications/createAlert
      payload:
        message: Setting Game Mode
        modal: false
        buttons:
          - label: ok
            focus: true
            buttonType: ok
            onClick: luna://com.webos.settingsservice/setSystemSettings
            params:
              category: picture
              settings:
                pictureMode: "{{ pictureMode }}"
        type: confirm
        isSysReq: true
  - delay:
      milliseconds: 40
  - service: webostv.button
    data:
      entity_id: media_player.living_room_tv_webos
      button: ENTER
mode: single
icon: mdi:gamepad
fields:
  pictureMode:
    selector:
      text: null
    name: pictureMode
    description: Picture Mode of the TV
    required: true

Automation to capture running app_id and run script

- id: Game Mode On
  alias: Game mode on
  trigger:
    platform: state
    entity_id: media_player.shield_android_tv
    attribute: app_id
    to: 
      - com.valvesoftware.steamlink
      - com.limelight
  action:
    - service: script.living_room_tv_game_mode
      data:
        pictureMode: game

I have one that restores “normal/standard” after I’ve exited those:

Automation to change TV to “normal/standard” picture mode

- id: Game Mode Off
  alias: Game mode off
  trigger:
    platform: state
    entity_id: media_player.shield_android_tv
    attribute: app_id
    from:
      - com.valvesoftware.steamlink
      - com.limelight
  action:
    service: script.living_room_tv_game_mode
    data:
      pictureMode: normal
2 Likes

This is a wonderful idea, you inspired me to see if I can get from Home Assistant which app an AppleTV is running and change the game accordingly.