Hi,
I have a problem with the mqtt 2.5 binding:
for some things the receiving status updating is working only the first time and after that just nothing happens when there is an update on the corresponding mqtt topic.
But for other items it is working without any problem.
Here is what I did:
manual publish: zigbee2mqtt/hue_white_1/set with {“brightness”:“150”}
observed the status update from the device (checked in a mqtt client)
log:
2020-01-10 15:50:16.116 [TRACE] [ansport.mqtt.internal.ClientCallback] - Received message on topic 'zigbee2mqtt/hue_color_wohnzimmer_rechts' : {"state":"ON","linkquality":21,"brightness":150,"color":{"x":0.45497869131350777,"y":0.1453366652166652,"saturation":100,"hue":46.2},"color_temp":153,"color_mode":1}
2020-01-10 15:50:16.118 [TRACE] [ansport.mqtt.internal.ClientCallback] - Topic match for 'zigbee2mqtt/hue_color_wohnzimmer_rechts' using regex zigbee2mqtt/hue_color_wohnzimmer_rechts
2020-01-10 15:50:16.121 [TRACE] [ansport.mqtt.internal.ClientCallback] - No topic match for 'zigbee2mqtt/hue_color_wohnzimmer_rechts' using regex zigbee2mqtt/hue_white_1
2020-01-10 15:50:16.123 [TRACE] [ansport.mqtt.internal.ClientCallback] - No topic match for 'zigbee2mqtt/hue_color_wohnzimmer_rechts' using regex zigbee2mqtt/osram_plug_3
2020-01-10 15:50:16.126 [TRACE] [ansport.mqtt.internal.ClientCallback] - No topic match for 'zigbee2mqtt/hue_color_wohnzimmer_rechts' using regex zigbee2mqtt/osram_plug_2
2020-01-10 15:50:16.128 [TRACE] [ansport.mqtt.internal.ClientCallback] - No topic match for 'zigbee2mqtt/hue_color_wohnzimmer_rechts' using regex homeassistant/.*
2020-01-10 15:50:16.130 [TRACE] [ansport.mqtt.internal.ClientCallback] - No topic match for 'zigbee2mqtt/hue_color_wohnzimmer_rechts' using regex zigbee2mqtt/bridge/log
2020-01-10 15:50:16.133 [TRACE] [ansport.mqtt.internal.ClientCallback] - No topic match for 'zigbee2mqtt/hue_color_wohnzimmer_rechts' using regex zigbee2mqtt/osram_plug_1
2020-01-10 15:50:16.135 [TRACE] [ansport.mqtt.internal.ClientCallback] - No topic match for 'zigbee2mqtt/hue_color_wohnzimmer_rechts' using regex zigbee2mqtt/hue_color_wohnzimmer_links
2020-01-10 15:50:16.137 [TRACE] [ansport.mqtt.internal.ClientCallback] - No topic match for 'zigbee2mqtt/hue_color_wohnzimmer_rechts' using regex zigbee2mqtt/bridge/state
2020-01-10 15:50:16.140 [TRACE] [ansport.mqtt.internal.ClientCallback] - No topic match for 'zigbee2mqtt/hue_color_wohnzimmer_rechts' using regex valetudo/rockrobo/state
2020-01-10 15:50:16.142 [TRACE] [ansport.mqtt.internal.ClientCallback] - No topic match for 'zigbee2mqtt/hue_color_wohnzimmer_rechts' using regex [^/]*/[^/]*/\$homie
-> Looks like JS:mapHueToPercent.js is not triggered but at least we get the mqtt status update
manual publish: zigbee2mqtt/hue_white_1/set with {“brightness”:“50”}
observed the status update from the device (checked in a mqtt client)
log: nothing
waited some time
manual publish: zigbee2mqtt/hue_white_1/set with {“brightness”:“150”}
observed the status update from the device (checked in a mqtt client)
log: nothing
[…]
I have an other device (zigbee2mqtt/hue_white_1) where I use JSONPATH:$.brightness + a rule for conversion and for this device it’s working without a problem: I get the “Received message on topic” + “Topic match for” message for every update.
Also double checked mapHueToPercent.js script (BTW: transformationPatternOut is working without a problem).
Furthermore I pasted the mapHueToPercent.js to a browsers javascript console to check if it’s valid js (with a small change: var logger = console)
Note: I’m also experiencing this bug: https://github.com/openhab/openhab-addons/issues/6243 - working around it with a “sudo service openhab2 restart” after each change. The next update after a restart is always catched.
Environment:
2.5.0 Release Build
openhab> version
4.2.7
openhab> feature:list | grep mqtt
openhab-misc-mqttbroker x 2.5.0 x x Uninstalled x openhab-addons-2.5.0 x MQTT Broker Moquette
openhab-binding-mqtt x 2.5.0 x x x Started x openhab-addons-2.5.0 x MQTT Binding
openhab-persistence-mqtt x 1.14.0 x x Uninstalled x openhab-addons-2.5.0 x MQTT Persistence
openhab-core-io-transport-mqtt x 2.5.0 x x Started x distro-2.5.0 x
openhab-transport-mqtt x 2.5.0 x x Started x distro-2.5.0 x MQTT Transport
Things:
Bridge mqtt:broker:MQTTBroker [ host="127.0.0.1", secure=false, username="openhabian", password="asdqwe" , clientID="openhab" ]
{
Thing topic hue_white_1 "Hue_white_1" @ "Wohnzimmer" {
Type switch : power [ stateTopic="zigbee2mqtt/hue_white_1", transformationPattern="JSONPATH:$.state", on="ON", off="OFF", commandTopic="zigbee2mqtt/hue_white_1/set", formatBeforePublish="{\"state\":\"%s\"}"]
Type number : brightness [ stateTopic="zigbee2mqtt/hue_white_1", transformationPattern="JSONPATH:$.brightness", min=0, max=255, commandTopic="zigbee2mqtt/hue_white_1/set", formatBeforePublish="{\"brightness\":\"%s\"}"]
}
Thing topic hue_color_wohnzimmer_links "Hue_color_wohnzimmer_links" @ "Wohnzimmer" {
Type switch : power "An/Aus" [ stateTopic="zigbee2mqtt/hue_color_wohnzimmer_links", transformationPattern="JSONPATH:$.state", on="ON", off="OFF", commandTopic="zigbee2mqtt/hue_color_wohnzimmer_links/set", formatBeforePublish="{\"state\":\"%s\"}"]
Type number : brightness "Helligkeit" [ stateTopic="zigbee2mqtt/hue_color_wohnzimmer_links", transformationPattern="JS:mapHueToPercent.js", min=0, max=255, commandTopic="zigbee2mqtt/hue_color_wohnzimmer_links/set", transformationPatternOut="JS:mapPercentToHue.js"]
Type colorHSB : colorHSB "Farbe" [stateTopic="zigbee2mqtt/hue_color_wohnzimmer_links", transformationPattern="JS:xyz2hsv.js", commandTopic="zigbee2mqtt/hue_color_wohnzimmer_links/set", transformationPatternOut="JS:hsv2xyz.js"]
Type number : temperature "Farbtemperatur" [commandTopic="zigbee2mqtt/hue_color_wohnzimmer_links/set", formatBeforePublish="{\"color_temp\":\"%s\"}", min=153, max=500]
}
Thing topic hue_color_wohnzimmer_rechts "Hue_color_wohnzimmer_rechts" @ "Wohnzimmer" {
Type switch : power "An/Aus" [ stateTopic="zigbee2mqtt/hue_color_wohnzimmer_rechts", transformationPattern="JSONPATH:$.state", on="ON", off="OFF", commandTopic="zigbee2mqtt/hue_color_wohnzimmer_rechts/set", formatBeforePublish="{\"state\":\"%s\"}"]
Type number : brightness "Helligkeit" [ stateTopic="zigbee2mqtt/hue_color_wohnzimmer_rechts", transformationPattern="JS:mapHueToPercent.js", min=0, max=255, commandTopic="zigbee2mqtt/hue_color_wohnzimmer_rechts/set", transformationPatternOut="JS:mapPercentToHue.js"]
Type colorHSB : colorHSB "Farbe" [stateTopic="zigbee2mqtt/hue_color_wohnzimmer_rechts", transformationPattern="JS:xyz2hsv.js", commandTopic="zigbee2mqtt/hue_color_wohnzimmer_rechts/set", transformationPatternOut="JS:hsv2xyz.js"]
Type number : temperature "Farbtemperatur" [commandTopic="zigbee2mqtt/hue_color_wohnzimmer_rechts/set", formatBeforePublish="{\"color_temp\":\"%s\"}", min=153, max=500]
}
}
mapHueToPercent.js:
(function(value){
var logger = Java.type("org.slf4j.LoggerFactory").getLogger("mapHueToPercent");
logger.warn("mapHueToPercent");
var data = JSON.parse(value);
var percentValue = parseInt(data.brightness)/255.0
logger.warn(data.brightness + "->" + percentValue);
return percentValue;
})(input)
mapPercentToHue.js:
(function(value){
var logger = Java.type("org.slf4j.LoggerFactory").getLogger("mapPercentToHue");
logger.warn("mapPercentToHue");
var hueValue = Math.round(value*255.0)
logger.warn(value + "->" + hueValue);
return '{"brightness":"' + hueValue + '"}';
})(input)
I’m investigating on this problem for multiple days now and getting out of ideas…