Wemos D1 mini becomes unavailable

I’ve got a Wemos D1 Mini running ESPHome that I use to monitor the temperature in my server cabinet via a DHT22 and then set the PWM fan speed for 2 x 80mm fans.

The problem I’m facing is that the entities keep becoming unavailable in Home Assistant - see logs from the last 4 hours below.

server-rack-fans Server Rack Intake Fan turned on
07:46:41 - 1 minute ago
server-rack-fans Server Rack Exhaust Fan turned on
07:46:41 - 1 minute ago
server-rack-fans Server Rack Intake Fan became unavailable
07:46:38 - 2 minutes ago
server-rack-fans Server Rack Exhaust Fan became unavailable
07:46:38 - 2 minutes ago
server-rack-fans Server Rack Intake Fan turned on
07:45:36 - 3 minutes ago
server-rack-fans Server Rack Exhaust Fan turned on
07:45:36 - 3 minutes ago
server-rack-fans Server Rack Intake Fan became unavailable
07:45:33 - 3 minutes ago
server-rack-fans Server Rack Exhaust Fan became unavailable
07:45:33 - 3 minutes ago
server-rack-fans Server Rack Intake Fan turned on
06:32:39 - 1 hour ago
server-rack-fans Server Rack Exhaust Fan turned on
06:32:38 - 1 hour ago
server-rack-fans Server Rack Intake Fan became unavailable
06:32:35 - 1 hour ago
server-rack-fans Server Rack Exhaust Fan became unavailable
06:32:35 - 1 hour ago
server-rack-fans Server Rack Intake Fan turned on
05:20:52 - 2 hours ago
server-rack-fans Server Rack Exhaust Fan turned on
05:20:52 - 2 hours ago
server-rack-fans Server Rack Intake Fan became unavailable
05:20:49 - 2 hours ago
server-rack-fans Server Rack Exhaust Fan became unavailable
05:20:49 - 2 hours ago
server-rack-fans Server Rack Intake Fan turned on
05:01:15 - 3 hours ago
server-rack-fans Server Rack Exhaust Fan turned on
05:01:15 - 3 hours ago
server-rack-fans Server Rack Intake Fan became unavailable
05:01:12 - 3 hours ago
server-rack-fans Server Rack Exhaust Fan became unavailable
05:01:12 - 3 hours ago
server-rack-fans Server Rack Intake Fan turned on
04:18:43 - 3 hours ago
server-rack-fans Server Rack Exhaust Fan turned on
04:18:43 - 3 hours ago
server-rack-fans Server Rack Intake Fan became unavailable
04:18:39 - 3 hours ago
server-rack-fans Server Rack Exhaust Fan became unavailable
04:18:39 - 3 hours ago
server-rack-fans Server Rack Intake Fan turned on
04:09:51 - 4 hours ago
server-rack-fans Server Rack Exhaust Fan turned on
04:09:51 - 4 hours ago
server-rack-fans Server Rack Intake Fan became unavailable
04:09:47 - 4 hours ago
server-rack-fans Server Rack Exhaust Fan became unavailable
04:09:47 - 4 hours ago
server-rack-fans Server Rack Intake Fan turned on
03:39:47 - 4 hours ago

My initial thought is that it is a WiFi related issue but HA reports the signal strength as -55db which seems fine. I have locked it to the nearest Unifi AP and set a static IP on the device. FWIW, unifi says the WiFi experience is excellent for the device with no drops.

Signal strength: -55 dB

image

Here’s the esphome.yaml for the device in question.

esphome:
  name: server-rack-fans
  friendly_name: server-rack-fans

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: [key]

ota:
  - platform: esphome
    password:  [password]

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

  manual_ip:
    static_ip: 192.168.10.199
    gateway: 192.168.10.1
    dns1: 192.168.10.2
    subnet: 255.255.255.0
    
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Server-Rack-Fans"
    password: "HGDx7P2Yf6hb"

captive_portal:

output:
  - platform: esp8266_pwm
    pin: D5
    frequency: 20000 Hz
    id: exhaust_fan_pwm  
  - platform: esp8266_pwm
    pin: D7
    frequency: 20000 Hz
    id: intake_fan_pwm

fan:
  - platform: speed
    id: exhaust_fan
    output: exhaust_fan_pwm
    name: "Server Rack Exhaust Fan"
    speed_count: 100
    restore_mode: ALWAYS_ON
  - platform: speed
    id: intake_fan
    output: intake_fan_pwm
    name: "Server Rack Intake Fan"
    speed_count: 100
    restore_mode: ALWAYS_ON

