arachnetech / homebridge-mqttthing

A plugin for Homebridge allowing the integration of many different accessory types using MQTT.
Apache License 2.0
466 stars 104 forks source link

startPub - no mqtt-message published but cached/old ones used? #521

Open trise-ne opened 2 years ago

trise-ne commented 2 years ago

Hello everyone,

i'm having problems with receiving the correct device state after homebridge reboots. Although logging the configured publish, i'm not seeing real mqtt-messages. When publishing those messages manually it's updating the devices status. I hope this is configured correctly. The message should look like:

Zigbee2MQTT Docs:

zigbee2mqtt/FRIENDLY_NAME/get This is the counterpart of the set command. It allows you to read a value from a device. To read e.g. the state of a device send the payload {"state": ""}. What you can /get is specified on the device page under the Exposes section.

I'm using:

Homebridge v1.3.9 (HAP v0.9.8) homebridge-config-ui-x v4.41.5 homebridge-mqttthing v1.1.38

This is my config:

{ "accessory": "mqttthing", "type": "lightbulb", "name": "Leselampe-X", "onValue": "ON", "offValue": "OFF", "onlineValue": "online", "offlineValue": "offline", "url": "http://localhost:1883", "username": "XXXX", "password": "XXXX", "mqttOptions": { "keepalive": 30 }, "mqttPubOptions": { "retain": false }, "logMqtt": true, "topics": { "getOnline": "zigbee2mqtt/Leselampe-X/availability", "getOn": { "topic": "zigbee2mqtt/Leselampe-X", "apply": "return JSON.parse(message).state" }, "setOn": "zigbee2mqtt/Leselampe-X/set", "getBrightness": { "topic": "zigbee2mqtt/Leselampe-X", "apply": "return Math.round(JSON.parse(message).brightness / 2.55)" }, "setBrightness": { "topic": "zigbee2mqtt/Leselampe-X/set", "apply": "return JSON.stringify({brightness: Math.round(message * 2.55)})" } }, "startPub": { "topic": "zigbee2mqtt/Leselampe-X/get/state", "message": "" }

Reboot-Logs:

[Leselampe-X] Initializing mqttthing accessory... [Leselampe-X] MQTT URL: http://localhost:1883 [Leselampe-X] MQTT options: {"keepalive":30,"clientId":"mqttthing_Leselampe-X_f34a49ac","protocolId":"MQTT","protocolVersion":4,"clean":true,"reconnectPeriod":1000,"connectTimeout":30000,"will":{"topic":"WillMsg","payload":"mqtt-thing [Leselampe-X] has stopped","qos":0,"retain":false},"username":"XXXX","rejectUnauthorized":false} [Leselampe-X] Publishing MQTT: topic = zigbee2mqtt/Leselampe-X/get/state [Leselampe-X] Publishing MQTT: message = […]

Shortly after that this is logged, although the device is OFF:

[Leselampe-X] Received MQTT: zigbee2mqtt/Leselampe-X = {"update_available":false,"state":"ON","linkquality":63,"brightness":51} [Leselampe-X] apply() function decoded message to [ON] [Leselampe-X] apply() function decoded message to [20] [Leselampe-X] Received MQTT: zigbee2mqtt/Leselampe-X/availability = online

This logged MQTT-message is not correct / present in my mqtt-network. Where is it from? Is there a cache I need to erase/turn off or is this an error? When publishing the mqtt-message above manually the status updates correctly.

Any advise / help would be appreciated. Thank you :)

rbswift commented 2 years ago

Something is publishing the "zigbee2mqtt/Leselampe-X" message. It's either your mqtt broker if zigbee2mqtt has told the broker to retain the message, or it's zigbee2mqtt itself publishing that message.

A good test is to stop mqttthing completely and login twice to the shell. At one shell type "mosquitto_sub -v -t '#'" and at the other type mosquito_pub -t "zigbee2mqtt/Leselampe-X/get/state" and see what happens.