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 sysscope = [‘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’)