How to create a custom component from one removed from HA itself

As recent HA releases do removal of integrations not maintained anymore, or just not in-line with the architecture decisions (see architecture/adr at master · home-assistant/architecture · GitHub for the up-to-date list), some users are left wondering what to do about that integration that is working for them, but which is not available anymore.

The response is clear: make a custom component out of the latest available code.

Now, that in itself might comes in 2 flavors:

  • The happy one: someone knowledgeable decided to take over the maintenance of that component and add it to HACS; Just install HACS, look for the component and install it. Done :slight_smile:

  • The sad one: nobody did so, and you are left to do the job yourself :frowning:

This guide will explain you step-by-step how to create a custom component out of HA code that was removed. It will take the DHT integration as an example, that was removed in 2022.4.

1. Where is the code?

Git and branches

  • The whole code of HA is available on github

  • Git is version management system. It is used to “store” and version code, python code as far as HA is concerned.

  • Git has the notion of “branches”; a branch is alike to a version of the code.

  • HA uses dev as its main branch; it is on this branch that code is added and removed on a daily basis.

  • Every month (currently) the rc branch is created from dev; this branch is the base for the monthly beta and the upcoming release.

Git and tags

  • At release time, the current code of rc is “tagged”; a tag is a pointer to a version of the code at a given moment

  • HA creates a new tag for every release, beta or final; you have, e.g., “2022.3.8”, “2022.4.0b4”, “2022.4.0” tags.

2. All nice, but where is THE code?

If you peruse the current HA code, on dev branch, the DHT code should be in the core/homeassistant/components/dht subdirectory. But, as it was removed, it isn’t there anymore unfortunately, so we’ll have to get it back from an older version of HA.

  • First, let’s find the latest code where the dht component was available. In this case, it was last in version 2022.3.8.

  • On the HA GitHub main page, click on “Releases”, on the right panel

Releases

  • You’ll reach the huge list of HA releases with their changelogs. Browse down until you find the release we are interested in, “2022.3.8”

  • We found the release, now we have to grab the actual files from that release. Click the “Assets” then the sources.zip link to download the source code from release 2022.3.8 to your local machine.

Download the sources

  • You’ll get a file with a name similar to core-2022.3.8.zip. Opening this ZIP with the tool of your choice, you will finally find back the missing code.

Get the ZIP

3. Great. Now what do I do with it?

Glad you asked, but here comes the easy part, really.

  • Copy the dht folder from the zip file to the custom_components subfolder of you HA config.

    • There are a bazillions way to do this depending on what local OS you use, which HA installation, … so I won’t go into details here
  • Expected result:

Got the code

3. Super. I am all set now, am I?

Not quite. The manifest.json must be edited to add a version tag. That is a HA requirement specifically for custom components.

  • Edit the manifest.json (I’m using VS code, here)

  • Add a “version” line in the json. The number can be anything looking like a version, really. Here, I’m using the actual version of the dht code that will be used.

4. Profit!

  • Save an restart HA. All done :slight_smile:

Keep in mind to restart HA before adding back the component configuration, if applicable, or HA will complain it cannot find (yet) the component.

Alternative path is to restart your HA machine altogether :wink:

8 Likes

What if the component depends on a file that is or used to be at helpers folder ?

Is there somekind of custom_helpers ?

No. This is about integrations and the builtin way to use custom components.
What is your issue, here?

Thanks, really helpful guide.

I was thinking on an deprecated integration that depends on a code that also is at helpers folder.

I would be able to copy the deprecated integration to custom_components folder, but not the code that it depends.

Unless there is somekind of custom_helpers or I also could copy the code from helpers folder and update its imports.