Zigbee2mqtt revisited: No more ugly transformations

details about color are here : https://github.com/Koenkk/zigbee-herdsman-converters/blob/edd4ce980975e76792b153c1df8d4e2c2b04e0e4/converters/toZigbee.js#L376 (also this Pull Request https://github.com/Koenkk/zigbee2mqtt/pull/2441).

That mean that we can set the color with an MQTT command like :
zigbee2mqtt/0x0017880102320dd8/set/color #FF0000 because of the condition || (typeof value === 'string' && value.startsWith('#')))
But we can’t do zigbee2mqtt/0x0017880102320dd8/set/color 100,100,100 because the condition require a Property (a JSON key).
As OpenHAB can only send colorRGB and colorHUE values, for now, there is no solution to control the color of a bulb without ugly transformation.

I would love to write a Pull Request to z2m but there is no easy way to distinguish RGB (255,255,255) values from HSB one (360,100,100).
Other solution would be to found a simple way to send color as Hex (#FF0000) from OpenHAB.

1 Like

Yeah I’ve just been struggling with how to set the colour of a Philips Hue RGB bulb… I’m keen to see if anyone has any smart ideas…

What does the structure in zigbee2mqtt look like?

7 posts were merged into an existing topic: Zigbee2mqtt and Zigbee bulbs small tutorial

Nobody knows the structure of color bulbs in zigbee2mqtt with attribute output enabled? So nobody connected a color bulb yet?

It works multiple ways, I think RGB is the easiest:
zigbee2mqtt/item/set/color with the value in RGB hex (so #FF0000 will be full red). I’m currently trying to figure out how to make it work with the colorpicker because it works from mqtt but the colorpicker wants to send these hue & saturation values that I don’t fully understant.
It also works with JSON providing the values in this format

Funny, no matter what combination I use: I have Closed when I should have OPEN and OPEN when I should have CLOSED.

the new version zigbee2mqtt 1.9.0 supports: "color values in HSB/HSV/HSL notation"

    // Hue, saturation, brightness (in HSB space)
    "hsb": "360,100,100"

At the moment it seems you can not set HSB/HSV/HUE value directly. You still have to use JSON with surrounding ‘color’ tag. So it’s now working with a small formatting, but without ugly transformation.

here is the working configuration for my Osram RGBW bulb:


    Thing topic osramrgbbulb "osramrgbbulb" {
        Type switch : power "Power" [ stateTopic = "zigbee2mqtt/0x7cb03eaa00ada0df/state", commandTopic = "zigbee2mqtt/0x7cb03eaa00ada0df/set/", on="ON", off="OFF" ]
        Type string : color "Color" [  stateTopic = "zigbee2mqtt/0x7cb03eaa00ada0df/color-hsb", commandTopic="zigbee2mqtt/0x7cb03eaa00ada0df/set" , formatBeforePublish="{\"color\":{\"hsb\": \"%s\"}}" ]


String WZ_OSRAM_Bulb_Color  "WZ_OSRAM_Bulb_Color"  <light> { channel="mqtt:topic:mosquitton:osramrgbbulb:color"}


Colorpicker item=WZ_OSRAM_Bulb_Color

The new version 1.9.0 now also supports output of payloads as JSON and plain attributes with the following option in configuration.yaml:

  # Optional: MQTT output type: json, attribute or json_and_attribute (default: shown below)
  # Examples when 'state' of a device is published
  # json: topic: 'zigbee2mqtt/my_bulb' payload '{"state": "ON"}'
  # attribute: topic 'zigbee2mqtt/my_bulb/state' payload 'ON"
  # json_and_attribute: both json and attribute (see above)
  output: 'json'

There is a error in the documentation, the option is called “attribute_and_json” and works as expected, payload is transmitted in both flavours.
That will help me with migrating from MQTT 1 to MQTT 2.x as well as from JSON to plain attributes.


How i can define Trigger type channel?
I try to use:

Type trigger  : action  "action"  [ stateTopic = "zigbee2mqtt/xiaomi_cube/action"]

but i have an error:
20:34:27.098 [ERROR] [l.thing.internal.GenericThingProvider] - Channel type mqtt:trigger could not be resolved.

I need to use it in rules like this:


Channel "mqtt:topic:be6e02f3:Cube:action" triggered


Have a look at the Ikea remote. This has an action channel as well. This is a simple string channel, the string is related to the type of action.

1 Like

Thank you very much, @job. Please share your rule example how catch events from action channel? What is event to catch action? item update or changed?

i try this, but it does not work-(

    Channel "mqtt:topic:be6e02f3:Cube:action" triggered

Try it with single quotes:

    Channel 'mqtt:topic:be6e02f3:Cube:action' triggered

I’m not 100% sure if that will make a difference but it’s what I use and it works so worth a try. Also what is triggered? You may need to add that after the word triggered like below where START is used.


Channel 'astro:sun:local:civilDusk#event' triggered START

1 Like

I don’t use trigger channel, i just trigger on item change. Just create the item based on the channel and trigger on the item.

Check the string within the rule.

1 Like

Thank you,friends. I used item based driven rules and this work fine for me.

 rule "Zigbee2Mqtt Cube action"
    Item Cube_Action received update
    logError("xiaomicube", "cube action fired")
    switch(Cube_Action.state.toString) {
        case "slide": {

Newb here, how does channel referencing work? Where can I RTFM it?

First post and

Sorry, I should have been clearer when asking: I don’t get the ITEMS part specifically.
I understand how “thing” references mqtt channel.
E.g. zigee2mqtt//… etc

But having defined things, why does one need to reference items like this:
And sometimes like this:

It’s up to you how you define the channels:

This post is about getting rid of transformations:

  output: attribute

Do items reference channels directly, or rather channels within things (not really via mqtt)?