Howto use zigbee2mqtt with openHAB, removing proprietary bridges / gateways

zigbee
mqtt
xiaomi
Tags: #<Tag:0x00007f1e6e2eb038> #<Tag:0x00007f1e6e2ea340> #<Tag:0x00007f1e6e2e9cd8>
(M) #102

Danke!! (Bin auch Deutscher btw)…

0 Likes

(JT) #103

Just wondering if anyone has any experience with the Xiaomi “Vibration” sensor.
Just curious to know if it’s an actual vibration sensor or a more simple tilt and movement sensor.
Anyone know what kind of data is exposed by the sensor?

0 Likes

(Stefan) #104

Continuing the discussion from Howto use zigbee2mqtt with openHAB, removing proprietary bridges / gateways:

I want openHAB control my IKEA tradfri lighting. I am using openHAB 2.4 with the new mqtt binding (2.4). If my understanding is correct, this Howto is designed for the old 1.x binding and I have to do some changes to get things working with 2.4 binding. (I think the MQTT binding in my openhab configuration as well as zigbee2mqtt are working. I use some Aqara sensors which deliver values as expected to openHAB.)

I started with the initial example:

Switch IKEAE27_TOGGLE "IKEAE27 [%s]" <light> {mqtt=">[broker:zigbee/IKEAE27/set:command:*:JS(setZigbeeState.js)],<[broker:zigbee/IKEAE27:state:JSONPATH($.state)]", expire="120m,command=OFF"}

Within PaperUI I created a Generic MQTT Thing for the Ikea tradfri lighting:

IKEA Tradfri 001
Generic MQTT Thing
mqtt:topic:50cfd56d

Then I added some channels (state, brightness, color_temp, …). Here’s what I entered for the state channel:

Channel Type: Text value
Channel id: state
Label: state
MQTT state topic: zigbee2mqtt/0x000b57fffe9dafee
MQTT command topic: zigbee2mqtt/0x000b57fffe9dafee/set
Incoming value transformation: JSONPATH:$.state
IS command: checked 

Here started my problems… Will it work using channel type “Text value” or do I have to use another channel type? And what about the JavaScript transformation (setZigbeeState.js)?

Well, afterwards I created an item as follows:

Switch  FF_Bedroom_Light "Licht Schlafzimmer [%s]" <dimmablelight> { channel="mqtt:topic:50cfd56d:state" }

Neither does my item show any value nor does it send anything via mqtt when I change its state.

0 Likes

(Fraser Howell) #105

You are correct that V2 requires a different setup.

You need to send command to Zigbee2MQTT in JSON format like the below.

{"state":"ON","brightness":255}

That’s what the js files do.

I had some bulbs working in V2 - see post Howto use zigbee2mqtt with openHAB, removing proprietary bridges / gateways

But I had some issues so I went back to V1 and used the scripts from the examples. Now I have some more time I’m having a play to get it working in V2 to my taste.

The above example was done in text files and not PaperUI.

Here’s a screenshot of what on of my bulb items looks like in PaperUI

2 Likes

(Stefan) #106

This was clear to me but I did not know how to post it via MQTT without the JavaScript transformation. Your screenshot saved my life:

Outgoing value format: { "brightness": %s }

I used it in my “state”-channel as follows, which works perfectly with my described switch item:

Outgoing value format: { "state": "%s" }

Thanks a lot for your help!

0 Likes

(None) #108

This one works perfectly for my FL 130C Innr strip. However, I can’t manage to get it to work the same way for color. Do you have an example for this maybe as well?

Regards
Chris

0 Likes

(Fraser Howell) #109

I don’t have any colour bulbs myself so not done any setup for that.

As a side not though, if you are on the latest Dev branch of Zigbee2MQTT you should be able to change the min and max values of the dimmer to 0-255.

The reason I had the Min set to 1 was because there was a bug where if you set he brightness to 0 the bulb still returned a brightness of 1 meaning OpenHAB still thought the bulb was on. This has now been resolved.

0 Likes

(JT) #110

Trying to figure out how to set up the things file for OH2.4
I have my Broker set up in separate things file. It’s working as it’s online and tested

According to documentation on thing files and Generic MQTT things I should be able to do the below. However. If I reference the bridge (mqtt:broker:ohmqtt) it errors. Only way it works is if I don’t define the name and the location “Zigbee2MQTT” @ “Zigbee2MQTT”. The thing name and location works if I don’t reference the bridge but then OH complains there’s no bridge assigned.

Is this a bug in MQTT 2.4?

//Zigbee2MQTT
Thing mqtt:topic:ohmqtt:zigbee2MQTT(mqtt:broker:ohmqtt) "Zigbee2mqtt" @ "Zigbee2MQTT" Channels:
 	Type switch : permitJoin         [ commandTopic="zigbee2mqtt/config/permit_join", On="true", Off="false" ]
 	Type string : state              [ stateTopic="zigbee2mqtt/bridge/state" ]
 	Type string : logType            [ stateTopic="zigbee2mqtt/bridge/log",  transformationPattern="JSONPATH:$.type" ]
 	Type string : logMessage         [ stateTopic="zigbee2mqtt/bridge/log",  transformationPattern="JSONPATH:$.message" ]
     }

