I followed a post from this: Writting sensors' values to Google Sheets to write values to Google Sheets.
This is my AppDaemon config:
system_packages: []
python_packages:
- hass-apps
- gspread
- oauth2client
init_commands: []
This is in my apps.yaml
google_sheets:
module: gsheets
class: GSheets
And this is my gsheets.py
import appdaemon.plugins.hass.hassapi as hass
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import datetime
class GSheets(hass.Hass):
def initialize(self):
self.log("GSheets started")
runtime = datetime.datetime.now()
addseconds = (round((runtime.minute*60 + runtime.second)/300)+1)*300
runtime = runtime.replace(minute=0, second=0, microsecond=0) + datetime.timedelta(seconds=addseconds)
self.run_every(self.publish_to_gs,runtime,300)
def publish_to_gs(self,kwargs):
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('/share/googleDriveCredentials.json', scope)
client = gspread.authorize(creds)
fmt = '%Y-%m-%d %H:%M:%S'
d = datetime.datetime.now()
d_string = d.strftime(fmt)
state_temp = self.get_state("sensor.solar_power_current")
state_humi = self.get_state("sensor.solar_power_today")
sheet = client.open("data").sheet1
row = [d_string,state_temp,state_humi]
index = 6
sheet.insert_row(row, index, value_input_option='USER_ENTERED')
And this is what the log shows:
2020-05-06 17:48:23.860971 WARNING google_sheets: ------------------------------------------------------------
2020-05-06 17:48:23.862311 WARNING google_sheets: Unexpected error initializing app: google_sheets:
2020-05-06 17:48:23.863667 WARNING google_sheets: ------------------------------------------------------------
2020-05-06 17:48:23.871420 WARNING google_sheets: Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/appdaemon/app_management.py", line 820, in check_app_updates
await self.init_object(app)
File "/usr/lib/python3.8/site-packages/appdaemon/app_management.py", line 271, in init_object
modname = await utils.run_in_executor(self, __import__, app_args["module"])
File "/usr/lib/python3.8/site-packages/appdaemon/utils.py", line 276, in run_in_executor
response = future.result()
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/appdaemon/apps/gsheets.py", line 2, in <module>
import gspread
ModuleNotFoundError: No module named 'gspread'
2020-05-06 17:48:23.874022 WARNING google_sheets: ------------------------------------------------------------
So I think it misses the gspread module. I am on Hassio, so how do I enable it?