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
-
The sad one: nobody did so, and you are left to do the job yourself
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 fromdev
; 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
- 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.
- 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.
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 thecustom_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:
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
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