Device will reboot when mqtt broker can't be reached

Hi,

This is about my first ESPHome project running on mini D1 without HA integration. On this stand alone device I want to display local time and date, some local sensor values and some values read from a mqtt broker.
I noticed when that mqtt broker is down my device won’t boot. It seems a connection to mqtt is mandatory before sntp and local sensor data can be retrieved and displayed.
Is this by design, is it a bug or do I have to modify my yaml?

To keep the question simple I reduced the yaml file to next:

esphome:
  name: mini4

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
#api:
#  password: ""

ota:
  password: ""

wifi:
  ssid: "my_ssid"
  password: "secret"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "mini4 Fallback Hotspot"
    password: "another_secret"

captive_portal:

time:
  - platform: sntp
    id: sntp_time
    timezone: "Europe/Amsterdam"

mqtt:
  broker: 192.168.178.100

web_server:
    port: 80
    ota: true

when 192.168.178.100 is up an running next is logged:

[D][sntp:074]: Synchronized time: 2022-03-13 20:43:26
[D][sntp:074]: Synchronized time: 2022-03-13 20:58:26

when 192.168.178.100 is down next is logged:

[I][mqtt:175]: Connecting to MQTT...
[W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[I][mqtt:175]: Connecting to MQTT...
[W][mqtt:260]: MQTT Disconnected: TCP disconnected.

There is no reboot there.

You are right, recurring attempt to initialize would have been better instead of reboot.
Display will not show the correct time when mqtt broker can’t be reached. I do not understand why mqtt connection seems to be mandatory before ESPHome can retrieve sntp.

If you leave out the mqtt line does sntp work at that point?

I tried once again to double check.

mqtt:
  broker: 192.168.178.99	# which is a fake ip address
[23:12:08][I][wifi:248]: WiFi Connecting to 'my_ssid'...
[23:12:11][I][wifi:505]: WiFi Connected!
[23:12:11][C][wifi:353]:   Local MAC: C4:5B:BE:DD:9F:7E
[23:12:11][C][wifi:354]:   SSID: 'my_ssid'
[23:12:11][C][wifi:355]:   IP Address: 192.168.178.140
[23:12:11][C][wifi:356]:   BSSID: 60:A4:B7:A8:18:AE
[23:12:11][C][wifi:358]:   Hostname: 'mini4'
[23:12:11][C][wifi:360]:   Signal strength: -52 dB
[23:12:11][C][wifi:364]:   Channel: 8
[23:12:11][C][wifi:365]:   Subnet: 255.255.255.0
[23:12:11][C][wifi:366]:   Gateway: 192.168.178.1
[23:12:11][C][wifi:367]:   DNS1: 192.168.178.105
[23:12:11][C][wifi:368]:   DNS2: 192.168.178.1
[23:12:11][D][wifi:514]: Disabling AP...
[23:12:11][C][web_server:085]: Setting up web server...
[23:12:11][C][ota:085]: Over-The-Air Updates:
[23:12:11][C][ota:086]:   Address: mini4.local:8266
[23:12:11][W][ota:094]: Last Boot was an unhandled reset, will proceed to safe mode in 7 restarts
[23:12:11][C][mqtt:030]: Setting up MQTT...
[23:12:11][I][mqtt:175]: Connecting to MQTT...
[23:12:13][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[23:12:16][I][mqtt:175]: Connecting to MQTT...
[23:12:17][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[23:12:21][I][mqtt:175]: Connecting to MQTT...
[23:12:22][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
#mqtt:
#  broker: 192.168.178.100
[23:17:04][I][wifi:248]: WiFi Connecting to 'my_ssid'...
[23:17:07][I][wifi:505]: WiFi Connected!
[23:17:07][C][wifi:353]:   Local MAC: C4:5B:BE:DD:9F:7E
[23:17:07][C][wifi:354]:   SSID: 'my_ssid'
[23:17:07][C][wifi:355]:   IP Address: 192.168.178.140
[23:17:07][C][wifi:356]:   BSSID: 60:A4:B7:A8:18:AE
[23:17:07][C][wifi:358]:   Hostname: 'mini4'
[23:17:07][C][wifi:360]:   Signal strength: -50 dB
[23:17:07][C][wifi:364]:   Channel: 8
[23:17:07][C][wifi:365]:   Subnet: 255.255.255.0
[23:17:07][C][wifi:366]:   Gateway: 192.168.178.1
[23:17:07][C][wifi:367]:   DNS1: 192.168.178.105
[23:17:07][C][wifi:368]:   DNS2: 192.168.178.1
[23:17:07][D][wifi:514]: Disabling AP...
[23:17:07][C][web_server:085]: Setting up web server...
[23:17:07][C][ota:085]: Over-The-Air Updates:
[23:17:07][C][ota:086]:   Address: mini4.local:8266
[23:17:07][W][ota:094]: Last Boot was an unhandled reset, will proceed to safe mode in 5 restarts
[23:17:07][C][sntp:025]: Setting up SNTP...
[23:17:07][I][app:062]: setup() finished successfully!
[23:17:07][I][app:102]: ESPHome version 2022.2.5 compiled on Mar 13 2022, 23:16:01
[23:17:07][C][wifi:491]: WiFi:
[23:17:07][C][wifi:353]:   Local MAC: C4:5B:BE:DD:9F:7E
[23:17:07][C][wifi:354]:   SSID: 'my_ssid'
[23:17:07][C][wifi:355]:   IP Address: 192.168.178.140
[23:17:07][C][wifi:356]:   BSSID: 60:A4:B7:A8:18:AE
[23:17:07][C][wifi:358]:   Hostname: 'mini4'
[23:17:07][C][wifi:360]:   Signal strength: -49 dB
[23:17:07][C][wifi:364]:   Channel: 8
[23:17:07][C][wifi:365]:   Subnet: 255.255.255.0
[23:17:08][C][wifi:366]:   Gateway: 192.168.178.1
[23:17:08][C][wifi:367]:   DNS1: 192.168.178.105
[23:17:08][C][wifi:368]:   DNS2: 192.168.178.1
[23:17:08][C][logger:233]: Logger:
[23:17:08][C][logger:234]:   Level: DEBUG
[23:17:08][C][logger:235]:   Log Baud Rate: 115200
[23:17:08][C][logger:236]:   Hardware UART: UART0
[23:17:08][C][captive_portal:144]: Captive Portal:
[23:17:08][C][web_server:179]: Web Server:
[23:17:08][C][web_server:180]:   Address: mini4.local:80
[23:17:08][C][mdns:084]: mDNS:
[23:17:08][C][mdns:085]:   Hostname: mini4
[23:17:08][D][sntp:074]: Synchronized time: 2022-03-13 23:17:08
[23:17:08][C][ota:085]: Over-The-Air Updates:
[23:17:08][C][ota:086]:   Address: mini4.local:8266
[23:17:08][W][ota:094]: Last Boot was an unhandled reset, will proceed to safe mode in 5 restarts
[23:17:08][C][sntp:050]: SNTP Time:
[23:17:08][C][sntp:051]:   Server 1: '0.pool.ntp.org'
[23:17:08][C][sntp:052]:   Server 2: '1.pool.ntp.org'
[23:17:08][C][sntp:053]:   Server 3: '2.pool.ntp.org'
[23:17:08][C][sntp:054]:   Timezone: 'CET-1CEST,M3.5.0,M10.5.0/3'
[23:21:58][I][ota:105]: Boot seems successful, resetting boot loop counter.
[23:24:47][D][sntp:074]: Synchronized time: 2022-03-13 23:24:48

with the correct ip address:

mqtt:
  broker: 192.168.178.100
[23:30:59][I][wifi:248]: WiFi Connecting to 'my_ssid'...
[23:31:03][I][wifi:505]: WiFi Connected!
[23:31:03][C][wifi:353]:   Local MAC: C4:5B:BE:DD:9F:7E
[23:31:03][C][wifi:354]:   SSID: 'my_ssid'
[23:31:03][C][wifi:355]:   IP Address: 192.168.178.140
[23:31:03][C][wifi:356]:   BSSID: 60:A4:B7:A8:18:AE
[23:31:03][C][wifi:358]:   Hostname: 'mini4'
[23:31:03][C][wifi:360]:   Signal strength: -54 dB
[23:31:03][C][wifi:364]:   Channel: 8
[23:31:03][C][wifi:365]:   Subnet: 255.255.255.0
[23:31:03][C][wifi:366]:   Gateway: 192.168.178.1
[23:31:03][C][wifi:367]:   DNS1: 192.168.178.105
[23:31:03][C][wifi:368]:   DNS2: 192.168.178.1
[23:31:03][D][wifi:514]: Disabling AP...
[23:31:03][C][web_server:085]: Setting up web server...
[23:31:03][C][ota:085]: Over-The-Air Updates:
[23:31:03][C][ota:086]:   Address: mini4.local:8266
[23:31:03][C][mqtt:030]: Setting up MQTT...
[23:31:03][I][mqtt:175]: Connecting to MQTT...
[23:31:03][I][mqtt:215]: MQTT Connected!
[23:31:03][C][sntp:025]: Setting up SNTP...
[23:31:03][I][app:062]: setup() finished successfully!
[23:31:03][I][app:102]: ESPHome version 2022.2.5 compiled on Mar 13 2022, 23:29:49
[23:31:03][C][wifi:491]: WiFi:
[23:31:03][C][wifi:353]:   Local MAC: C4:5B:BE:DD:9F:7E
[23:31:03][C][wifi:354]:   SSID: 'my_ssid'
[23:31:03][C][wifi:355]:   IP Address: 192.168.178.140
[23:31:03][C][wifi:356]:   BSSID: 60:A4:B7:A8:18:AE
[23:31:03][C][wifi:358]:   Hostname: 'mini4'
[23:31:03][C][wifi:360]:   Signal strength: -50 dB
[23:31:03][C][wifi:364]:   Channel: 8
[23:31:03][C][wifi:365]:   Subnet: 255.255.255.0
[23:31:03][C][wifi:366]:   Gateway: 192.168.178.1
[23:31:03][C][wifi:367]:   DNS1: 192.168.178.105
[23:31:03][C][wifi:368]:   DNS2: 192.168.178.1
[23:31:03][C][logger:233]: Logger:
[23:31:03][C][logger:234]:   Level: DEBUG
[23:31:03][C][logger:235]:   Log Baud Rate: 115200
[23:31:03][C][logger:236]:   Hardware UART: UART0
[23:31:03][C][captive_portal:144]: Captive Portal:
[23:31:03][C][web_server:179]: Web Server:
[23:31:03][C][web_server:180]:   Address: mini4.local:80
[23:31:03][C][mdns:084]: mDNS:
[23:31:03][C][mdns:085]:   Hostname: mini4
[23:31:03][C][ota:085]: Over-The-Air Updates:
[23:31:03][C][ota:086]:   Address: mini4.local:8266
[23:31:03][C][mqtt:064]: MQTT:
[23:31:03][C][mqtt:065]:   Server Address: 192.168.178.100:1883 (192.168.178.100)
[23:31:03][C][mqtt:067]:   Username: ''
[23:31:03][C][mqtt:068]:   Client ID: 'mini4-c45bbedd9f7e'
[23:31:03][C][mqtt:070]:   Discovery prefix: 'homeassistant'
[23:31:03][C][mqtt:071]:   Discovery retain: YES
[23:31:03][C][mqtt:073]:   Topic Prefix: 'mini4'
[23:31:03][C][mqtt:075]:   Log Topic: 'mini4/debug'
[23:31:03][C][mqtt:078]:   Availability: 'mini4/status'
[23:31:03][C][sntp:050]: SNTP Time:
[23:31:03][C][sntp:051]:   Server 1: '0.pool.ntp.org'
[23:31:03][C][sntp:052]:   Server 2: '1.pool.ntp.org'
[23:31:03][C][sntp:053]:   Server 3: '2.pool.ntp.org'
[23:31:03][C][sntp:054]:   Timezone: 'CET-1CEST,M3.5.0,M10.5.0/3'
[23:31:33][D][sntp:074]: Synchronized time: 2022-03-13 23:31:34

Does adding a reboot_timout: of 0 work?

no, same result
I tried adding reboot_timeout: 0s to wifi: and mqtt:

And how many times does it retry to connect to mqtt? How long have you waited?

I’m having the same issue. My smart plug is dealing with connection problems and reboots.

I have a configuration file compiled with ESPHome 2021.12.3 and no problem here. I have the same configuration file compiled with ESPHome 2022.2.3 and it has the problem. When I remove MQTT in the configuration file, the plug remains stable.

I also tried with latest version, ESPHome 2022.3.2, here the problem still exists.

Hi, I have the same Problem …
in my log it seems to trying connect to mqtt for 4 times and afterward sometimes it is rebooting without any other reasons…

09:31:00 [I] [mqtt:242]

Connecting to MQTT…

09:31:00 [W] [mqtt:331]

MQTT Disconnected: TCP disconnected.

09:31:05 [I] [mqtt:242]

Connecting to MQTT…

09:31:05 [W] [mqtt:331]

MQTT Disconnected: TCP disconnected.

09:31:06 [D] [text_sensor:064]

‘Uptime’: Sending state ‘0d 0h 14m 45s’

09:31:10 [I] [mqtt:242]

Connecting to MQTT…

09:31:10 [W] [mqtt:331]

MQTT Disconnected: TCP disconnected.

09:31:15 [I] [mqtt:242]

Connecting to MQTT…

09:31:15 [W] [mqtt:331]

MQTT Disconnected: TCP disconnected.

09:31:18 [D] [dallas.sensor:143]

‘T01 FB Heizung VL’: Got Temperature=28.1°C

09:31:18 [D] [sensor:093]

‘T01 FB Heizung VL’: Sending state 28.06250 °C with 2 decimals of accuracy

09:31:18 [D] [dallas.sensor:143]

‘T02 FB Heizung RL’: Got Temperature=28.2°C

09:31:18 [D] [sensor:093]

‘T02 FB Heizung RL’: Sending state 28.18750 °C with 2 decimals of accuracy

09:31:18 [D] [dallas.sensor:143]

‘T03 GasTherme HK1 VL’: Got Temperature=29.0°C

09:31:18 [D] [sensor:093]

‘T03 GasTherme HK1 VL’: Sending state 29.00000 °C with 2 decimals of accuracy

09:31:18 [D] [dallas.sensor:143]

‘T11 Heizraum Aussen’: Got Temperature=25.1°C

09:31:18 [D] [sensor:093]

‘T11 Heizraum Aussen’: Sending state 25.12500 °C with 2 decimals of accuracy

09:31:18 [D] [dallas.sensor:143]

‘T10 WW Zirkulation’: Got Temperature=43.5°C

09:31:18 [D] [sensor:093]

‘T10 WW Zirkulation’: Sending state 43.50000 °C with 2 decimals of accuracy

09:31:18 [D] [dallas.sensor:143]

‘T08 Heizraum Innen’: Got Temperature=28.6°C

09:31:18 [D] [sensor:093]

‘T08 Heizraum Innen’: Sending state 28.56250 °C with 2 decimals of accuracy

09:31:18 [D] [dallas.sensor:143]

‘T09 Stiegenhaus KG’: Got Temperature=26.3°C

09:31:18 [D] [sensor:093]

‘T09 Stiegenhaus KG’: Sending state 26.31250 °C with 2 decimals of accuracy

09:31:18 [D] [dallas.sensor:143]

‘T07 Boiler 800’: Got Temperature=72.9°C

09:31:18 [D] [sensor:093]

‘T07 Boiler 800’: Sending state 72.93750 °C with 2 decimals of accuracy

09:31:18 [D] [dallas.sensor:143]

‘T04 GasTherme HK1 RL’: Got Temperature=28.4°C

09:31:18 [D] [sensor:093]

‘T04 GasTherme HK1 RL’: Sending state 28.37500 °C with 2 decimals of accuracy

09:31:18 [D] [dallas.sensor:143]

‘T06 Gastherme HK2 RL’: Got Temperature=33.9°C

09:31:18 [D] [sensor:093]

‘T06 Gastherme HK2 RL’: Sending state 33.93750 °C with 2 decimals of accuracy

09:31:18 [D] [dallas.sensor:143]

‘T05 Gastherme HK2 VL’: Got Temperature=29.4°C

09:31:18 [D] [sensor:093]

‘T05 Gastherme HK2 VL’: Sending state 29.43750 °C with 2 decimals of accuracy

09:31:20 [I] [mqtt:242]

Connecting to MQTT…

09:31:20 [W] [mqtt:331]

MQTT Disconnected: TCP disconnected.

09:31:25 [I] [mqtt:242]

Connecting to MQTT…

09:31:25 [W] [mqtt:331]

MQTT Disconnected: TCP disconnected.

09:31:29 [D] [sensor:093]

‘Uptime sec’: Sending state 945.78302 s with 0 decimals of accuracy

09:31:30 [I] [mqtt:242]

Connecting to MQTT…

09:31:30 [W] [mqtt:331]

MQTT Disconnected: TCP disconnected.

09:31:35 [E] [mqtt:366]

Can’t connect to MQTT… Restarting…

09:31:35 [I] [app:127]

Forcing a reboot…

Very strange. Looking at the code, this definitely shouldn’t be possible if you set reboot_timeout to zero in mqtt:.

Did you do that? If yes, how long after a reboot does this happen?