Portable ESPHome devices

I’m trying to get a portable esphome device to stay connected to my home assistant when I’m travelling.

I set it up to use wireguard client when it’s connected to other WiFi networks, it works and I can see it connected to my wireguard server whenever it’s connected to a different WiFi.
However, when connected to wireguard, the device is neither available in home assistant nor it is accessible via it’s peer IP 10.10.10.13 from home assistant container.

I’m using WireGuard app (addon) as the server. And I added a static route on the home assistant host to route traffic to 10.10.10.0/24 via wireguard container.

me@homeassistant ~ $ sudo ip route add 10.10.10.0/24 via 172.30.33.10 

Has anyone run into a similar problem? If so, how did you solve it?

here is snippet of the config I’m using

esphome:
  name: my_device
  friendly_name: My Device

esp32:
  variant: ESP32S3
  board: esp32-s3-devkitc-1
  flash_size: 16MB
  framework:
    type: esp-idf

wifi:
  ssid: ${home_ssid}
  password: !secret wifi_password
  power_save_mode: high
  reboot_timeout: 0s
  ap:
    ssid: MyDeviceFallback
    password: !secret ap_password
  use_psram: true
  on_connect:
    - lambda: |-
        if (wifi::global_wifi_component->wifi_ssid() == "${home_ssid}") {
          id(my_wireguard).disable();
        } else {
          id(my_wireguard).enable();
        }
  on_disconnect:
    - lambda: |-
        id(my_wireguard).disable();

captive_portal:

time:
  - platform: sntp
    id: sntp_time
    timezone: Europe/Atlantis

wireguard:
  id: my_wireguard
  address: 10.10.10.13
  netmask: 255.255.255.0
  private_key: !secret wireguard_private_key
  peer_endpoint: vpn.my.com
  peer_port: 51820
  peer_public_key: !secret wireguard_server_public_key
  peer_allowed_ips:
    - 10.10.10.0/24
  peer_persistent_keepalive: 25s
  reboot_timeout: 0s

ESPHome uses mDNS to resolve what ip the device have I think.
To simplyfy this so it uses static ip addresses instead of dynamic(DHCP) you could type in a static ip in the wifi section something like this:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.1.228
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.1

And think also wiregard may change the dns settings to another dns.

So you have to make up a ip plan.
And change the router settings so some of the networks ip addresses uses dhcp and another uses static ones.

If I don’t getting your questions wrong ?

mDNS is an issue I would revisit once the device is actually accessible from home assistant, here is what I’m seeing now.
From homeassistant container

$ docker exec homeassistant sh -c 'ping -c2 -W2 10.10.10.13'

PING 10.10.10.13 (10.10.10.13): 56 data bytes

--- 10.10.10.13 ping statistics ---
2 packets transmitted, 0 packets received, 100% packet loss

From WireGuard container

$ docker exec addon_a0d7b954_wireguard ping -c2 -W2 10.10.10.13

64 bytes from 10.10.10.13: seq=0 ttl=64 time=459.881 ms
64 bytes from 10.10.10.13: seq=1 ttl=64 time=687.941 ms
0% packet loss

it wouldn’t matter what mDNS resolves, the peer is not accessible

Why not using the HA app on your mobile and connect your mobile via Wireguard to your home-network, that’s the way I stay connected when I’m not at home.

I do, this is about having an ESPhome device still be accessible from HA, basically I want to still be able to control the device from HA.

Solved this one, for future reference, adding the supervisor subnet to peer_allowed_ips in the wireguard component config fixed it

  peer_allowed_ips:
    - 10.10.10.0/24
    - 172.30.32.0/23