I am new to MQTT. I have read/watched everything I can find, but I’m still having the same issue discussed here:
I have a switch and optical encoder connected to a raspberry pi zero W that I am wanting to use in my garage. I write the python on the pi zero to connect to the broker on HA and I am hoping to use auto discovery to see the entity and/or device.
Do I need to define each of these using a script as mentioned in the above reference? It seems like I should be able to specify everything from my Python script running on the pi zero w.
I am running:
Home Assistant 0.116.2
Installed from HassOS image (version 4.13)
on a raspberry pi 4, 64 bit
I uninstalled and re-installed the MQTT add-on broker and the MQTT integration:
When I runt the python program on the pi zero, listening with the MQTT integration I see this in HA. I see the values for both the switch and encoder on the Integration listener, but I don’t see any entities or devices.
Message 1 received on homeassistant/binary_sensor/Garage1Open/config at 9:48 PM:
{
"device_class": "binary_sensor",
"name": "Garage1",
"state_topic": "homeassistant/binary_sensor/Garage1Open/state",
"retain": "true"
}
QoS: 0 - Retain: false
Message 0 received on homeassistant/sensor/sensorGarage1/config at 9:48 PM:
{
"device_class": "sensor",
"name": "Garage1",
"state_topic": "homeassistant/sensor/sensorGarage1/state",
"retain": "true"
}
I forgot to mention that I also need to have a userid in my MQTT config. If I try to use an HA user, it doesn’t seem to work. Here’s my current MQTT config without a local user:
user MUSER
topic readwrite #
user homeassistant
topic readwrite #
With this, when I try running my Python program I receive the following notification:
Login attempt or request with invalid authentication from supervisor (172.30.32.2) (Python/3.8 aiohttp/3.6.2)
If I add MUSER as a local login with the same password I don’t have this problem. Perhaps /share is not the correct directory for the mosquitto directory? I have tried in other directories and I receive an error on MQTT. It seems to work in this directory.
Correct. if you specify active: true you need an ACL file and it needs either the user MUSER (in your case) defined in the logins section of the addon OR MUSER defined as a HA user.
The share folder is correct.
SOLVED. I think my version may have had an issue with 64 bit since I’m using an 8 GB PI 4. I wiped out my HA image and downloaded the latest home assistant OS image. After starting over with this image the MQTT discovery works perfectly.