Help with command_line switch using telnet

Attempting to create a command_line switch to switch picture modes using telnet with an LG webOS Tv.

Logging in directly with Putty and using below code makes the desired “on” behaviour happen.

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

The below:

luna-send -n 1 luna://com.webos.settingsservice/getSystemSettings
 '{"category": "picture", "keys": ["pictureMode"]}'

returns the following output


I have found the below code which is meant to work, but does not.

  - platform: command_line
        unique_id: "lgtv_pict_bright"
        command_on: "echo \"luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{\\\"category\\\": \\\"picture\\\", \\\"settings\\\": {\\\"pictureMode\\\": \\\"expert1\\\"}}' & exit\" | nc 23"
        command_off: "echo \"luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{\\\"category\\\": \\\"picture\\\", \\\"settings\\\": {\\\"pictureMode\\\": \\\"expert2\\\"}}' & exit\" | nc 23"
        command_state: "echo \"luna-send -n 1 luna://com.webos.settingsservice/getSystemSettings '{\\\"category\\\": \\\"picture\\\", \\\"keys\\\": [\\\"pictureMode\\\"]}' & exit\" | nc 23 | grep -c expert"
        friendly_name: "LG Picture Bright"

Any help appreciated. Thanks.

What is in the homeassistant log - any error messages?

Nothing coming up in logs.

What log level do you have set for homeassistant.components.command_line? You should set it to at least info, and possibly debug, then look in the full log for related INFO and/or DEBUG messages.

Also, what type of install are you using? When you say you “logged in directly”, is it in the same context, and with the same user, that HA uses?

Installed on Raspberry Pi 4 with an SSD using Rpi imager.

Connected directly to TV using laptop via Telnet with PuTTY. There is no user/pass.

Changed log level to debug, and still no issues flagged.

I suspect the issue is with the command_state line.

I meant HAOS, Docker, Core in Python venv, etc. I’m guessing HAOS???

I meant how did you log into the machine running HA?

Oftentimes this kind of issue (works from the command line, but not in HA) has more to do with the context HA runs in and the HA user vs your user account; i.e., permission issues. That’s why I’m asking for those details.

Please note that INFO & DEBUG messages will not appear on the UI Log page. You have to either click the button to load the full log, or go look directly in the home-assistant.log file.

With some persistence finally managed to fix it…

  - platform: command_line
        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://
        command_off: >
            echo "luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{\"category\": \"picture\", \"settings\": {\"pictureMode\": \"expert2\"}}' & exit" | curl --raw --max-time 1 telnet://
        command_state: > 
            echo "luna-send -n 1 luna://com.webos.settingsservice/getSystemSettings '{\"category\": \"picture\", \"keys\": [\"pictureMode\"]}' & exit" | curl --raw --max-time 1 telnet:// | grep -c expert1
        friendly_name: "LG Picture Bright"