ESPhome connected via Wireguard - no API

Hi guys,
I’m having an issue connecting an ESP32 via Wireguard to HA: it seems API connection is for some reason not working. But Logs/Firmware-upgrade work.

My HA runs on IP 192.168.143.5, Sensor is having Wireguard IP 192.168.143.201

The sensor keeps sending data:

[13:12:43][D][sensor:094]: ‘esp32emily1 Uptime’: Sending state 822.21503 s with 0 decimals of accuracy

which is not being received by HA, all HA sensors related to this ESP32 keep showing “unknown”

From my PC I can telnet to API port and ESP32 shows “accepting connection” but I don’t see any of those messages related to HA IP.

It seems HA is not connecting to ESP32 although name resolution in SSH-shell is working properly, Ping also works.

Does anybody have an idea?

Running latest Supervisor and ESPhome.

substitutions:
  name: esp32emily1

logger:

web_server:
  port: 80

api:
  encryption:
    key: "bih...="
  port: 6099

wifi:
  networks:
  - ssid: !secret wifi_em1_ssid
    password: !secret wifi_em1_password
  domain: .fritz.box

wireguard:
  id: wireguardhome
  address: 192.168.143.201
  private_key: sN5...=
  peer_endpoint: jz...
  peer_public_key: 6xO...=

  # Optional netmask (this is the default, no outgoing traffic
  # will pass through the tunnel if omitted)
  netmask: 255.255.254.0

  # Optional endpoint port (WireGuard default if omitted)
  peer_port: 54507

  # Optional pre-shared key (omit if not in use)
  peer_preshared_key: Rzh...=

  # Optional list of ip/mask (any host is allowed if omitted)
  #peer_allowed_ips:
  #  - 192.168.142.0/23

  # Optional keepalive (disabled by default)
  peer_persistent_keepalive: 25s


switch:
  - platform: restart
    name: ${name} Restart
    id: ${name}_restart

binary_sensor:
  - platform: status
    name: $name status
  - platform: wireguard
    enabled:
      name: '$name WireGuard Enabled'
  - platform: wireguard
    status:
      name: '$name WireGuard Status'

sensor:
  - platform: wifi_signal
    name: $name WiFi Signal
    update_interval: 60s
    id: wifisignal
    on_value_range: 
      - above: -0.01
        below: 0.01
        then:
          - switch.turn_on: ${name}_restart
  - platform: uptime
    name: ${name} Uptime 
  - platform: homeassistant
    entity_id: sensor.temp0_temperature
    id: temp1
  - platform: homeassistant
    entity_id: sensor.temp2_temperature
    id: temp2

time:
  - platform: sntp
    id: sntp_time
    timezone: Europe/Berlin
    servers:
     - ptbtime1.ptb.de
     - ptbtime2.ptb.de
     - ptbtime3.ptb.de

I finally found the culprit. When setting up, the ESP was locally connected and added to HA with its local IP address.

Removing ESP from HA (not ESPhome) and manually adding ESP using its FQDN name fixed the issue.

I connected two fritz box routers with their own wireguard solution, but I also have the problem that my esp32 is not detected. I can add it manually with the IP address but then API seems not working. What do you mean with FQDN name, how can I find out what die FQDN name of my btproxy esp32 is?

He means to use the address that Wireguard gave you to connect the device to connect.

wireguard:
  address: 10.5.5.2 <-- This one right here
  private_key: 
  peer_endpoint: 
  peer_public_key: 
  peer_preshared_key: 
  peer_port: 51820 
  peer_allowed_ips:
    - 0.0.0.0/0 
  peer_persistent_keepalive: 25s

Also on the DOCS it says that you have to use this line in wifi: to have the esp device use the WG IP and not the internal IP

wifi:
  use_address: 10.5.5.2