Firstly, I’m a bit green when it comes to MQTT so forgive me if I use the wrong terminology.
Anyway, I have Tesla Mate running which publishes data via MQTT to Home Assistant. For the last few years this has worked great but recently it’s acting weird, where the sensors in HA that are linked to MQTT topics suddenly stop updating. If I restart HA then things start updating again but eventually will stop again.
I turned debug logging on for Mosquitto, I’ve also SSH’d into HA to run mosquitto_sub and I’ve also used MQTT explorer to connect to HA and everything seems to show that Mosquitto is receiving up to date data for each topic from Tesla Mate. For reasons I haven’t been able to determine, I cannot see why the defined sensors in HA are not updating.
The only other thing I have publishing to Mosquitto is a room-assistant sensor and that is updating just fine.
Is there somewhere else I should be looking to find the source of the issue?
Has there been an update to the Telsa Mate, and in particular, the topics it uses to publish data?
If the data starts fine, but then stops, my guess it is Tesla Mate that has a problem keeping connected (with the car?), not MQTT and the broker (e.g. mDNS, WLAN, a crash, etc). Can you restart Tesla Mate and not the broker?
Sometimes sensors publish topics which are ‘retained’, which stay on the broker even if things change. This is usually to allow Last Will and Testament failure detection, but can mask issues with upgrades and discovery: https://www.hivemq.com/blog/mqtt-essentials-part-8-retained-messages/
Find the Tesla Mate topics, and use https://mqtt-explorer.com/ to delete them ALL. This might show another issue, but at least you know the data in the broker is fresh and not retained, and in particular MQTT discovery is correct.
IPv6 didn’t work with HASS brokers, but that wouldn’t work at all.
Tesla Mate hasn’t had an update since Jan so nothing has really changed on its side. The only thing that I forgot to mention that has changed in that time is that my virtual host had a hardware issue that meant I needed to restore both the HA and Tesla Mate VMs from backups. It seems like this issue has started since then.
This may be me not understanding MQTT properly, but if while examining Mosquitto via debug logs, mosquitto_sub and MQTT Explorer and all three tools are showing that up-to-date data has been sent to it, doesn’t that rule out Tesla Mate as the issue?
You have the benefit of log data which we can’t see, so frankly the root cause could be anywhere! All we can do is make suggestions at areas to look at, and give links for things to read.
The chain of MQTT data is usually something like:
Data source
MQTT broker
Connect
OPTIONAL Publish HASS discovery data to auto-create HASS entities
Publish data topics
Publish data topics (repeat)
HASS MQTT Add-On
OPTIONAL HASS Discovery creates entities
OPTIONAL YAML manual entity definition
HASS subscribes to topics, updates entities
How are the entities in HASS being created? HASS discovery, manual YAML, other?
a. If HASS discovery, have you deleted ALL retained topics and tried a restart?
b. If manual, have you changed the YAML to the new MQTT format (about 6 months ago)
Can you trace the data path from end-to-end, looking for things like changed IP addresses, fresh data making it from sensor to HASS entity?
Has the format changed in the MQTT topics and not being picked up in HASS?
Can you manually mosquitto_pub publish obviously different values to the Tesla Mate topic, and see the result change in HASS?
Are there any signs of the Tesla Mate disconnecting? (e.g LWT values changing after a timeout)
Again, retained topics can give the appearance that data is there, so manually delete the lot and do a clean restart.
If fresh, current data is making it from the sensor to HASS entity once, then something else is happening, like low memory on a VM crashing after time.
So, I think I may have solved the issue but will keep an eye on it to see if things go wrong again.
Essentially, when I set Mosquitto up a few years back it looks like the way I did it was wrong/dumb lol. On the Devices & Services page, it looks like I had configured the MQTT to be connecting to Tesla Mate as the broker. I changed that to now look at Mosquitto hosted on HA and as soon as I did that things started updating properly again.
I still don’t fully understand why things were working fine until recently or if this is even a permanent fix (afterall, it would come right and then stop). Hopefully that’s the solution tho.