Sonoff s31 mDNS not working when plugged into AC

i have an sonoff s31 switch that worked wonderfully until it didn’t this past week or so. i noticed that it disappeared off esphome and my apple home bridge via homeassistant. so i try flashing it again using usb → uart and after disconnecting and connecting 5v power it seems to work just fine, i can ping its mDNS address and control it via HA. but when i put it all back together and plug it into the wall, it stops responding to mDNS and i can’t control it via HA. it is connected to wifi because i see it in unifi console and i can ping the ip address directly.

i also bought a brand new one off amazon and same behavior.

any ideas?

    esphome:
        name: laundryroom-light-switch
        friendly_name: laundryroom-light-switch

    esp8266:
        board: esp01_1m

    # Enable logging
    logger:

    # Enable Home Assistant API
    api:
        encryption:
            key: "f"

    ota:
        password: "f"

    wifi:
        ssid: !secret wifi_ssid
        password: !secret wifi_password

        # Enable fallback hotspot (captive portal) in case wifi connection fails
        ap:
            ssid: "Laundryroom-Light-Switch"
            password: "f"

    captive_portal:

    uart:
        rx_pin: RX
        baud_rate: 4800

    binary_sensor:
        - platform: gpio
            pin:
                number: GPIO0
                mode: INPUT_PULLUP
                inverted: True
            name: "Sonoff S31 Button"
            on_press:
                - switch.toggle: relay
        - platform: status
            name: "Sonoff S31 Status"

    sensor:
        - platform: wifi_signal
            name: "Sonoff S31 WiFi Signal"
            update_interval: 60s
        - platform: cse7766
            current:
                name: "Sonoff S31 Current"
                accuracy_decimals: 1
            voltage:
                name: "Sonoff S31 Voltage"
                accuracy_decimals: 1
            power:
                name: "Sonoff S31 Power"
                accuracy_decimals: 1
                id: my_power

    switch:
        - platform: gpio
            name: "Sonoff S31 Relay"
            pin: GPIO12
            id: relay
            restore_mode: ALWAYS_ON

    time:
        - platform: sntp
            id: my_time

    status_led:
        pin:
            number: GPIO13
            inverted: True

Can you ping with the (non mdns) hostname?

Do you use any vlans by chance? I think this unifi hardware blocks mdns broadcast across vlans…

You can also use esphome without mdns (see esphome faqs)

Latest firmware update is breaking my Sonoff S31s.
Sometimes they will time out connecting to wifi and I have to connect to them to set wifi. Even when they do connect they don’t work. When I look for the logs at best it will say “Successfully connected”
but then
“WARNING Can’t connect to ESPHome API for sonoff-s31-02 @ 192.168.1.2: Timeout waiting for HelloResponse, ConnectResponse after 30.0s (TimeoutAPIError)
INFO Trying to connect to sonoff-s31-02 @ 192.168.1.2 in the background
WARNING sonoff-s31-02 @ 192.168.1.2: Connection error occurred: sonoff-s31-02 @ 192.168.1.2: Connection lost”

I had an old firmware from November for a different S31 and was able to flash that to the problem S31 and it works fine.