I’m struggling with MQTT auto-discovery. I’ve read the documentation, and all of the posts I could find about similar problems, and still nothing.
I’ve got a topic emon/power/import that carries numeric data. I’m advertising this to Home Assistant using a retained message published to homeassistant/sensor/emon/power-import/config, with the payload
I have verified that the MQTT integration is connected to the broker, and subscribing to homeassistant/# from within Home Assistant regurgitates the retained configuration message immediately, as expected. I have verified that discovery is enabled in the MQTT integration configuration. But nothing happens - no entities or devices are created, nothing.
I’m not sure what to try next. Can I get any more debug information from Home Assistant, which appears to be receiving and ignoring my discovery messages?
In case it’s important I’m running Home Assistant Container, and the info screen reports version 2021.2.0.dev20210119.
Something isn’t quite as perfect as you reported because when I publish the same payload to the same topic I instantly get a sensor created:
Basically, I’ve confirmed there’s nothing wrong with your choice of discovery topic or discovery payload. What it suggests is that something may be amiss elsewhere.
I assume you’ve already seen this in the MQTT integration and it’s enabled:
Plus you confirmed that you saw the discovery payload published while monitoring it here:
Please excuse the weirdly joined image, as a new user I’m not allowed to post more than one picture. Note that there are actually 6 sensors, I just chose one for the purposes of the original question, and a different one is visible at the top of the screenshot.
After a night’s sleep though it did finally occur to me to check the logs and I found this:
Exception in discovery_done when dispatching 'mqtt_discovery_done_('sensor', 'emon power-import')': (None,) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/mqtt/discovery.py", line 170, in discovery_done pending = hass.data[PENDING_DISCOVERED][discovery_hash]["pending"] KeyError: ('sensor', 'emon power-import')
Edit: this is the better-formatted version from the log file on the container itself:
2021-04-21 08:10:11 ERROR (MainThread) [homeassistant.util.logging] Exception in discovery_done when dispatching 'mqtt_discovery_done_('sensor', 'emon power-import')': (None,)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/mqtt/discovery.py", line 170, in discovery_done
pending = hass.data[PENDING_DISCOVERED][discovery_hash]["pending"]
KeyError: ('sensor', 'emon power-import')
This seems relevant. Unfortunately, though I’m a reasonable Python programmer, I’m not sufficiently familiar with the internals of Home Assistant to have any idea what it means.
Well, how unsatisfactory. I’m sorry to say that it now works, without me doing anything at all - I was messing with something else entirely and suddenly my entity list grew significantly. In fact I got multiple copies of each entity, which took me a while to sort out.
I wish I’d been able to get to the bottom of this. “It works fine now” is fine as an outcome, but understanding what was wrong would have been significantly more satisfactory. Just to clarify, I didn’t change anything at all. It’s possible that I did a restart of Home Assistant - I certainly have done so since.
Well ok, but “restart and cross my fingers” appears to be exactly what I did, and there is now no opportunity to gather any more debugging data so there’s no chance of fixing whatever the underlying problem was.
On some forums I’m used to, marking the thread as solved would be encouraged so as not to waste the time of people looking to help. On others, it would be discouraged so as not to waste the time of other people looking for solutions. Whatever is the accepted practice here I will happily go along with it. Would you rather I removed the “Solution” mark?
It’s your topic so you are free to mark whatever post you want as the Solution.
Having spent a few years here, my understanding is that the Solution tag isn’t the either/or situation you described but both; it indicates the problem is solved and shows how to fix it.
In this case, the symptoms simply disappeared, the root cause is unknown, and there are no instructions to help anyone else fix it.
I had problem, when auto-discovery didn’t work with examples from manual, but zwave2mqtt worked perfectly fine,
so i took one of topics and modified to my needs: