MQTT and API at the same time - it's possible?

Hi!
It’s possible, by somehow, to have both MQTT and API enabled?

Let me explain: I don’t want to use HA + ESPHome using MQTT, I’m already using API and it’s perfect.
The reason for using MQTT is because I need to read some sensor running ESPHome into my weather station (that subscribe to some MQTT topics)…so I need to publish just some sensor from ESPHome into my weather station using MQTT.
Is that possible??

I’m using mqtt: key…but this creates 2 devices in my HA and only one works…also, everything get’s duplicated and device (ESPHome) keeps rebooting, which is the correct behavior:

Warning
If you enable 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 15 minutes because no client connected to the native API.

Any ideas here?

1 Like

Add discovery: false to the mqtt definition. Then your device isn’t discovered automatically by HA.

See: MQTT Component

Before flashing the new firmware you should call esphome clean-mqtt your.yaml to cleanup the MQTT discovery topics.

Ok about discovery, but I think I still can’t usw both because of reset thing :confused:

You can overwrite the default reboot_timeout (in the api & mqtt component) with :zero: to disable it. So it will not reboot if api/mqtt is not connected.

1 Like

If I understand correct you are using HA API for this node. And need MQTT for your weather station.
As long as there is a API connection to the node, nothing will happen. The reboot will only occur, if no HA API connection is available.

Tks Guy’s, its woring with both options, API and MQTT (discovery disabled).

1 Like

OK, that’s a quick short answer. Can you give a more specific point to review. “MQTT Component” is several pages long. I have read it, but, to digest it in one view isn’t that easy.

Thanks for adding a pointer to what you think answers this excellent question. I don’t understand/know why MQTT and the API can’t coincide.

1 Like

If you are using API and MQTT you will end with to devices in HA. One is created from API integration and one is created from MQTT.
Device creation could be disabled with discovery: false

1 Like