Unexpected messages from ESPHome devices

I have 3 motion sensors running ESPHome.

The problem:
The devices report “OFF” every 15 minutes; all 3 at nearly the same time.

I was using the “OFF” to trigger a “stay on” timer (Node-red), but had to change it or it turned them on every 15 minutes.

This did not happen when I was running my own code on the devices, so I don’t think it’s a hardware problem.

This doesn’t happen when I have the logs displayed for the device.

It seems to be related to this in the logs:
Boot seems successful, resetting boot loop counter.

Why does this happen? Is it Normal?

Looking at the docs, I see on_boot and on_loop optional automations.
Could it be one of these be causing it extra “OFF” message?
Could defining one of them stop the messages?

Thanks,
-Mike

The ESPHome code is pretty much from the example code:

esphome:
  name: livingroom_motion
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "###############"
  password: "###############"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Livingroom Motion"
    password: "###############"

captive_portal:

# Enable logging
logger:

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

ota:
  password: "###############"

binary_sensor:
  - platform: gpio
    pin: D1
    name: "livingroom_motion"
    device_class: motion
    
mqtt:
  broker: homeassistant
  discovery: True
  username: "###############"
  password: "###############"
  
  topic_prefix: "home/1"
  
  birth_message:
    topic: "topic/livingroom_motion/availability"
    payload: "online"
  will_message:
    topic: "topic/livingroom_motion/availability"
    payload: "offline"

I may be wrong but you can’t have api: and MQTT: at the same time.

If you do so, your ESP will reboot every 5 min.

That is totally normal.

So if I remove

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

it will behave like a nice, normal MQTT only device?
Do all the other ESPHome functions (logs especially) not require the API?

Thanks,
-Mike

I would say the nicest part of esphome is it doesn’t rely on mqtt but all (and more) is much easier using the native api.

But if you have time for it and want to use a 20 year old protocol esphome should work perfectly fine as a “normal” mqtt only device.

The logging should be available over mqtt too, other esphome function I can think of would be ota which is not related to api or mqtt but just uses the ota component.

Advantages over MQTT

The ESPHome native API has many advantages over using MQTT for communication with Home Automation software (currently only Home Assistant). But MQTT is a great protocol and will never be removed. Features of native API (vs. MQTT):

  • Much more efficient: ESPHome encodes all messages in a highly optimized format with protocol buffers - for example binary sensor state messages are about 1/10 of the size.
  • One-click configuration: ESPHome just needs one click to set up in Home Assistant - no more messing around with retained MQTT discovery messages and alike.
  • One less single point of failure: In the ESPHome native API each ESP is its own server. With MQTT, when the broker shuts off nothing can communicate anymore.
  • Stability: Since ESPHome has far more control over the protocol than with MQTT, it’s really easy for us to roll out stability improvements.
  • Low Latency: The native API is optimized for very low latency, usually this is only a couple of milliseconds and far less than can be noticed by the eye.

It’s been over a year since your recommendation. I did convert all of the devices running my MQTT code to ESPHome using their API. Sonoff devices that were using Tasmota/mqtt were left alone. I didn’t make any measurements, but the response time for ESPHome motion sensor to node-red to Tasmota device seemed slower than my mqtt code on the sensors.
I recently replaced a Tasomta device with an ESPHome device and the performance was noticeably improved.

-Mike