Executing python script in Hass.io (for config of Lutron Caseta)

How do you execute a python script in Hass.io?

To install the Lutron Caseta component, it’s necessary to run a python script to generate certificates.

Tried SSHing into Hassio and navigating to /config (where I’ve put the get_lutron_cert.py script), but I don’t seem to have access to python (tried “python get_lutron_cert.py”, “python3 get_lutron_cert.py”, etc but python is not found).

Ideas?

3 Likes

I thought the script needed to be run on the hassio box, but it seems that’s not the case. I ran the script on another machine, copied the resulting crt and key files over to hassio, and it worked.

That’s a good piece of information. However, I’m still not sure how to get through this script. I’m on a Mac and when I try to run the commands listed at the top of the script in a Terminal window I get errors immediately that I don’t know how to get around:

python -m venv env gives me /usr/bin/python: No module named venv.

If anyone can provide more detailed instructions and prerequisites for these commands and the script it would be greatly appreciated.

In the past I’ve always run it on my home assistant machine (not hassio), which had the Python virtual environment configured as per these initial install instructions. The script’s instructions seems to assume that you’re running it this way (on your home assistant machine that you installed HA on via Python virtual environment method).

If you’re running the script on your mac, you could try following these steps:

  1. You need to use pip to install a couple dependencies. In terminal, type which pip. If it returns a path (something like /usr/local/bin/pip), you’re all set. Move to step 2. Otherwise if it just gives you a blank prompt, you need to install pip. Follow this guide from step 1-5 to install pip (you can continue further to the virtualenv step too if you want - it’s a nice thing to have).

  2. Install the needed dependencies with pip install cryptography==2.1.3 requests==2.18.4

  3. Run the script with python get_lutron_cert.py (note: you need to be in the same folder in terminal for this to work, or you need to give the full path to the get_lutron_cert.py. Easiest method is to type the "python " part and then drag the .py file from Finder into your Terminal window).

Haven’t tested this as I have a different setup, but hope it helps!

I really appreciate the detail. Before I try to install and run all this from my Mac I did try to run it from my Pi, but got errors that so far no one has been able to explain or help with.

I’ll work through the steps and let report back if successful.

Thanks again for trying to help, but I’m just digging a deeper hole. The “instructions” in the script leave a lot of unanswered questions about the assumptions and I am not making any progress in getting this to work.

I tried installing things that you suggested on my Mac and turns out I had most of it, but I have a pip2 command, not a pip command. After all that I run the first command in the get_lutron_cert.py script “python -m venv env” and I get “/usr/bin/python: No module named venv”. It seems I’m still missing something that the script writer didn’t detail. I may just go back to the custom component I got working (by using a similar script) before they incorporated the “fix” in HA. It would be cool if the cert files I generated previously worked after they incorporated the fix in HA, but for some reason they don’t.

Thanks again for trying.

So… kept banging my head on this door and I have finally solved it. Apparently, on my Mac, I was running Python 2.7.14, but this script for creating the cert files requires a Python 3 version which supports the venv virtual environment (that’s what I was completely unaware of). I downloaded a Python 3 installer and ran it, then used “python3” in my python commands (vs. ‘python’ as detailed in the “instructions”) and it all ran perfectly. The cert files are installed now and working. Phey!

1 Like

Glad to hear you got it figured out. Yeah the instructions definitely assume a lot about your setup, and weren’t written with hass.io in mind. Would be great to get the docs updated with recommended workflow for hass.io users but I’m not quite sure what a proper workflow would be for various OSes etc. Hopefully someone is able to update the component to do this stuff through the hass.io interface rather than command line python.

1 Like

I’ve read so many forum posts on this, but I just cannot get this thing to work. Any help?

I’m trying to run this python script on my mac. I’ve done the following:

  • Installed Python3
  • Installed Pip
  • Did the following: pip install cryptography==2.1.3 and pip install requests==2.18.4
  • If I try: python get_lutron_cert.py, I get this error:

ImportError: No module named parse

  • If I try: python3 get_lutron_cert.py, I get this error:

ModuleNotFoundError: No module named ‘requests’

Any help?

I’ve tried altering the python script (based on guides online) to:
Changing this line:
from urllib.parse import urlparse
to:
from urlparse import urlparse

Still another error.

Please help. Nothing seems to work. Thanks.

I don’t totally understand how this works but I think pip works with python2 and pip3 works with python3.

Maybe try:

pip3 install cryptography==2.1.3
pip3 install requests==2.18.4
python3 get_lutron_cert.py

Also as a diagnostic, you can see what python packages you’ve successfully installed with:

pip freeze

and

pip3 freeze

(It seems like perhaps the requests package didn’t install successfully, or only installed for python2 and not python3)

1 Like

Yes! This is what finally got it working for me! Had to install Python 3 first but these commands finally worked! Thank you so much!!

I still see the odd like on this old thread, so wanted to update:

It looks like there’s a hassio package you can use to do this now.

Add the community add-on repository to your Add-On Store (Hassio in side menu > Add-On Store, and add https://github.com/hassio-addons/repository ). Then install “Lutron Certificate”