Never mind the bridge info needs to come after the name definition of the thing. Makes less sense to me for this format as you would think you’re defining the thing and it’s bridge for the UID before you’d name and locate it.

Thing mqtt:topic:ohmqtt:zigbee2MQTT “Zigbee2mqtt” (mqtt:broker:ohmqtt) @ “Zigbee2MQTT” {

Channels:

0 Likes

(the.neon) #111

Can help with this error message 2019-04-19 21:06:53.987 [WARN ] [eneric.internal.generic.ChannelState] - Command '{ "brightness": 65 }' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{ "brightness": 65 } 2019-04-19 21:06:56.468 [WARN ] [eneric.internal.generic.ChannelState] - Command '{ "brightness": 77 }' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{ "brightness": 77 } 2019-04-19 21:06:58.810 [WARN ] [eneric.internal.generic.ChannelState] - Command '{ "brightness": 67 }' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{ "brightness": 67 } 2019-04-19 21:07:00.659 [WARN ] [eneric.internal.generic.ChannelState] - Command '{ "brightness": 67 }' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{ "brightness": 67 }

items:

Dimmer KitchenLED1 "Küche Licht [%s] " <light> [ "Lighting" ] {channel="mqtt:topic:broker:kitchenled:brightness"}

thing:
Type dimmer : brightness "brightness" [ stateTopic="zigbee2mqtt/0x000d6f001374850c", commandTopic="zigbee2mqtt/0x000d6f001374850c/set", min=1, max=254, step=1, transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{ \"brightness\": %s }" ]

0 Likes

(CM6.5 H102) #112

@the.neon I have a similar config that works without errors.

item:

Dimmer MyLight_Level "My Light Level [%.0f %%]"    <light> ["Lighting"]  { channel="mqtt:topic:pibroker:zigbee2mqtt:dimmer" }

thing:

Type dimmer : dimmer "Dimmer"              [ stateTopic="zigbee/0xb0ce1814030ac279",
                                                    commandTopic="zigbee/0xb0ce1814030ac279/set", transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{\"brightness\":%s}" ]

Maybe try without a spaces in the formatBeforePublish.
Example:
formatBeforePublish="{\"brightness\":%s}" ]

0 Likes

(the.neon) #113

Hi , sorry same error

2019-04-20 18:23:28.984 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:23:28.990 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:23:29.005 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:23:30.650 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:23:30.914 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:23:30.920 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:23:30.929 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:45:04.343 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘rothmund.sitemap’

2019-04-20 18:46:00.013 [INFO ] [eclipse.smarthome.model.script.Scene] - Blinds Eltern 99

2019-04-20 18:47:20.400 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘mqtt.things’

2019-04-20 18:48:10.074 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘{ “brightness”: 29 }’ not supported by type ‘OnOffValue’: No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{ “brightness”: 29 }

2019-04-20 18:48:23.981 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘{ “brightness”: 0 }’ not supported by type ‘OnOffValue’: No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{ “brightness”: 0 }

2019-04-20 18:48:24.250 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:48:24.478 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:48:33.259 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:48:33.546 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:48:33.553 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:48:33.559 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:48:34.509 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:48:34.759 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:48:34.766 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

2019-04-20 18:48:34.772 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘0’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

^[[A^C

0 Likes

(CM6.5 H102) #114

Try without the part below and see if that works.

 min=1, max=254, step=1, 

Use only this:

Type dimmer : brightness "brightness" [ stateTopic="zigbee2mqtt/0x000d6f001374850c", commandTopic="zigbee2mqtt/0x000d6f001374850c/set", transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{ \"brightness\": %s }" ]
0 Likes

(frookt) #115

What am I doing wrong?

tail -f /var/log/openhab2/openhab.log /var/log/openhab2/events.log

2019-05-02 00:49:34.613 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service JSONPATH for pattern $.action not found!

2019-05-02 00:49:34.617 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service JSONPATH for pattern $.linkquality not found!

2019-05-02 00:49:34.620 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"linkquality":134,"from_side":0,"to_side":2,"side":5,"angle":24.64,"battery":62,"voltage":2935,"action":"wakeup"}' not supported by type 'NumberValue'

2019-05-02 00:49:34.623 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service JSONPATH for pattern $.voltage not found!

2019-05-02 00:49:34.625 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"linkquality":134,"from_side":0,"to_side":2,"side":5,"angle":24.64,"battery":62,"voltage":2935,"action":"wakeup"}' not supported by type 'NumberValue'

==> /var/log/openhab2/events.log <==

2019-05-02 00:49:34.626 [vent.ItemStateChangedEvent] - ZigbeeCubeAction changed from {"linkquality":131,"from_side":0,"to_side":2,"side":5,"angle":24.64,"battery":62,"voltage":2935,"action":"flip90"} to {"linkquality":134,"from_side":0,"to_side":2,"side":5,"angle":24.64,"battery":62,"voltage":2935,"action":"wakeup"}

==> /var/log/openhab2/openhab.log <==

2019-05-02 00:49:34.628 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service JSONPATH for pattern $.battery not found!

2019-05-02 00:49:34.632 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"linkquality":134,"from_side":0,"to_side":2,"side":5,"angle":24.64,"battery":62,"voltage":2935,"action":"wakeup"}' not supported by type 'NumberValue'

2019-05-02 00:49:35.137 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service JSONPATH for pattern $.action not found!

2019-05-02 00:49:35.145 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service JSONPATH for pattern $.linkquality not found!

==> /var/log/openhab2/events.log <==

2019-05-02 00:49:35.156 [vent.ItemStateChangedEvent] - ZigbeeCubeAction changed from {"linkquality":134,"from_side":0,"to_side":2,"side":5,"angle":24.64,"battery":62,"voltage":2935,"action":"wakeup"} to {"linkquality":126,"from_side":2,"to_side":3,"side":5,"angle":24.64,"battery":62,"voltage":2935,"action":"flip90"}

==> /var/log/openhab2/openhab.log <==

2019-05-02 00:49:35.163 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"linkquality":126,"from_side":2,"to_side":3,"side":5,"angle":24.64,"battery":62,"voltage":2935,"action":"flip90"}' not supported by type 'NumberValue'

2019-05-02 00:49:35.168 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service JSONPATH for pattern $.voltage not found!

2019-05-02 00:49:35.173 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"linkquality":126,"from_side":2,"to_side":3,"side":5,"angle":24.64,"battery":62,"voltage":2935,"action":"flip90"}' not supported by type 'NumberValue'

