Recieve from Mqtt brocker value and tehn update Item

Platform information:RPI3B+
openHAB version:2.5 Rc1

Hi, i try to update the state of some items when i recieve from Mqtt Brocker value.

for exemple i recieve pourcent value from dimmer through Mqtt , value for exemple “40”

then trought a rules “update the state” of item physicaly attached and recieve “40” for pourcent values.

Exc; dimmerMqttSubscribe = 40 , then physical Dimmer.sendCommand (40) .This is the idea

i try this trought a rules :

rule "Zigbee dimmer Salle de Gym mqtt"
when Item ZigbeeDimmerSalGymSub received update

then ZigbeeDimmerSalGym.sendCommand("{\"brightness\":" + ZigbeeDimmerSalGymSub.state + "}")


but i recieve in frontail this message:

[WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert '{"brightness":32}' to a command type which item 'ZigbeeDimmerSalGym' accepts: [PercentType, OnOffType, IncreaseDecreaseType, RefreshType].

also here is my item file mqtt :

Dimmer ZigbeeDimmerSalGymSub     "Zigbee dimmer SalGym sub[%.0f %%]" {channel="mqtt:topic:58d1f7db:ZigbeeDimmerSalGymSub"}

and the physical dimmer item here:

Dimmer ZigbeeDimmerSalGym        "Salle de Gym Dimmer[%.0f %%]"   <dim>     (Sgym)      {channel="openwebnet:zb_dimmer:6821146:7670182:brightness"}

what i need to convert and how ? thanks very mutch for your help !

I use js transformation service for my zigbee dimmers. To do the same you will need to install the js transformation addon via PaperUI. Then add the examples below in /etc/openhab2/transform and name them whatever.js

To get the brightness:



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

    return result;

To set the brightness:


    var brightness = x * 255/100;

    var result = new Object();
    result.brightness = brightness;
    return JSON.stringify(result);

To get the state:


    var result = new Object();
    result.state = x;
    return JSON.stringify(result);

My thing and item example:


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}" ]


Switch BedroomLight "Bedroom Light"    <light> ["Lighting"]  { channel="mqtt:topic:pibroker:zigbee2mqtt:power", expire="120m,command=OFF" }
Dimmer BedroomLight_Level "Bedroom Light Level [%.0f %%]"    <light> ["Lighting"]  { channel="mqtt:topic:pibroker:zigbee2mqtt:dimmer" }
1 Like

thanks a lot for your help ! this is great !
so i try and not succed to the setup , i thing i don’t understood the mqtt topic things , i do whit paperui , also i dont need the commandTopic, my goal is to recieve from incoming topic a"subscribe" value.

And then paste “trought a rules” the same value on a real “item”, i have 2 Rpi but the dongle zigbee for the first Rpi i too fareway of the physical switch.
So i send the command from the first Rpi using “mqtt Publish topic”

then on the second Rpi (the one have the physical zigbee dongle) read from “mqtt subscribe topic” the value recived and “trought a rules” clowning value to value. is like a remote if you wish.

maebe there are best process for doing that ?

but i found this this is very simple but it work “i test many trick and by accident i found”
here is the rule for a switch and a dimmer

rule "Zigbee Switch 1 Ancienne Maison mqtt"
when Item ZigbeeSwitch01AcMaisonSub received update


    ZigbeeSwitch01AcMaison.sendCommand( ZigbeeSwitch01AcMaisonSub.state )


rule "Zigbee Dimmer Ancienne Maison Salle de Gym mqtt"
when Item ZigbeeDimmerSalGymSub received update


    ZigbeeDimmerSalGym.sendCommand( ZigbeeDimmerSalGymSub.state )


this is creasy no ? :wink:

thanks a lot for your help realy !