If you are running the script in the home assistant docker container where these packages are not installed, as the configuration is valid for the appdaemon container.
AppDaemon is a docker container on its own and scripts must be run from within appdaemon and that is set up in the ‘/config/appdaemon’ directory tree where you would normally be keeping the scripts as well.
To call a script, you should be able to use my setup:
/config/appdaemon/apps/call-script/call_script.py:
import os
import sys
import subprocess as s
import adbase as ad
import hassapi as hass
class CallScript(hass.Hass):
def initialize(self):
event_name = "call_script"
if "event" in self.args:
event_name = self.args["event"]
self.listen_event(self.call_script, event_name)
self.call_script()
@ad.app_lock
def call_script(self, *args, **kwargs): # pylint: disable=unused-argument
if "script" not in self.args:
raise("Missing script parameter for CallScript")
script_args = [self.args["script"]]
if "args" in self.args:
s_args = self.args["args"]
script_args.extend(s_args)
out = sys.stdout
err = sys.stderr
closeout = False
closeerr = False
if "outfile" in self.args:
out = open(self.args["outfile"], "w")
closeout = True
if "errfile" in self.args:
err = open(self.args["errfile"], "w")
closeerr = True
s.call(script_args, stdout=out, stderr=err)
# Close files as needed
if closeout:
out.close()
if closeerr:
err.close()
Then add a configuration in apps, example: /config/appdaemon/apps/scripts.yaml:
chrome_filetype:
module: call_script
class: CallScript
event: call_file
script: /usr/bin/file
args:
- /usr/bin/chromedriver
- /usr/bin/chromium-browser
- /usr/bin/python3
- /usr/bin/python3.10
- /usr/lib/chromium/chromedriver
outfile: /config/appdaemon/apps/script.log
errfile: /config/appdaemon/apps/scripterr.log
The above will call ‘/usr/bin/file’ in the AppDaemon container when the ‘call_file’ event is triggered.
In my case that results in /config/appdaemon/apps/script.log containing:
/usr/bin/chromedriver: symbolic link to ../lib/chromium/chromedriver
/usr/bin/chromium-browser: symbolic link to ../lib/chromium/chromium-launcher.sh
/usr/bin/python3: symbolic link to python3.11
/usr/bin/python3.10: cannot open `/usr/bin/python3.10' (No such file or directory)
/usr/lib/chromium/chromedriver: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, BuildID[sha1]=1e63da5a822ad402ffc12658fe24f2939b40daba, stripped
Adding a configuration file ‘/config/appdaemon/apps/tplink.yaml’ as follows with ‘call-script’ in place should execute your script with access to the selenium package as expected when firing the event ‘reboot_tplink’:
tplink:
module: call_script
class: CallScript
event: reboot_tplink
script: /usr/bin/python3
args:
- /config/scripts/python/tp_link_reboot.py
- --args
outfile: /config/scripts/python/tp_link_debug.log
errfile: /config/scripts/python/tp_link_debug_err.log