ESPHome state changes every 2 minutes

Home Assistant: 2020.12.7
ESPHome: v.1.15.3
Sensor: NodeMcu (with MQTT)

Since a few days I recognized some strange flickering in my hassio lovelace UI.
See Video: Link (right side, “Corridor” panel)

This flickering occurs every ~2minutes.
Nearly at the same time I can see the following MQTT messages. State switch from online to offline for a frew milliseconds every ~2minutes.

This happens for all my ESPHome sensors.
Here is a sample configuration of one of my sensors.

Is this an expected behavior? Or do I have some configuration errors?

YAML:

esphome:
  name: ff_corridor_msens_01
  platform: ESP8266
  board: nodemcuv2

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Ff Corridor Msens 01"
    password: !secret wifi_ap_password

captive_portal:

# Enable logging
logger:
  level: INFO

# Enable Home Assistant API
ota:
  password: !secret ota_password
  
mqtt:
  broker: !secret mqtt_broker_ip
  username: !secret mqtt_username
  password: !secret mqtt_password

output:
  - platform: gpio
    pin:
      number: D0
      inverted: False
    id: "ff_corridor_alarm"
  - platform: gpio
    pin:
      number: D6
      inverted: True
    id: "ff_corridor_lamp"
    
i2c:
  sda: D2
  scl: D1
  scan: True
  id: bus_a

switch:
  - name: "FF Corridor Alarm"
    platform: output
    output: ff_corridor_alarm

sensor:
  - platform: bh1750
    name: "BH1750 Illuminance"
    address: 0x23
    measurement_time: 69
    update_interval: 60s
    
  - platform: bme280
    temperature:
      name: "BME280 Temperature"
      oversampling: 16x
    pressure:
      name: "BME280 Pressure"
    humidity:
      name: "BME280 Humidity"
    address: 0x76
    update_interval: 60s

binary_sensor:
  - platform: gpio
    pin:
      number: D5
      inverted: True
      mode: INPUT_PULLUP
    name: "PIR Sensor"
    device_class: motion
    
light:
  - platform: fastled_clockless
    chipset: WS2812B
    pin: D3
    num_leds: 2
    rgb_order: GRB
    name: "FastLED WS2811 Light"
  - platform: binary
    name: "Lamp"
    output: ff_corridor_lamp

Check the following logs for errors:

ESPHome
HA system
Mqtt

Hi Tom,

good idea, thank you. As far as I can say the ESPHome and HA System logs looking ok for me.
In MQTT logs I found several timeout errors. This is confusing for me, because the signal strength from all of my sensors are good. (also ICMP-Pings are ok ~4ms)

Timeout in MQTT logs occurs also if I ping the sensor. The ping was still good at about ~4ms without any interruptions.

Im using AddOn MQTT Server bundled Hivemq`s as mqtt server.

What can I do to reduce these timeout problems? Any ideas?

MQTT Logs:

1608201220: New connection from <IP>.165 on port 1883.
1608201220: New client connected from <IP>.165 as DVES_58F4C1 (p2, c1, k30, u'<user>').
1608201221: New connection from <IP>.161 on port 1883.
1608201221: New client connected from <IP>.161 as ff_corridor_msens_01-mac(p2, c1, k15, u'<user>').
1608201221: New connection from <IP>.157 on port 1883.
1608201221: New client connected from <IP>.157 as ff_kitchen_relay_8ch_01-mac(p2, c1, k15, u'<user>').
1608201262: Saving in-memory database to /data/mosquitto/mosquitto.db.
1608201275: Client ff_corridor_msens_01-mac has exceeded timeout, disconnecting.
1608201275: New connection from <IP>.161 on port 1883.
1608201275: New client connected from <IP>.161 as ff_corridor_msens_01-mac (p2, c1, k15, u'<user>').
1608201276: Client ff_kitchen_relay_8ch_01-mac has exceeded timeout, disconnecting.
1608201276: New connection from <IP>.157 on port 1883.
1608201276: New client connected from <IP>.157 as ff_kitchen_relay_8ch_01-mac(p2, c1, k15, u'<user>').
1608201296: Client DVES_58F4C1 has exceeded timeout, disconnecting.
1608201296: New connection from <IP>.165 on port 1883.
1608201296: New client connected from <IP>.165 as DVES_58F4C1 (p2, c1, k30, u'<user>').

thanks for pushing me in right direction.
I think that I could solve my issue.

I did the following:

  1. The mentioned MQTT AddOn from my previous post seems to be deprecated. I uninstalled it and using now “Mosquitto broker” v.5.1 from official home assistant AddOn store.
  2. I had a fallback network configuration. (LAN+WIFI)
    I removed the WIFI connection and will handle the fallback outside of home assistant. (LoadBalancer, etc…)

One downside: I did both changes at once. So I am not sure which step has solved the problem :wink:
Thanks for your help!