Remote debugging from VSCode to live HAOS instance

I’m working on debugging some HomeKit thread stuff - so the remote debugger is a perfect solution for allowing me to see what’s going on within a live HAOS instance with a Thread radio attached to a live mesh with HK accessories. So I followed the instructions here: Set up Development Environment | Home Assistant Developer Docs and here: Remote Python Debugger - Home Assistant

I’ve forked core and have the correct version running in my VS Code workspace.
I’ve added:

debugpy:
  start: true
  wait: false

to my configuration.yaml

I launch “Home Assistant Attach Remote” from the VSCode debug tab - which uses this launch.json entity:

    {
      // Debug by attaching to remote Home Asistant server using Remote Python Debugger.
      // See https://www.home-assistant.io/integrations/debugpy/
      "name": "Home Assistant: Attach Remote",
      "type": "python",
      "request": "attach",
      "port": 5678,
      "host": "homeassistant.local",
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "/usr/src/homeassistant"
        }
      ]
    }

This is the default section for remote attach in the workspace - and it appears to be correct for my purposes.

The versions match:

Screen Shot 2023-03-24 at 9.55.49 AM
Screen Shot 2023-03-24 at 9.56.43 AM

I am able to set breakpoints in the relevant __init__.py module for the integration. (Without the correct localRoot or remoteRoot the breakpoints become greyed out.)

Screen Shot 2023-03-24 at 9.51.26 AM

The debugger attaches to the HA instance and shows a number of running threads.

Screen Shot 2023-03-24 at 9.52.47 AM

But the breakpoints never get hit - neither when restarting nor when reloading an integration entry.
logpoints don’t seem to do anything either.

Also, I am not seeing any messages at all in the debugger output.

This seems like I’m missing something simple.

Does anyone have any experience with this?

1 Like

I just stumbled upon the same Problem - can anyone help here?

1 Like

I have exactly the same problem.
if I put an breakpoint to util/json.py:76 (load_json) it stops as expected but a breakpoint e.g. at bootrap.py:700, one line after initializing the debugger, is not working.
Is no one here who can give a hint?

Not just me, then :sweat_smile:

I’m seeing the same, breakpoints light up (which they don’t if the remote path isn’t right) and I can see the list of threads etc, but breakpoints never seem to trigger.

I can pause execution (it takes about 7 seconds to do so) and step through wherever the main thread happens to be, but not at my set breakpoints.

I am developing a custom integration that is set up for HACS distribution (and is installed on the live instance via HACS), I wonder if it’s related to that?

After long trial of errors, I seem to have found a workaround that worked for me.

I needed to add a following line, just before the final “True” statement.
/usr/src/homeassistant/homeassistant/components/debugpy/__init__.py

debugpy.breakpoint()

For whatever reason it makes other breakpoints work.
What I also tried, and what did not seem to have an effect:

  • calling “loop.set_debug(True)” in /usr/src/homeassistant/homeassistant/core.py
  • passing “-X dev” and/or “-X frozen_modules” off and/or “–debug” in /etc/services.d/home-assistant/run
  • calling a sequence of “debugpy.listen(); debugpy.wait_for_client(); debugpy.breakpoint()” in /usr/src/homeassistant/homeassistant/main.py

As some additional context, I am running homeassistant 2024.4.4 on docker and I made those edits directly inside the container using vi.