sensor:
  - platform: dht
    pin: D1
    model: DHT22
    humidity:
      name: "Server Rack Humidity"
    temperature:
      name: "Server Rack Temperature"
      on_value_range:
      - below: 26.0
        then:
          - fan.turn_off: intake_fan
          - fan.turn_off: exhaust_fan             
      - above: 26.0
        below: 31.0
        then:
          - fan.turn_on: 
              id: intake_fan
              speed: 55
          - fan.turn_on: 
              id: exhaust_fan
              speed: 45
      - above: 31.0
        then:
          - fan.turn_on: 
              id: intake_fan
              speed: 100
          - fan.turn_on: 
              id: exhaust_fan
              speed: 100   

  - platform: pulse_counter
    pin:
      number: D6
      mode:
        input: true
        pullup: true
    name: "Server Rack Exhaust Fan Speed"
    id: exhaust_fan_pulse
    unit_of_measurement: 'RPM'
    accuracy_decimals: 0
    filters:
      - multiply: 0.5
    count_mode:
      rising_edge: INCREMENT
      falling_edge: DISABLE

  - platform: pulse_counter
    pin:
      number: D2
      mode:
        input: true
        pullup: true
    name: "Server Rack Intake Fan Speed"
    id: intake_fan_pulse
    unit_of_measurement: 'RPM'
    accuracy_decimals: 0
    filters:
      - multiply: 0.5
    count_mode:
      rising_edge: INCREMENT
      falling_edge: DISABLE      

I have tried two Wemos D1 mini’s and now it is running on a Wemos D1 mini pro but the issue persists. Any help/feedback would be greatly appreciated.

You should have a look at your esphome log when esp becomes unavailable

Hey @Karosm

These logs?

One of possible options is constant wifi channel changing on router (if you have channel set to auto). I’ve had this experience, and it took quite a while to figure it out why my esp modules randomly drop connection. It turned out that when router changes wifi channel some of them (totally random one or two out of 40+ esp’s) decides NOT to reconnect. Then it takes 15 minutes (default esphome setting) for esp module to restart and after that it was ok again. Setting wifi channel fixed to a least congested channel solved all my issues.

The problem can be if you live in highly populated area, where there are “tons” of wifi signals…

Thanks @Protoncek. I have set a static channel (channel 3) on the access point that this device is connected to. Fortunately our RF environment is pretty clear and we don’t have too many devices connected to this AP.

@Karosm, I managed to catch the logs when this happened. It looks like “Connection error occurred: [Errno 104] Connection reset by peer” is the cause of this.

server-rack-fans Server Rack Intake Fan turned on
09:17:03 - Now
server-rack-fans Server Rack Exhaust Fan turned on
09:17:03 - Now
server-rack-fans Server Rack Intake Fan became unavailable
09:16:59 - 4 seconds ago
server-rack-fans Server Rack Exhaust Fan became unavailable
09:16:59 - 4 seconds ago
[09:14:53][D][sensor:093]: 'Server Rack Intake Fan Speed': Sending state 1852.12354 RPM with 0 decimals of accuracy
[09:14:55][D][dht:049]: Got Temperature=28.0°C Humidity=44.2%
[09:14:55][D][sensor:093]: 'Server Rack Temperature': Sending state 28.00000 °C with 1 decimals of accuracy
[09:14:55][D][sensor:093]: 'Server Rack Humidity': Sending state 44.20000 % with 0 decimals of accuracy
WARNING server-rack-fans @ 192.168.10.199: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for server-rack-fans @ 192.168.10.199
WARNING Disconnected from API
INFO Successfully connected to server-rack-fans @ 192.168.10.199 in 0.039s
INFO Successful handshake with server-rack-fans @ 192.168.10.199 in 3.879s
[09:17:08][D][pulse_counter:186]: 'Server Rack Exhaust Fan Speed': Retrieved counter: 3090.90 pulses/min
[09:17:09][D][sensor:093]: 'Server Rack Exhaust Fan Speed': Sending state 1545.44849 RPM with 0 decimals of accuracy
[09:17:25][D][pulse_counter:186]: 'Server Rack Intake Fan Speed': Retrieved counter: 3706.00 pulses/min

It looks like this happened to someone else and it was a network issue. I really don’t think it is a network issue for me because I have 9 other ESPHome devices that are all working fine and even though my DHCP lease is 24 hours, this device has a static IP so it shouldn’t be affected by the DHCP lease time.

This reddit post hints that this could be a memory issue on the ESP so I have updated the yaml to use an esp01_1m so that we only use 1mb of memory.

Lets see is this makes any difference.

Nope, still getting this error with esp01_1m set

WARNING server-rack-fans @ 192.168.10.199: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for server-rack-fans @ 192.168.10.199
WARNING Disconnected from API
INFO Successfully connected to server-rack-fans @ 192.168.10.199 in 0.105s
INFO Successful handshake with server-rack-fans @ 192.168.10.199 in 3.764s

I don’t see anything strange on your yaml.

What we have left is connected hardware and power supply.
Have you measured voltage of your Esp? Tried with another power supply?
Tried with fans disconnected?

The ESP is powered by one of these power HAT’s. I’ve just moved it over to a different, bigger 12v power supply so lets see if that makes any difference.

If not, I’ll go back to the original PSU and disconnect the fans.

Thanks for the help with this @Karosm

I would try with (Samsung) phone charger. Why you need that FEIYANG ?
Are the fans powered separately?