Regular python script for testing?

Hi everybody,

after getting into AppDaemon after a lot of help in these forums, I am currently writing some test scripts to understand how things work and what I can “outsource” to AD, etc.

Is it possible to test scripts locally rather than in AppDaemon? Let me explain: I have two AppDaemon docker containers on my home server (alongside Home Assistant). The first is the initial installation, the second one a custom instance for testing only.

I’d like to run small test scripts on my local machine (so not one the home server) before actually integrating them into the main appdaemon instance.

Can I do this? So instead of these scripts running constantly, just manually run run them, see the output, change them, debug, etc., and once I am happy with how they work, transfer them to AppDaemon…

I could also create yet another docker container on my local machine, but containers make it a bit difficult to install additional libraries (well, not really difficult, but at least labor intensive); I have tried virtualenv instead, but when I did, appdaemon would never successfully initialize any new modules (not even those that are successfully running on in production).

What I currently do is hardcoding things I’d usually receive from home assistant (for example testvalue = [123, 23, 74]) into regular python scripts, run and debug them, then integrate them into appdaemon. While this works, it requires me to rewrite my working code as appdaemon modules require a different structure (connecting, initializing) than “regular” scripts.

Sorry if this is a stupid question. Perhaps there is a much better solution that I hadn’t thought of?

1 Like

AppDaemon doesn’t work in a “single script” mode. It needs the plugin code (to attach to home assistant), the scheduling code (to allow run_in, run_every, run_daily, etc to work), and all of the state management code (to allow for get_state, listen_state, etc) in order to do it’s thing.

However, you can run it on your local machine, depending on WHAT your local machine is. I’ve done so under both OSX and Ubuntu. You can also run AppDaemon from the command line instead of as a service so that you can CTRL-C and the process will end. By placing just one AppDaemon app in your local configuration and running AppDaemon on the command line, you would be testing just the one script.

If you’re using the AppDaemon docker image, additional libraries can be easily installed using requirements.txt. This is actually exactly what I do. I have a local docker container pointed to local directories that I use to test any apps before copying them into my production AppDaemon instance.

1 Like

Thank you. I missed this part

Sometimes it can be helpful to install additional Python dependencies into the Docker container before AppDaemon starts, to allow additional libraries to be used from Apps. The Docker script will recursively search the CONF directory for any files named requirements.txt. All the found requirements will be used as input to pip3 to install any packages that they describe.

Which does exactly what I’d need it to. Now I’ll try a docker container on my local machine :slight_smile:

1 Like