ESP32 Sensor connected via Wireguard does not work

Thank you @glitch69! Your example got me on the right track. For others looking to get this working, follow these steps:

  1. Use the ‘Advanced SSH & Web Terminal’ add-on and run this command in the terminal:

    host a0d7b954-wireguard
    

    This will give you the Docker IP of your WireGuard instance (mine was 172.30.33.11). Confirm the hostname on the WireGuard add-on info screen.

  2. You will need:

    • Docker IP of your WireGuard instance (e.g., 172.30.33.11)
    • WireGuard VPN subnet (e.g., 10.42.42.0/24)
    • Your Home Assistant server LAN IP (e.g., 192.168.1.242)
  3. Add the following to your configuration.yaml:

    - platform: command_line
      name: WireGuard addon internal IP
      command: >
        ip route replace 10.42.42.0/24 via 172.30.33.11 src 192.168.1.242
    
  4. Restart Home Assistant.

  5. In the integrations, add an ESP device using the WireGuard IP of your ESP device. It may show as offline in the ESPHome add-on, but you should still be able to connect and view logs wirelessly.

  6. Ensure you have the use_address setting under WiFi in your ESP configuration.

I hope this helps someone else. I spent way too long figuring this out.

2 Likes

@skyflyt86 When adding this to the config.yml is there a certain area that this needs to be added. I have tried setting this up several times now with no success. I am able to ping to the esp8266 device over the wireguard vpn but cannot add the device in home a assistant through integrations → esphome node → IP/port. I am insure if I am missing something but just wanted to ask. The only way that I can ping the esp device is by running the command listed above ( `host_result=$(host a0d7b954-wireguard); addon_ip=${host_result##*
}; ip route replace 192.168.5.0/24 via $addon_ip src 192.168.x.x. Placing in th proper IPs accordingly.

Thanks, for any help

I assume this is with the Wireguard add-on for Home Assistant? I’m having similar issues, but I’m running Wireguard on my Unifi dream machine router. Is there a similar approach I need to use in my situation?

No, this discussion is about esphome.

I’m using ESPhome within HA as well, but I’m not using the Wireguard add-on for HA, I’m running Wireguard on my Unifi firewall.

Did you find a solution for your situation? I’m in a similar boat.