Zigbee2mqtt revisited: No more ugly transformations

what the zigbee device reports only gets shown when the device sends the data. This data is then handled by the converter to interpret. Some devices may always send the linkquality on a regular basis, some not. One helpful tool to check the linkquality is to use the network map. There you see the routes and linkqualities.

As the the log suggests, there was a timeout. Either there was no repsonse by the device and thus the message could not be delivered or the sent command was not recognised. As this is more a zigbee2mqtt than OH issue, I would search on the project’s github page.

I have opened a Issue on their repo. Seems like I am not the only one who gets this error. But should be quite easy to fix from what I understood.

What does your thing look like? So far, I’m only using attributes (works fine) but have added json. But I’m not familar with json and information on color-transformation are a bit tricky to find.

BR Frank

i need some help with the https://www.zigbee2mqtt.io/devices/E1603_E1702.html

This is my Thing

 Thing topic WalloutletCoffeeDevice "Koffie" {
            Type string : state "state"         [ stateTopic="zigbee2mqtt/WalloutletCoffeeDevice/state"] 
            Type string : update_available "update_available"     [ stateTopic="zigbee2mqtt/WalloutletCoffeeDevice/update_available"]   
            Type number : linkquality      "linkquality"     [ stateTopic="zigbee2mqtt/WalloutletCoffeeDevice/linkquality" ]     
    

This is my item

// WalloutletCoffeeDevice
Switch      GF_WalloutletCoffeeDevice_Button_Press              "KoffieAutomaat"                     <button>            (GF_DiningRoom, gButton)     ["Button"]      {channel="mqtt:topic:c99ba5fd:WalloutletCoffeeDevice:state"} 
Number      GF_WalloutletCoffeeDevice_Button_Link               "Link kwalietijd"                 <link>              (gButton)                       ["link"]        {channel="mqtt:topic:c99ba5fd:WalloutletCoffeeDevice:linkquality" }
String      GF_WalloutletCoffeeDevice_Button_update_available   "Update beschhikbaar [%s]"      <softwareupdate>            (gButton)              ["update_available"]     {channel="mqtt:topic:c99ba5fd:WalloutletCoffeeDevice:update_available"} 

The update status and link status is working. But i cant get the switch working.

And does any know how to make a button to update a device software? https://www.zigbee2mqtt.io/information/ota_updates.html

Your switch channel appears to have no commandTopic

oops different device. :frowning:

confused with E1524.

As @rossko57 said, you need a command topic. And you should use a switch channel, not a string. You need something like this:

Type switch : state "state" [ stateTopic = "zigbee2mqtt/WalloutletCoffeeDevice/state", commandTopic = "zigbee2mqtt/WalloutletCoffeeDevice/set/state", on="ON", off="OFF" ]

If you look in the first post, you will find several examples. Many types of devices are covered. Your device is similar to the Osram Plug.

Thank you! i understand it better now. Thought Its is not updating the state. I have to look further.

Edit it works now. I had to restart my pi.

In the past I formatted within the thing, but now I split it and use transformations. With this I only need the colorpicker on the sitemap as it has the toggle already built in. Here is an example

Thing

Thing topic wohnz_Innr_Licht_Stehlampe_Holz "Licht Innr Stehlampe Holz" {
    Channels:
        Type switch : toggleonoff               [ commandTopic="zigbee2mqtt/XX/set", on="ON", off="OFF" ]
        Type colorHSB : colorHSB                [ commandTopic="zigbee2mqtt/XX/set", transformationPatternOut="JS:HSBtoRGB.js" ]
    }

Transformation HSBtoRGB.js

(function (x) {
    if (x=="ON" || x=="INCREASE") {
        return '{"state":"ON","transition":0.3}'
    } else if (x=="OFF" || x=="DECREASE") {
        return '{"state":"OFF","transition":0.3}'
    } else {
        var tex = x.split(',');
        s = parseInt(tex[1]);
        v = parseInt(tex[2]);
        h = parseInt(tex[0]);
    
        h=(!h ? 0 : h/360.0);
        s=(!s ? 0 : s/100.0);
        v=(!v ? 0 : v/100.0);
        i = Math.floor(h * 6);
        f = h * 6 - i;
        p = v * (1 - s);
        q = v * (1 - f * s);
        t = v * (1 - (1 - f) * s);
        switch (i % 6) {
            case 0: r = v, g = t, b = p; break;
            case 1: r = q, g = v, b = p; break;
            case 2: r = p, g = v, b = t; break;
            case 3: r = p, g = q, b = v; break;
            case 4: r = t, g = p, b = v; break;
            case 5: r = v, g = p, b = q; break;
        }
        return '{"brightness":'+ Math.round(v * 255)+',"color":{"rgb":"'+ Math.round(r * 255)+','+ Math.round(g * 255)+','+Math.round(b * 255)+'"},"transition":0.7}'
    }
})(input)
2 Likes

It would be very nice if every one that has a working configuration. Submit it to the zigbee2mqtt GitHub documentation. It is very easy to do. You need to make a Git Hub account.

Search for the device on https://www.zigbee2mqtt.io/information/supported_devices.html

Open the device page. *To contribute to this page, edit the following file

So, i shared my configuration for an MCCGQ01LM Xiaomi MiJia door & window contact sensor (contact) as you suggested on the zigbee2mqtt device page. Lets see if and when it will be merged.
Update: It is already merged. So if someone can check if it is appropriated described.

3 Likes

Danke!

:slight_smile:

Dr. Frank Looff

Frühlingstrasse 8

22525 Hamburg

01523/6366477

BlueMail for Android herunterladen

I have noticed that it allows to indicate the expiration time

  • Xiaomi Aqara human body movement and illuminance sensor RTCGQ11LM thing:
    Thing topic TEMD "TEMD"  @ "TE"
    {
        Channels:
            Type switch : occupancy "occupancy" [ stateTopic = "zigbee2mqtt/TEMD/occupancy", on="true", off="false"  ]
            Type number : illuminance "illuminance" [ stateTopic = "zigbee2mqtt/TEMD/illuminance" ]            
            Type number : voltage "voltage" [ stateTopic = "zigbee2mqtt/TEMD/voltage" ]     
            Type number : battery "battery" [ stateTopic = "zigbee2mqtt/TEMD/battery" ]     
            Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/TEMD/linkquality" ]     
    }
``` Type switch : occupancy "occupancy" [ stateTopic = "zigbee2mqtt/TEMD/occupancy", on="true", off="false" , expire="1m"  ]

I have noticed that it allows to indicate the expiration time

Nice try, but it didn’t work, at least not for me. I changed my thing file, as you suggested to set the expiration time to 1 Minute (which by the way is the most shorted value you can use) and it still expires after 90 seconds which is the default. I mean it is possible, to change the expiration time as described on the manual page, but obviously not like you have described here. It is still possible, that I did something wrong. But I added your , expire="1m" to my working configuration and than commented out the thing in my thing file, saved it and after that removed comment and saved it again.

By the way, this is the workaround instead of restarting OpenHAB when making changes to an exisiting thing by first deleting (commenting it out) the thing and than save the thing file and removing the comment and saving it again, which obviuously recreates a thing instead of just restarting it.

Do you have the Expire binding installed?

By the way expire binding applies over ITEMS not in thing File, if I correctly remember.

I do not think, this will work as expected. Just if you expire before the “occupancy = false” message is sent. If you set it to more than the usual 90 seconds, the standard message will switch the switch off before it expires.

If you want to change the expiration time, you have to to send this as a commandTopic. It will persisted. I remember this feature from the Xiaomi Binding…

Not exactly sure about the command in detail with Mqtt , but definitely not like the code above.

See at zigbee2mqtt: https://www.zigbee2mqtt.io/devices/RTCGQ01LM.html

  • occupancy_timeout : Timeout (in seconds) after the occupancy: false message is sent. If not set, the timeout is 90 seconds. When set to 0 no occupancy: false is send.

IMPORTANT : occupancy_timeout should not be set to lower than 60 seconds. The reason is this: after detecting a motion the sensor ignores any movements for exactly 60 seconds. In case there are movements after this, a new message ( occupancy: true ) will be sent and the sensor will go for one more minute sleep, and so on. This is expected behaviour (see #270). To work around this, ahardware modification is needed.

You’re right.
Thank you Gentlemen. My initial post was a bit premature … I should have read a bit more before posting … :(.

I am trying to solve a commandTopic issue by myself :wink:

Did anyone get something like this working:

Activate Touchlink via a switch or
Factory Reset via Switch.

With

experimental: output: attribute

My THINGS

   Thing topic factory_reset "Z touchlink factory reset" 
        {
        Channels:
            Type switch : factoryreset            [ commandTopic="zigbee2mqtt/bridge/config/touchlink/factory_reset"] 
        }
        Thing topic permit_join "Z touchlink factory reset" 
        {
        Channels:
            Type switch : permit_join            [ stateTopic="zigbee2mqtt/bridge/config/permit_join",on="true", off="false" , commandTopic="zigbee2mqtt/bridge/config/permit_join", on="true", off="false"] 
        }

My ITEMS

Switch zFactroryReset “Zigbee Touchlink Factory Reset” (gXiaomi) { channel=“mqtt:topic:openhabBroker:factory_reset:factoryreset”, expire=“5s,command=OFF”}
Switch zPermitJoin “Zigbee Permit Join 2 min” (gXiaomi) { channel=“mqtt:topic:openhabBroker:permit_join:permit_join”}

Inspired by @Josep_Xavier_Sellart i read a little deeper into the zigbee2mqtt documentation to figure out how to set the expiration time of a zigbee RTCGQ01LM occupancy sensor. So as @chrode mentioned there is a parameter to set the occupancy timeout of the RTCGQ01LM sensor

But this can’t be done on an OpenHAB level, this has to be done on zigbee2mqtt level in the configuration files.
There are two possibilities to set a new occupancy_timeout value for an occupancy sensor:

  1. For all occupancy sensors
    Add to your configuration.yaml of your zigbee2mqtt installation the following two lines:
#set the occupancy timeout for all devices to 120 seconds
device_options:
  occupancy_timeout: 120
  1. For a specific occupancy sensor
    In this case you have to add one line to the specific configuration of the device in the devices: section of the configuration.yaml
devices:
 '0x0000000000000001':
    friendly_name: SomeOtherZigbeeDevice1

 #set the occupancy timeout for a specific device to 120 seconds
 '0x0000000000000002':
    friendly_name: MotionSensorKU
    occupancy_timeout: 120

 '0x0000000000000003':
    friendly_name: SomeOtherZigbeeDevice2

Don’t forget to restart zigbee2mqtt on your linux machine by
sudo systemctl restart zigbee2mqtt

2 Likes