Visual Studio Code has been a soaring success for Microsoft. The free and source-code editor was ranked the most popular developer environment tool in the Stack Overflow 2019 Developer Survey, just four years after its initial release.
Visual Studio Code has also proven to be a popular tool for editing Home Assistant YAML code. While YAML is being phased out more and more, there are still many integrations that haven’t been ported to the UI yet. So while we still have to edit YAML, we might as well make it as easy and efficient as possible.
Home Assistant Config Helper
If you, just like me, edit your Home Assistant YAML code in Visual Studio Code, you need the Home Assistant Config Helper extension installed. And the installation couldn’t be easier, it’s all done from within the app itself.
Installing the Home Assistant Config Helper
Press Ctrl+Shift+X on your keyboard or click on the extensions icon in the left-hand menu. Then simply search for Home Assistant and the first result should be the Home Assistant Config Helper. Select the extension and click on install. You will then be prompted to configure the extension.
Configuring the Home Assistant Config Helper
With the settings open, search for the Home Assistant Config Helper under Extensions. Next, enter the URL of your Home Assistant host. This can be the internal or public address.
Open Home Assistant and click on your username in the main menu. Scroll all the way down until you see the box titled Long-Lived Access Tokens. Create a new token by clicking on create token. Give this token a name (e.g., Visual Studio Code) and click OK. You will next be presented with said token. Copy the token and paste it into the Visual Studio Code settings. You must never share this code with anyone. If that were to happen, make sure you immediately delete it in Home Assistant. For the settings to apply, you might have to restart Visual Studio Code.
Using the Home Assistant Config Helper
To use the Home Assistant Config Helper, you will have to change the language in Visual Studio Code to Home Assistant in the bottom bar.
What the Home Assistant Config Helper does
The Home Assistant Config Helper does many things to help speed up your editing. I’ll highlight a few of my favourite features in the following paragraphs. A list of all the features can be found on the projects GitHub page.
Completion for entity IDs, services, scenes, and triggers
Let’s say you’re creating a new automation or setting up a binary sensor for room occupancy. Instead of painstakingly looking up the correct IDs of the entities you want to be included, the Home Assistant Config Helper will present a list of all available entities from which you can select the right one. The same goes for scenes, triggers, and services.
Completion and validation for configuration and Lovelace schema
Properties, values, and enums will be auto-completed and most schemes that Home Assistant uses will be validated.
Go to definition for includes
I use a lot of includes in my configuration, and thus this feature is very dear to me. By highlighting an include and clicking F12, it is possible to easily navigate between files.
If you use the Visual Studio Code add-on, you’re in luck because there’s nothing left to install for you. This extension is already included.