Have you read this topic:
For brightness I use:
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)
My things file:
Thing topic zigbee2mqtt "Bedroom Light" @ "Bedroom" {
Channels:
Type switch : power "Power" [ stateTopic="zigbee/0xb0ce1814030ac279/state",
commandTopic="zigbee/0xb0ce1814030ac279/set/state", on="ON", off="OFF" ]
Type dimmer : dimmer "Dimmer" [ stateTopic="zigbee/0xb0ce1814030ac279",
commandTopic="zigbee/0xb0ce1814030ac279/set", transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{\"brightness\":%s}" ]