Use the Aqara FP2 sensor to switch on the energy-saving mode on the TV

I have installed an Aqara FP2 presence sensor in the living room, this runs under the name:
binary_sensor.aqara_fp2_bewegungsmelder_wohnzimmer_presence_sensor_1

I have also created a switch in HA to set my LG TV to energy-saving mode.
configuration.yaml:

command_line:
  - switch:
      name: "LG Energy Mode"
      unique_id: "lgtv_energy"
      command_on: >
            echo "luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{\"category\": \"picture\", \"settings\": {\"energySaving\": \"max\"}}' & exit" | curl --raw --max-time 1 telnet://192.168.127.232:23
      command_off: >
            echo "luna-send -n 1 luna://com.webos.settingsservice/setSystemSettings '{\"category\": \"picture\", \"settings\": {\"energySaving\": \"auto\"}}' & exit" | curl --raw --max-time 1 telnet://192.168.127.232:23
      command_state: > 
            echo "luna-send -n 1 luna://com.webos.settingsservice/getSystemSettings '{\"category\": \"picture\", \"keys\": [\"energySaving\"]}' & exit" | curl --raw --max-time 1 telnet://192.168.127.232:23 | grep -c max

Now I would like to link the two, so if the presence sensor detects that nobody is in the room, it should switch on the energy-saving mode, and vice versa, switch it off again.
But I can’t get the automation to work, I can’t find a way to execute the corresponding command_line command.

Does anyone have any advice?