2019-05-02 00:49:35.188 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service JSONPATH for pattern $.battery not found!

2019-05-02 00:49:35.192 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"linkquality":126,"from_side":2,"to_side":3,"side":5,"angle":24.64,"battery":62,"voltage":2935,"action":"flip90"}' not supported by type 'NumberValue'

zigbee.items

// Xiaomi Aqara wireless buttons WXKG01LM
Group  gZigbeeCube    "Zigbee Cube"

String ZigbeeCubeAction         "Cube action [%s]"              <action>    (gZigbeeCube) { channel="mqtt:topic:OpenHab:cube:action" }
Number ZigbeeCubeLinkQuality    "Cube Link Quality [%d]"        <network>   (gZigbeeCube) { channel="mqtt:topic:OpenHab:cube:battery" }
Number ZigbeeCubeVoltage        "Cube Voltage [%d mV]"          <energy>    (gZigbeeCube) { channel="mqtt:topic:OpenHab:cube:voltage" }
Number ZigbeeCubeBattery        "Cube Battery [%.1f %%]"        <battery>   (gZigbeeCube) { channel="mqtt:topic:OpenHab:cube:battery" }

mqttConnections.things

//Aqara smart cube
    Thing topic cube "Aqara Smart Cube" {
    Channels:
        Type string : action "Action"       [ stateTopic="zigbee2mqtt/cube", transformationPattern="JSONPATH:$.action"]
        Type number : voltage "Voltage"     [ stateTopic="zigbee2mqtt/cube", transformationPattern="JSONPATH:$.voltage"]
        Type number : battery "Battery"     [ stateTopic="zigbee2mqtt/cube", transformationPattern="JSONPATH:$.battery"]
        Type number : linkquality           [ stateTopic="zigbee2mqtt/cube", transformationPattern="JSONPATH:$.linkquality" ]
    }
0 Likes

(Udo Hartmann) #116

Did you install JSONPATH service?

1 Like

(frookt) #117

Thank you so much. Everywhere it is written how to do but it is not written that you need to activate JSONPATH

0 Likes

(JT) #118

I finally got a vibration sensor to play with.
I use it to detect if my Dryer is on so I simplified the outputs of the sensor with the following transformation.
I have it set to high sensitivity and it’s pretty accurate for detecting the ON/OFF State.

setZ2MAction.js

(function(x){

    var result = "OFF";
 
    var json = JSON.parse(x);  
    if (json.action == "vibration") 
    {
        result="ON";
    } 
    else 
    {
        result="OFF";
    }

    return result;
    
})(input)

The other applicable actions that get reported are “tilt” or “drop” so you can parse for that as well and return their value.

A js transform is needed to handle “angle” because it not always updated, only updated when changed and action is tilt.

The rest of the outputs can be parsed with json.path
angle_x
angle_y
angle_z
angle_x_absolute
ange_y_absolute
battery
voltage
linkquality

0 Likes