Controlling TV via python script does not work: Error 2

Hello,

I have a python script which configures the background light of my television. If I call it via SSH on my Raspberry Pi which is running Home Assistant everything works like a charm:

python3 tv_brightness.py

I want to go a step further and want to run it via a Lovelace button, but this is not working. The error message is:

Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/init.py:113
Integration: Shell Command
First occurred: 1. Dezember 2020, 21:28:05 (6 occurrences)
Last logged: 11:15:24

Error running command: python3 "tv_brightness.py", return code: 2

NoneType: None

type: button
name: Fernseher dunkel
show_state: false
tap_action:
  action: call-service
  service: script.dark_tv
  service_data:
    entity_id: script.dark_tv
icon: 'hass:television'

/config/scripts.yaml:

turn_off_tv:
    sequence:
      service: shell_command.tv_off
      
dark_tv:
    sequence:
      service: shell_command.tv_dark

/config/configuration.yaml:

shell_command:
  tv_off: python3 -m samsungctl --host=192.168.x.x --name HomeAssistant KEY_POWEROFF
  tv_dark: python3 "tv_brightness.py"

The configuration.yaml contains a shell_command with the name “tv_off” which is working in contrast to “tv_dark”. The difference is that tv_off is only a single call to a python-module instead of a script.

I tried to chmod tv_brightness to 777 but this isnt helping. I also tried to place the files in different paths. Currently they are in /home/pi/.local/bin but I tried to place them in /usr/share/hasio/homeassistant/scripts also without luck.

The contents of the script tv_brightness.py can be runned manually via SSH so it can’t be the problem here.

Is there anything I am missing? Any suggestions?