Having both the Home Assistant API and MQTT configured

Is it a problem (read: not advised) to have both the HA API and MQTT options enabled for a device?

Config:

api:
  password: !secret home_assistant_api_password

mqtt:
  broker: !secret mqtt_broker
  discovery: True

I see messages like this in my HA log:

2020-07-29 17:19:54 ERROR (MainThread) [homeassistant.components.binary_sensor] Entity id already exists - ignoring: binary_sensor.rhs_garage_door_status_2. Platform esphome does not generate unique IDs

If it is indeed ok to have both configured, how do I control the entity IDs? I couldn’t find anything on this in the ESPHome docs (as excellent as it is, which makes me think this should rather not be done).

In case you ask why I’d want this: It was purely from a first device I built and I experimented with the two options. I know that the API is considered more efficient, but where I use these devices in HA I tend to use MQTT.

Using both has its issues. Better to use one or the other.

Warning

When enabling MQTT and you do not use the “native API” for Home Assistant, you must remove the api: line from your ESPHome configuration, otherwise the ESP will reboot every 5 minutes because no client connected to the native API.

I only use MQTT for ESP’s I put to sleep. Here’s why.

Thanks for the quick reply.

No amount of searching on my side got me to that paragraph. :slight_smile:

I didn’t know about the sleep challenge either.

1 Like

As a follow-up: I’ve updated all my devices and removed the API option and rebooted everything including HA.

I still see the warnings in my log.

Is my only option to remove both integrations and add all my devices again, or should it be sufficient to only delete the MQTT topics and let it be recreated?

I just had to delete the old entities. Simple.