MQTT Binding - JS transformation only executed randomly when in wrong format?

Hi all,

I have a small issue with MQTT binding and incoming data transformation using JavaScript. Somewhere in the forum (can’t find the post anymore), I read that there are two valid formats for JavaScript. But for some reason, one (that works for other MQTT things), is triggered always, while the other only is every few minutes. Can anyone explain me, why? The RawPayload is only there to verify that I actually receive every payload published to the topic and it’s not a connection issue.

Thing mqtt:topic:Zigbee2Mqtt_Kueche_Hue_Color_Links "Hue Color Links (MQTT)" (mqtt:broker:broker) {

  Channels:
    Type color : color [
      stateTopic="zigbee2mqtt/1.05-kueche/hue-color/links",
      transformationPattern="JS(zigbee2MqttToColor.js)"
    ]
    
    Type string : RawPayload [
      stateTopic="zigbee2mqtt/1.05-kueche/hue-color/links"
    ]
}

With this content/format, the following code is executed always (I can see the log line)

(function(x) {
    console.log("I am always here!");

    [...]
})(input)

But with this format, the code is only executed every few minutes. No errors or else in the logs.

console.log("Sometimes, I'm here!");

[...]

Any Idea what might be the issue or how to debug?

Edit:

Platform: openHAB 5.1.0, OpenJDK Runtime Environment Zulu21.0.9

Are the Items updating even when no log appears? If so, are they updating to the original message or a transformed message?

The first format with the self executing function is the properly documented way to write a JS transformation. But it should work without that self executing function and that certainly doesn’t explain why it might only execute periodically unless there is some sort of blocking call elsewhere in the transformation (only one copy of any given JS transformation can run at a time so if one takes a long time to run, subsequent calls to it are queued up and run in sequence). That’s the only thing I cna think of which might cause the transformation to only execute sometimes.

But we don’t know that’s what’s happening. There might be something odd going on just with the logging.

Hi Rich,

thank you for your reply!

No, the item is not updated when there is no log. I added the logging afterwards to ensure that the transformation is not called at all. Since you say, both methods should work (and I know it does at other things in the same file), I’ll stick with the function one and add this topic to my “inspect later and write a PR if I can find the reason”

Sascha