ESPHome issue with a repeater (NAT)

no luck with a new sensor. Same effect: In the log everithing ok but the state are offline

i just juse “api:” here the full code:

esphome:
  name: esp_windsensor
  platform: ESP8266
  board: d1_mini_lite

wifi:
  ssid: "ESP_Sensor"
  password: "xyxyxyxy"
  manual_ip:
    static_ip: 192.168.178.161
    gateway: 192.168.178.161
    subnet: 255.255.255.0

  ap:
    ssid: "POE_Fallback_Hotspot_Windsensor"
    password: "BMbDBwnS72i9"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

sensor:
  - platform: adc
    pin: A0
    name: "Windsensor Spannung"
    update_interval: 10s
    filters:
      - multiply: 3.3

  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 20s

Can you ping it?

Frome the primary side (router, homeassistant,…) to the repeater, seems ok(on picture, upper request).
From the secoundary side (other side of NAT) to the esp device seems also ok (on the picture the secend request - I change with the notebook to the “secoundary side wlan” for the secound request)

No one is interested in your screenshots of text.

Copy and paste was developed last century, please learn to use it.

ping is actually totally useless if you want to get the api to work…

Two different scenarios which could work for you are:

  1. Try your luck with mqtt. As there is no mDNS involved directly it could work out with the configuration you have right now

  2. Give esphome with esp-now a shot

1 Like

Thank you for taking me back to the present. :rofl:
Both ping requests were successful. I wonder which track you want to lead me on.

Thank you for your help. I think I choose the MQTT adventure.

ping is always the first step on testing networking issues.

It really doesn’t matter because mDNS ≠ DNS. The later could be used to ping a hostname - or you ping the IP directly like @Yves_IF did. In anyway it doesn’t help at all for this particular issue @nickrout

It does prove that the device is reachable over the network. Then the next step is to work out why your particular service/or application is not responding as you would expect.

2 Likes

multicastDNS/bonjour can’t cross a NAT. So no way for api/ota (what @Yves_IF was trying).
So it does what is expected → it doesn’t work

Anyway alternative solutions like trying mqtt or esp-now are already on the table…

Read the first reply.

1 Like

I read the second…

1 Like

Just to add a solution that worked for me in order to put a router between HA and my ESP. Here is the config of the ESPHome that is behind the router:

wifi:
  ssid: xxxx
  password: yyyyy
  fast_connect: true
  use_address: 192.168.0.144 #this is the WAN IP of the router.    
  
  manual_ip:
    static_ip: 192.168.4.144
    gateway: 192.168.4.1
    subnet: 255.255.255.0

On the router, you need to configure port forwarding for 6053 and 8266 ports.

When integrating the ESPHome device in HA, I use the WAN IP of the router.

I am using this w/o problems for 2 years now.

Hope this helps.

2 Likes

Thanks, this looks like a solution. 2 questions:

  1. WAN IP of the router? Is this the gateway i.e.192.168.0.1 (for instance) or the ISP assigned external WAN IP i.e. 156.155.x.x
  2. You have used 192.168.0.144 as the WAN IP and 192.168.4.144 as the static_ip. Is the .144 significant in any way or just random?

Thanks in advance

Edit: finally got it working. Steps below:

  1. Use this for the ESP32 router (GitHub - dchristl/esp32_nat_router_extended: a simple ESP32 NAT Router with some additional features). This allows for port mapping on the ESP32 router itself. Install as per normal.
  2. Normal steps on setting up the AP settings and the STA settings
  3. I set up a static ip for the ESP32 router in my home router - in my case I set it to 192.168.0.202
  4. On the ESP32 router page (192.168.4.1) go to “Portmap configuration” and set up 2 portmaps:
    • One for port 6053 to (in my case) 192.168.4.202 (the .202 does not have to be the same but it does
      help mapping the .0.202 on the main vlan to the .4.292 on the .4 vlan
    • One for port 8266 to (in my case) 192.168.4.202
  5. In the ESP device (that is sitting behind the ESP32 router) use the settings as above. In my case this would be:
wifi:
  ssid: xxxx #SSID of the ESP32 router
  password: yyyy #pw of the SSID of the ESP32 router
  fast_connect: true
  use_address: 192.168.0.202 #this is the WAN IP of the ESP32 router on the main vlan.    

  manual_ip:
    # Set this to the IP of the ESP device that is being connected
    static_ip: 192.168.4.202
    # Set this to the IP address of the router. Often ends with .1
    gateway: 192.168.4.1
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0
  1. If the ESP32 device is present in the ESPHome integration in HA then delete the device and re-add the device (“+Add Device” button in the bottom right hand corner) and use 192.168.0.202 as the IP of the device to be added. This should now show as available in the ESPHome integration with data for the sensors

This set up finally worked for me, the ESP32 device is visible. Thank for the advice in the thread

Glad it worked for you. Was trying to remember all the details as I did this long time ago and since then it was just the update to the ESPHome version that I needed to do.

Hi,

Thanks for the instructions. I works.
The log works and shows everything, but the entities are unavailable in HA.

As I wrote above I use this method to connct to ESP behind router for 3 years now.
However, last week I noticed the HA ESP integration going unavailable and staying like that indefinitely. Deleting the integration and creating it again made the integration working again. Lately I observed that this is happening after power off/on of the ESP.

So today I decided to investigate what is going on. Seems with the latest HA even though the setting of ESP integration is based on the “use_address” field (in my case 192.168.0.144), HA zeroconf requests and ESP answers mDNS with the static_ip (192.168.4.144). Subsequently the HA will use this static_ip which will obviously not connect. See wireshark log below.

screenshot

A simple solution is to disable the mDNS in ESP, just add the following in the project yaml:

mdns:
  disabled: true

Hope this helps.

use_address is only supposed to be used on a one off basis when changing the IP of the esp device.