Zigbee2mqtt revisited: No more ugly transformations

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
{r:“255”,g:“0”,b:“0”}

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:

.things

    Thing topic osramrgbbulb "osramrgbbulb" {
    Channels:
        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\"}}" ]
    }     

.items

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

.sitemap

Colorpicker item=WZ_OSRAM_Bulb_Color
9 Likes

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

experimental:
  # 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.

5 Likes

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:

when

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

then

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-(

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

Try it with single quotes:

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

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.

when

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

then
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"
when
    Item Cube_Action received update
then
    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:
“mqtt:topic:broker:0x00158d00015aa9b5:click”
And sometimes like this:
“mqtt:topic:mosquitton:osramrgbbulb:color”
?

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

This post is about getting rid of transformations:

experimental:
  output: attribute

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

1 Like

What version of openhab do you use?
i have the problem with 2.5.2 that i get a value with dezimals.

%s is not working :frowning:

Sorry for the delay, I use 2.5.2 without any problems

do you use the docker container ore do you have installed on a raspberry?