[SOLVED] MQTT, Homie and Dimmers

One issue when using a dimmer item and linking that to a homie channel is that dimmer items will accept ON/OFF commands in addition to a percent command. MQTT/Homie does not convert the ON/OFF into 100/0 so that any scripts using ON/OFF do not work.

Can this be fixed with a transform (I have read but don’t quite understand how I would do this).

Yes a transformation will work. What about transformations are you having issue with? Are you using files for items or PaperUi only?

Here is an example of two Things that use transformations:

Thing topic zigbee2mqtt "Bedroom Light" @ "Bedroom" {
        Type switch : power  "Power"               [ stateTopic="zigbee/0xb0ce1814030ac279", transformationPattern="JSONPATH:$.state",
                                                    commandTopic="zigbee/0xb0ce1814030ac279/set", on="ON", off="OFF" ]
        Type dimmer : dimmer "Dimmer"              [ stateTopic="zigbee/0xb0ce1814030ac279",
                                                    commandTopic="zigbee/0xb0ce1814030ac279/set", transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{\"brightness\":%s}" ]

    Thing topic Esp1 "Garage Light Level" @ "Garage" {
        Type number : level  "Light Level"          [ stateTopic="/Esp1/Garage/LightLevel" ]
        Type switch : contact  "Open Closed"        [ stateTopic="/Esp1/Door/Switch", transformationPattern="MAP:ONOFF.map" ]
        Type switch : motion  "Motion"              [ stateTopic="/Esp1/Motion/Switch", transformationPattern="MAP:ONOFF.map" ]

The first one is using js transformation and the second is using MAP.

In etc/openhab2/transform I have this file the item uses to make the transformation:

File name: ONOFF.map (notice the file name and the .map on the end)


One example of js transform
File name: getZigbeeBrightness.js


    var result;
    var json = JSON.parse(x);  
    result = json.brightness * 100 / 255;

    return result;

I hope these examples help and there are 2 other js files used (not posted) with the associated thing above.

I haven’t actually ever used transformations - have looked at a couple of examples on the forum but not sure.

I use .items files

Dimmer HomieTestDimmer "Homie Test Dimmer" {channel="mqtt:homie300:Queen:testdimmer:dimmer#dimmer"}

Since mqtt version 2.x the transformation is done with Thing not Item. I have all Things in files but many recommend using PaperUi for things and files for items. You can add the transformation in PaperUI just click the thing then “show more” in bottom left corner.

Thank you. Is there a way to do this in a generic way for all MQTT Homie things? I have about 100 dimmers…

For all things at once?

Not that I’m aware of, it’s one of those things you just have to do one at a time. After the first 1 or 2 it should go pretty quick.:crossed_fingers:

Give the first one a try, if you have errors post the config and error message and we can figure it out.

Will do, thank you

1 Like

It might be easier to make the modifications through the rest API docs or by editing the jsondb manually.

Best scenario would be a modification to the Homie section of the MQTT binding such that ON/OFF commands were change to a 1 or a 0.

Even better would be a Homie extension with device profiles so that when devices are discovered, items are created linked to corresponding best matching OH item type…

As with most things, if you can code it yourself the next best thing is to open a feature request.

Not in Java… :frowning:

Overall, despite having invested hundreds of hours developing Python libraries around Homie, I am not really sure it has made anything easier over basic MQTT.

@mjcumming I have just been trying out your ISY-Homie-Bridge as a way to control my Insteon devices (nice job by the way!). FYI I’m on ISY 5.16C .

I quickly found the sending “ON”/“OFF” problem to Dimmer items (the channel shows as a Number channel). can’t figure out a workaround for this though. If i try to edit the autodiscovered Thing/channel (to try setting a mapping up) OH gives the error Link not editable.

Have you found a workaround for this?


For dimmer items, you need to send 0 for off and 100 for on. I imaging you could setup a transform to turn off to 0 and on to 100.