WTH: Why don't the developer documents cover VSCode's setup?

The development documents only cover a small portion of the ‘setting up a development environment’. However these docs miss the most important part: Setting up the IDE (visual studio code) to properly run, with breakpoints. Simply providing an example launch.json would probably suffice.

For example: The dev container route describes all the requirements to set up ‘dev contianer’ on all 3 major operating systems. It even claims that VSCode is required. However the last set of instructions just get you a container running in docker. Additional setup is needed to get Home Assistant running with your changes.

I stumbled upon this thread with a lengthy vscode setup process for VSCode & Dev Container. I don’t know if this is correct however it worked for me. Either way, this should be included in the dev docs by someone “in the know” with proper corrections.

We really need this documented!
My development looks like this:
I copy/create a new integration in custom_components, do the edits, I add as many logger messages as I can, and then I start everything using hass -c config.

I have no idea how to use breakpoints while developing for HA, this is really frustrating and I lose a lot of time because I need to log everything I need.

I’m using Windows 10, I have Docker installed, when I clone the repo and open it in VS Code it is suggesting to reopen the folder in DevContainer (which is ok). But there is nothing about breakpoints and using actual hardware, in my case Raspberry Pi in development - I’d like to create a couple of integrations for specific hardware (mostly I2C). Ideally, I should be able to use a Raspberry Pi to run and debug my changes while using VS Code on my PC.
Can we use Windows and VS Code to develop and run code on Raspberry Pi with breakpoints?

Yep, and you can. I’m pretty sure all you need to do is:

Add the remote python debugger to configuration.yaml. It’s interesting, I didn’t know about this integration until yesterday late at night. After looking at those docs, it pretty much spells out everything you need. So in order to satisfy this WTH, the dev docs should just link to this integration.

# Enable VSCode debugging
  start: true
  wait: true

Then in VSCode terminal (with your dev container open) use this command:

hass -c config --debug

VSCode should then wait for attachment. Then in vscode run the following launch file:

    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
            // Example of attaching to my production server
            "name": "Python: Attach Remote",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "homeassistant.local",
            "pathMappings": [
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "/usr/src/homeassistant"

This assumes that your domain is local. If you don’t know it or just want to use the IP, change

            "host": "homeassistant.local",

to your correct IP

            "host": "",

When you press run (if you have more than 1 launch config), select Python: Attach Remote.

Because python is weird with debugging, it requires libraries to attach unlike C# and other languages. I knew that but still wasn’t thinking about it being an integration (Stupid on my part). Anyways, I believe that the debugpy configuration opens the ability to attach to HA with debug via port 5678.

1 Like