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));
}