I thought I would share this in case anybody else finds it useful.
I have managed to get zigbee2MQTT working with an Innr and Ikea Tradfri bulb using the latest MQTT binding without using a javescript transformation, just a JSON one for the incoming message.
Things file.
Bridge mqtt:broker:myUnsecureBroker [ host="192.168.2.4", secure=false ]
{
Thing topic zigbeeMQTT "Zigbee2mqtt" {
Channels:
Type switch : permitJoin [ commandTopic="zigbee2mqtt/bridge/config/permit_join", on="true", off="false" ]
Type dimmer : Test_Lamp "Test Lamp" [ stateTopic="zigbee2mqtt/Her_Lamp", commandTopic="zigbee2mqtt/Her_Lamp/set", min=1, max=254, step=1, transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{ \"brightness\": %s }" ]
//Main Study Lights
Type dimmer : Main_Study_1 "Test Main Study 1" [ stateTopic="zigbee2mqtt/Main_Study_1", commandTopic="zigbee2mqtt/Main_Study_1/set", min=1, max=254, step=1, transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{ \"brightness\": %s }" ]
Type dimmer : Main_Study_2 "Test Main Study 2" [ stateTopic="zigbee2mqtt/Main_Study_2", commandTopic="zigbee2mqtt/Main_Study_2/set", min=1, max=254, step=1, transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{ \"brightness\": %s }" ]
Type dimmer : Main_Study_3 "Test Main Study 3" [ stateTopic="zigbee2mqtt/Main_Study_3", commandTopic="zigbee2mqtt/Main_Study_3/set", min=1, max=254, step=1, transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{ \"brightness\": %s }" ]
}
}
The ‘Min’ value is set to 1 as that’s what my bulbs report as off, ‘Max’ is 254 so the value can be between 1-255.
The ‘transformationPattern’ selects just the ‘Brightness’ value from the incoming JSON message. The ‘formatBeforePublish’ works to format the outgoing message into JSON format.
I have tested it with a couple of my lights and I am able to control them fine using Basic UI, HabPanel and through my Alexa.