How to edit components in Hass.io?

This seems like it should be simple, but none of the instructions I have found seem applicable to what I am seeing.

I have a HASSIO system running on a Rasberry PI 3B. The HA version says 0.93, the HASSIO says it’s HASSOS 2.11 on the system tab in the web UI. This is just the standard build you get from the HA website that I flashed onto a 32GB SD card.

I want to edit one of the components that comes with the system (specifically, I want to create a custom version of the aqualogic component), but as far as I can tell I have no local components files on the system.

If I ssh to the HASS, login as root, I can see that there is a “config” folder, but there’s almost nothing there. All I see are the yaml files, there are zero python files of any kind. Searching around I did find a /usr/lib/python3.6 dir, but I don’t see anything for aqualogic there either.

It seems like I’m missing libraries, but I can’t find anything the clearly spells out that I would need to do something special to install the source code, all the threads I’ve read seem to assume that the source code is already on the box.

Any assistance appreciated.

1 Like

You should start by following the directions to set up an ssh login into the home assistant container (see instructions here about setting up port 22222: https://developers.home-assistant.io/docs/en/hassio_debugging.html). When you log in via ssh that way, you can get to the current Home Assistant Python files here: /usr/local/lib/python3.7/site-packages/homeassistant/components

An alternative is to clone the home assistant repo manually and find the “components” directory there: https://github.com/home-assistant/home-assistant

Create a custom_components directory in your config directory and copy the directory of the component you want to modify into that new directory. Home Assistant will then pick up your custom version whenever it starts. There’s more information about custom_components out there, too.

2 Likes

Thanks, this is helpful. I’ve created the pub/priv keys and I can get to the system on port 22222 now.

However, I’m still missing something. At first login I get the “hassio” prompt. That doesn’t allow me to navigate to any directories, so I assume I need to do the “login” option to get to a standard shell. Once I do the “login” option I get a standard shell and I can navigate directories, but there is no /usr/local/lib/python3.7 directory, all I have is a /usr/lib dir and there is no python there, there is no site-packages dir, no components dir, etc.

Would the files be located somewhere else? thanks

You need to end up in the main Home Assistant docker container and I wasn’t sure where the port 22222 ssh server puts you. I do this to get into the container from my Hass.io on Ubuntu installation, and I think it’ll work for you, too. You may need to do docker ps to make sure that you have the right container name.

docker exec -t -i homeassistant /bin/bash

1 Like

That did it, exact steps were:

  1. enable the pub-key SSH option to get to the box on 22222
  2. once logged in you get the “hassio” prompt, enter login
  3. once at the login shell enter docker exec -t -i homeassistant /bin/bash

Then you can navigate to the /usr/local/lib/python3.7/site-packages/homeassistant/components

Final question: the component I am interested in modifying references a core.py 2 levels up, can I just copy the core.py along with the component files to the custom_components or do I need to re-create an entire dir structure? thanks

1 Like

I don’t think you have to do anything other than copy the directory from …/components/… into config/custom_components. It should find the other dependencies back in the original location.

If you’re talking about things like “from homassistant.core import xxx”, my custom components do that without needing to replicate any more of the surrounding directory structure.

Cool, will try it, thanks very much for all the help!

Is it enough to copy the core component folder into the custom_components folder?
How do you test your modifications?
Do you need to restart the host system or is there a better way to test your modified core component?

Hi, I found this thread because I too want to edit the aqualogic component in HA. Predominantly to add the inexcusably left out switch to toggle between Pool and Spa. So I’m wondering if that was your reason and if you have already accomplished the task? If not I’ll get started.

Hi,
I did the following command to find the light.py :

find / -name "light.py" | grep flux
/usr/src/homeassistant/homeassistant/components/flux_led/light.py

It seems the location is hard to know and can change upon the context of your homeassistant instance and the way it runs.

Thanks for all your advices

Hi, I’m wondering because I want to use this tactic.

But I can’t seem to make it work, I tried copying the history component and for example change the icon but nothing happend.

Any tips, maybe it’s patched?
Thanks