I have defined a Channel with the type percentage value. The dimmer value is sent via this mqtt channel to the broker.
A fhem device subscribes this parameter.
The percentage value is transmitted with 1 digit after the decimal separator e.g. 10.0 for 10% via mqtt. The chem device can not handle “10.0” because it expects “10”.
I tried to use Outgoing value transfer in the openhab Paper UI. But the value on mqtt is still “10.0”.
You are right. The OH log shows it without the decimal but the MQTT Broker receives the value with the decimal.
OH is publisher --> FHEM is subscriber
The device which is controlled via FHEM does not accept the value with decimal.
I use files for everything so the only example I can show will be file-based but it’s recommended to create your Things in PaperUI and Items in files. For your case, you may be able to use the transformation part only and it work? Also, this is my example as you may need to adjust the code in one or all of the transformation files to suit your needs.
Then using js transformation (will need to install this via PaperUI) and place the code in ect/openhab2/transform naming it whatever you like with the .js on the end.
Example:
getZigbeeBrightness.js
(function(x){
var result;
var json = JSON.parse(x);
result = json.brightness * 100 / 255;
return result;
})(input)
setZigbeeBrightness.js
(function(x){
var brightness = x * 255/100;
var result = new Object();
result.brightness = brightness;
return JSON.stringify(result);
})(input)
setZigbeeState.js
(function(x){
var result = new Object();
result.state = x;
return JSON.stringify(result);
})(input)
That was my point earlier, you needed a transformation be it js, javascript or whatever. Glad it’s working as expected and don’t forget to click the square box on solution post.