Direct editing of add-on source code to try code tweaks

I want to try some minor tweaks to an add-on directly in my HA environment. I’ve installed Portainer and in the app directory of its container I can see the python files of the add-on. If I edit a file (for testing my approach I’ve simply edited a write to the log which should show up but doesn’t) in the app directory and then restart the add-on, my edit is lost and the original file is returned. Clearly, restarting an add-on copies the source files from somewhere. Try as I might, I can’t find this original source. Can somebody point me in the right direction (ideally the appropriate documentation too)?

Ultimately, I might want to either fork the add-on or suggest to the original writer some updates.

The best way to do this, I find, is to create a copy of the integration and place its files/folders in a folder in the custom_components directory. Then add a version-line to the manifest.json file and you should be good to go.

You can do all this from within HA itself via the Visual Studio Code addon. Adding the directories, files and make the changes to the code.

1 Like

I think what you say only applies to integrations. Unfortunately I want to work with an add-on. Any suggestions for that?

Sorry, I did not read properly :slight_smile:
Yes, for an addon it’s best to fork to your own github repo, make the changes and load it from that repo too. I’ve done this in the past too.

When the changes work, you can create a pull-request for them from your own repo. There will be a button for that shown when you have made the changes, all automatic.

1 Like

I would suggest reading this: Local add-on testing | Home Assistant Developer Docs

1 Like

I have read this but confess to still being lost. I suspect there’s a gap in my understanding of how the whole docker environment works. The local run option, which would seem to be what would be best for me, is confusing to say the least (and I’m not IT illiterate, quite the opposite).

If you can steer me in the right direction I’d really appreciate it. If there are any tutorials, videos etc out there that would be perfect. I don’t want to waste anyone’s time.

To start with, I simply want to make some small tweaks to an existing add-on. I’ll be doing this in my production environment (I know this is bad practice but I really am talking about tweaks and I’m confident as I can be nothing will break, plus I don’t have another option at the moment). I want to edit the code of the add-on, restart it, see what happens, make another edit, repeat ad nauseam. I can’t find where the local “master” source for the add-on is (I can’t believe an add-on is dependent on github for a restart, HA must be resistent to network failures if it restarts, I presume that when an add-on restarts, a master of it is copied to the docker container where it runs).

If I can work this out I’ll happily document how I did it to help others in the future.

Any add-on is an executable but restricted with exact port numbers to communicate with outside world. When you containerized the executable, you are sealing the content but can allow some folders to be mounted externally, so you can go with external volume path but i would say, let’s go easy.

Setup the executable somewhere else, run it there without docker or add-on and test your changes. When you are done, you can update the main add-on with your changes.

Take this random example: GitHub - bropat/hassio-eufy-security-ws: Official eufy-security-ws Home Assistant add-on repository

If you look at run.sh file, you will see how arguments are generated and what is the exact runnable at the end. (https://github.com/bropat/hassio-eufy-security-ws/blob/b9e330c18c32bd5c1a898451550b5849eac6bc1f/eufy-security-ws/run.sh)

You can copy all these locally and run without using docker and add-on, redirect your whatever integration to this local version.

Lastly, please share the addon you are mentioning:-)

1 Like

I’ll digest this later when I’ve some time. The add-on I want to tweak is this one (which is unlikely to be of interest to many people!): GitHub - egguy/grott-home-assistant-add-on: Grott Home Assistant add-on - Native MQTT plugin.

this is the file eventually being run: https://github.com/egguy/grott-home-assistant-add-on/blob/31269b7d39d060e36aa9ed5cf7f84888e39b6bd5/grott-current/script.sh

1 Like

Run the addon locally (from /addons), use the Dockerfile to COPY the modified file to destination path i.e. overwrite.

Can you provide more detail please? I’ve overwritten files as I said at the start of this thread but the original add-on takes over.

Ok, short steps of the method I proposed:

  1. fork the repo from eqquy to you own github repo,
  2. in your own repo, make the changes you want,
  3. uninstall the addon by egguy,
  4. restart HA,
  5. add your repo to HA to be able to install your version of the addon (I’m not sure if a restart is needed at this point),
  6. install the addon from your own repo, restart HA,
  7. now you version of the addon should be active.

Other readers, feel free to correct/add :slight_smile:

2 Likes