I am still quite the newbie to HA and I need some help with configuring and using MQTT.
I have a home-build (Hardware and Software) MQTT-Client that regularly publishes status updates to a MQTT server (no need to be able to “control” anything on the client from HA).
The MQTT-server is running and does receive the published status messages, this I have confirmed using three different tools (mosquitto_sub, HA-MQTT-Explorer and HA itself (Listen to topic)).
Here is the output from the three Tools (the “time” does not match as the Info is collected at different times):
Message 0 received on basement/wateralarm/state at 17:29:
{
“sensor”: “Wateralarm”,
“time”: 1763656148,
“status”: “OK”
}
And in HA-MQTT-Explorer:
basement
wateralarm
state = {“sensor”:“Wateralarm”,“time”:1763656750,“status”:“OK”}
Even if I receive data - the status of the device shows up as “Unknown”.
The status can contain three different status-codes:
OK
WARNING
CRITICAL
I have searched the net and found some YouTube-Videos, but most of them are either really old or when I try the configuration steps I end up with some errors.
Any suggestions where I could have gone wrong?
If you need more information, please feel free to ask.
If you want MQTT Discovery you need to publish in the homeasistant/ topic.
If you want to publish in your own topic, you need to create MQTT YAML to interact with them. Both are documented here:
Why is the topic basement? What is the field sensor? Where are these things coming from? And how do you expect Home Assistant to understand them and turn them into Home Assistant things??
You need to be way more clear about what you’re doing.
It seems you set up a sensor instead of a binary_sensor. As the state is OK I guess that is the ON state. Also you can set the device class to moisture.
Yes you are correctly assuming that it is a “3 state sensor”.
What I mean with “home-build” is that this is a sensor that I have build myself - hardware (Arduino) and software.
No, the device does not use Zigbee2MQTT but directly sends its status data via WiFi to the MQTT server (which works).
Once every 10 minutes the device will “post” a status message like this
This is to be able to see that the device is up & running (keep-alive message).
If something “happens” the status immediately changes to WARNING and if not reacted to within a certain time the status changes to CRITICAL.
I have used exactly the same Hardware and Software in an other “Home Automation Project” and there it worked fine (do not ask why I changed).
From my point of view, a binary_sensor will not work in this scenario as it is only On/Off and not three-state.
I am going to try again to set it up using a “yaml entry”, but last time I tried that I got some error message (cant remember exactly what) in the log.
I’ll get back with the outcome of that test tomorrow.
Now I will try to make an automation that triggers by a state change.
But that is another theme and will try to do it myself and before I post here again.