I’ve been working on a couple python scripts to run from HA, and i’m struggling with debugging. After a day of trial and error, I was able to determine that HASS was in fact calling my script, but it’s complaining about modules that don’t exist, even though I can successfully run the script from the venv command line.
here is my trial script
#!/usr/bin/env python3
try:
import syslog
import sys
import requests
import yaml
secrets = yaml.load(open('/home/homeassistant/.homeassistant/configuration.yaml'))
syslog.syslog(secrets['media_player'])
syslog.syslog("CUSTOM COMMAND: Getting Garage Door Status")
except Exception as e:
syslog.syslog("EXCEPTION: %s" % e)
running from the command line I’m ny venv, it executes and I get a syslog line as expected.
when I run it from HA, I get
/garagedoor.py: EXCEPTION: No module named 'yaml'
I use system to run HA, and it should be starting in the venv.
[Unit]
Description=Home Assistant
After=network.target
[Service]
Type=simple
User=homeassistant
ExecStartPre=source /srv/homeassistant/homeassistant_venv/bin/activate
ExecStart=/srv/homeassistant/homeassistant_venv/bin/hass -c "/home/homeassistant/.homeassistant"
[Install]
WantedBy=multi-user.target
I start the service with
sudo service homeassistant start
As a last ditch effort, I stopped the system homeassistant instance ,and ran it from the venv command line
hass
Once I did that, my script ran fine.
Anyone have any ideas why I can’t get it to execute in the venv from the system daemon?
Thanks!