Rollershutter channel/item does not update on non-OH commands when applying JS/MAPtransformation

I have a MQTT Thing of my fixed home automation system by Qbus. This is transferring it’s states and commands via MQTT to my OH-system. This was working fine, except for the dynamic icons in the widgets which were inverted (open=close and close=open). I applied a JS transformation (also tried MAP transformation, same issue) on the channel to invert the state percentages.

This which works fine when sending commands through OH, but does not work anymore when sending commands from my fixed home automation system (fixed buttons or cloud app). When using no JS/MAP transformation, the state changes of my fixed home automation system are logged correctly in OH, but when the transformation is applied I cannot see the state changes unless they are given by OH. When checking MQTT explorer, all the state changes are still visible.

I also tried to add the JS-transformation to the “Incoming Value Transformation” in the channel configuration, but can’t get it working. This is what I changed to the Thing/Channel configuration given below:

transformationPattern: JSONPATH:$.properties.shutterPosition∩JS:invertpercent.js

Then I got this error logging in OH.

2022-11-02 15:07:02.053 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command 'function(i)  {
   var percent_shelly = parseInt(Number(i),10);
   var percent_oh = (100.0- percent_shelly);
   return new StringType(percent_oh.toFixed(0));
}' from channel 'mqtt:topic:QbusMQTT:QbusMQTTGW:QbusMQTT_rolLivO' not supported by type 'RollershutterValue': Cannot call update() with function(i)  {
   var percent_shelly = parseInt(Number(i),10);
   var percent_oh = (100.0- percent_shelly);
   return new StringType(percent_oh.toFixed(0));
}
  • Platform information:
    • Hardware: RPi4B
    • OS: OpenHABian
    • Java Runtime Environment: openjdk version “11.0.16” 2022-07-19
    • openHAB version: 3.3.0

Thing configuration:

UID: mqtt:topic:QbusMQTT:QbusMQTTGW
label: Generic MQTT Thing
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:QbusMQTT
channels:
  - id: QbusMQTT_rolLivO
    channelTypeUID: mqtt:rollershutter
    label: Screen Liv-O MQTT
    description: ""
    configuration:
      transformationPatternOut: JINJA:{"id":"UL55","type":"state","properties":{"shutterPosition":{{value}}}}
      formatBeforePublish: "%d"
      commandTopic: cloudapp/QBUSMQTTGW/UL1/UL55/setState
      stateTopic: cloudapp/QBUSMQTTGW/UL1/UL55/state
      transformationPattern: JSONPATH:$.properties.shutterPosition
      off: "0"
      on: "100"

Profile: JS-transformation applied on channel because of inverted icons. Code below of invertpercent.js:

function(i)  {

   var percent_shelly = parseInt(Number(i),10);
   var percent_oh = (100.0- percent_shelly);
   return new StringType(percent_oh.toFixed(0));

}

It would probably be best to fix this at the widget instead of at the Channel, assuming in all other respects the inverted value is OK.

Your JS Transformation isn’t formatted correctly. Here’s an example from the docs:

(function(i) {
    var array = i.split(" ");
    return array[array.length - 1].length;
})(input)

Notice how it’s surrounded by parens and that (input) at the end. That’s what actually causes the transform to execute the function.

Thanks for the reply. I would rather leave the transformation in the channel or even better combined with the JSONPATH transformation, but that doesn’t work at all.

I modified the JS transformation with the () and (input) and now it works fine.