Shell_command: problems executing py

Hello,

I get an error when home assistant executes a shell command:

Error running command: python3 /home/homeassistant/gsheets.py 125, return code: 2
NoneType: None

I would like to push a value (in this case 125) to a google sheet via gsheets.py. When I execute the command via console (I am using configurator addon of hassio), it works without problems. But the shell command in the configuration.yaml throws an error.

I think there is something wrong with my path to client_secret.json and gsheets.py. But I have no idea - I tried several options (folder within /config, several path definitions, etc.), but no success…I am running hass.io on a tinker board, no venv.

configuration.yaml

shell_command:
uptosheets: python3 /home/homeassistant/gsheets.py 125

automations.yaml

  • id: push_power
    alias: push_power
    trigger:
    platform: state
    entity_id: input_number.myfield
    action:
    service: shell_command.uptosheets

gsheets.py

import gspread
from oauth2client.service_account import ServiceAccountCredentials
import datetime
import sys

scope = [‘https://spreadsheets.google.com/feeds’,
https://www.googleapis.com/auth/drive’]
creds = ServiceAccountCredentials.from_json_keyfile_name(‘/home/homeassistant/client_secret.json’, scope)
client = gspread.authorize(creds)
fmt = ‘%Y-%m-%d %H:%M:%S’
d = datetime.datetime.utcnow()
d_string = d.strftime(fmt)

val1 = sys.argv[1]

sheet = client.open(“test”).sheet1

row = [d_string,val1]
index = 1
sheet.insert_row(row, index, value_input_option=‘USER_ENTERED’)

Hi,
it might be a problem with the indention of the yaml-file. As to the format in the post one cannot really see, but make sure it looks like this:

- id: push_power
  alias: push_power
  trigger:
    platform: state
    entity_id: input_number.myfield
  action:
    service: shell_command.uptosheets

Anton.

I will check it but I dont think its a problem caused by the indention.
It seems that HA try to execute the .py script but without success.

Recommend increasing the log level for shell commands to get more detail on the error.