I am currently using Node red, but others have convinced me to give Home Assistant a try.
I added mqtt and switches to my configuration.yaml file, and I can turn the lights on by clicking on the switch slider. However, a couple of seconds later, the slider goes off, yet the light remains on. I can’t turn the light off from Home Assistant, but I can from Node Red.
This is normally because HA is not receiving the state_topic message to acknowledge that the light has changed. It assumes it hasn’t so puts this switch back to its original state.
Check that the state_topic: and payload match the status being received after the light is turned on. And that HA is still connected to the broker and subscribed to all topics.
Thanks. Makes sense, but I am monitoring the mqtt traffic and my state_topic payload is being sent by the lights.
Here’s the code in my light node: #define NODENAME “room”
const char *cmdTopic = NODENAME “/light”;
const char *statusTopic = NODENAME “/light/status”;
I have MQTTLens (please tell me if you have a preferred MQTT monitor program- I am not thrilled with MQTTLens). Anyway, MQTTLens shows topic: ‘room/light/status’ has a payload of “on” as soon as the light is turned on.
Could I be missing something in my .yaml file?
- platform: mqtt
name: “Room Node”
state_topic: “room/light/status”
command_topic: “room/light”
payload_on: “on”
payload_off: “off”
optimistic: false
qos: 0
I normally use mosquitto_sub, but I don’t think it does anything different.
I can’t see anything wrong with your configuration. The only thing I can think of trying is to remove the quotes from the payload. The documentation has them in, but my configuration doesn’t, and that seems to work fine - so
payload_on: on
payload_off: off
If not, you can turn on logging to debug in HA, to get information in the logs about what is happening to the message (if it is being received)
You might also subscribe to $SYS/broker/publish/# as this contains data about the broker. If the broker isn’t sending messages out, then it doesn’t think that HA has subscribed.