Howto use zigbee2mqtt with openHAB, removing proprietary bridges / gateways

Tags: #<Tag:0x00007f616d02bea0> #<Tag:0x00007f616d02bd60> #<Tag:0x00007f616d02bc20>

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

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

Did you install JSONPATH service?

1 Like

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

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

I have followed exactly Kiryl example to add an Ikea Tradfri Button item but I have the following error message:

15:16:32.983 [WARN ] [tt.generic.ChannelStateTransformation] - Transformation service JSONPATH for pattern $.linkquality not found!
15:16:32.983 [WARN ] [hab.binding.mqtt.generic.ChannelState] - Incoming payload ‘{“linkquality”:0,“battery”:74,“click”:“off”}’ not supported by type ‘NumberValue’
15:16:32.983 [WARN ] [tt.generic.ChannelStateTransformation] - Transformation service JSONPATH for pattern $.click not found!
15:16:32.983 [WARN ] [tt.generic.ChannelStateTransformation] - Transformation service JSONPATH for pattern $.battery not found!
15:16:32.983 [WARN ] [hab.binding.mqtt.generic.ChannelState] - Incoming payload ‘{“linkquality”:0,“battery”:74,“click”:“off”}’ not supported by type ‘NumberValue’

The received payload {“linkquality”:0,“battery”:74,“click”:“off”} is JSON friendly and I don’t understand if I have to add a specific transformation file and if yes what should it do?

Have you installed the JSONPATH transformation? It’s an addon you have to install via paperui or the addons file:

It seems like that you have the payload on a NUmber item and not a string? Maybe post your setup?

Otherwise I have about the same setup as Kiryl and my Tradfri buttons are working flawlessly

You are right the JSONPATH addon was missing. How stupid of me…
Many thanks for your quick answer

Yes. Transformation is required. There were some samples in this discussion. But you may simply ignore this error. Everything should be fine.

That’s not completely true. I am running without. No ugly transformations anymore.

You need a quite recent zigbee2mqtt and need to enable the attribute transmission. This removes jsonpath and transmits single attributes.

I have installed Zigbee2mqtt version 1.7.1 but I do not know how to enable the attribute transmission?

experimental:
  output: attribute

I have tried to add that in the zigbee2mqtt configuration.yaml file but with no effect. Also how does it work when there are multiple attributes (click, battery, linkquality for example) for one device?

Strange. That’s exactly how it was described:

Did you restart zigbee2mqtt after changing configuration.yaml?

Quite simple:
image

How does the publish from zigbee2mqtt with attributes then look like? Because if I remember right (it’s a few months back when I configured everything), zigbee2mqtt publishes everything to e.g. statetopic= zigbee2mqtt/cube. So on this you have to filter this publish for the different attributes like battery, action, etc.
Isn’t there json the right thing as its really easy to parse this “string” then?

No, no filter involved. Zigbee2mqtt creates a subtopic for each attribute with its own value. Just look in my screenshot.

If you are interested in details, have a look here:

experimental: output: attribute

After reboot zigbee2mqtt send the payload as expected:

zigbee2mqtt:info  2019-11-26T22:32:58: MQTT publish: topic 'zigbee2mqtt/switch1/linkquality', payload '21'
zigbee2mqtt:info  2019-11-26T22:32:58: MQTT publish: topic 'zigbee2mqtt/switch1/battery', payload '87'
zigbee2mqtt:info  2019-11-26T22:32:58: MQTT publish: topic 'zigbee2mqtt/switch1/click', payload 'on'

I then updated my mqtt.things as followed:

Thing topic switch1 "switch 1" {
Channels:
    Type string : click   [ stateTopic="zigbee2mqtt/switch1/click" ]
}

and kept the .item as it was.
This works but I keep having a warning message:

00:04:38.604 [WARN ] [hab.binding.mqtt.generic.ChannelState] - Command 'off' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.off
00:04:38.604 [INFO ] [smarthome.event.ItemStateChangedEvent] - switch1Click changed from ON to OFF

How could I get rid of that warning?

I would also to get rid of the ZigbeeLogType messages (INFO and WARNING) that appears in my log tail every 2 minutes:

00:04:24.253 [INFO ] [smarthome.event.ItemStateChangedEvent] - ZigbeeLogType changed from devices to groups
00:04:24.269 [WARN ] [nternal.JSonPathTransformationService] - JsonPath expressions with more than one result are only supported for Boolean, Number and String data types, please adapt your selector. Result: [{"ieeeAddr":"0x00124b000be89d05","type":"Coordinator","networkAddress":0,"friendly_name":"Coordinator","softwareBuildID":"zStack12","dateCode":"20190608","lastSeen":1574809464259},{"ieeeAddr":"0xccccccfffe924769","type":"EndDevice","networkAddress":63209,"model":"E1743","friendly_name":"switch2","manufacturerID":4476,"manufacturerName":"IKEA of Sweden","powerSource":"Battery","modelID":"TRADFRI on\/off switch","hardwareVersion":1,"softwareBuildID":"2.2.008","dateCode":"20190410","lastSeen":1574809175502},{"ieeeAddr":"0xccccccfffe2fbaa0","type":"EndDevice","networkAddress":47694,"model":"E1525","friendly_name":"Motion Sensor","manufacturerID":4476,"manufacturerName":"IKEA of Sweden","powerSource":"Battery","modelID":"TRADFRI motion sensor","hardwareVersion":1,"softwareBuildID":"2.0.022","dateCode":"20190308","lastSeen":null},{"ieeeAddr":"0xccccccfffe925007","type":"EndDevice","networkAddress":18691,"model":"E1743","friendly_name":"switch1","manufacturerID":4476,"manufacturerName":"IKEA of Sweden","powerSource":"Battery","modelID":"TRADFRI on\/off switch","hardwareVersion":1,"softwareBuildID":"2.2.008","dateCode":"20190410","lastSeen":1574809438004},{"ieeeAddr":"0x000d6ffffeaf6ff8","type":"Router","networkAddress":48108,"model":"E1603\/E1702","friendly_name":"Prise","manufacturerID":4476,"manufacturerName":"IKEA of Sweden","powerSource":"Mains (single phase)","modelID":"TRADFRI control outlet","hardwareVersion":1,"softwareBuildID":"2.0.022","dateCode":"20190308","lastSeen":1574809454446},{"ieeeAddr":"0x000d6ffffefd566c","type":"Router","networkAddress":4667,"model":"E1603\/E1702","friendly_name":"Prise_Denon","manufacturerID":4476,"manufacturerName":"IKEA of Sweden","powerSource":"Mains (single phase)","modelID":"TRADFRI control outlet","hardwareVersion":1,"softwareBuildID":"2.0.022","dateCode":"20190308","lastSeen":null},{"ieeeAddr":"0x000d6ffffefd4f11","type":"Router","networkAddress":20717,"model":"E1603\/E1702","friendly_name":"Prise_Sony","manufacturerID":4476,"manufacturerName":"IKEA of Sweden","powerSource":"Mains (single phase)","modelID":"TRADFRI control outlet","hardwareVersion":1,"softwareBuildID":"2.0.022","dateCode":"20190308","lastSeen":1574807409334},{"ieeeAddr":"0x000d6ffffefc1b85","type":"Router","networkAddress":6524,"model":"E1603\/E1702","friendly_name":"Eclairage_Armoire","manufacturerID":4476,"manufacturerName":"IKEA of Sweden","powerSource":"Mains (single phase)","modelID":"TRADFRI control outlet","hardwareVersion":1,"softwareBuildID":"2.0.022","dateCode":"20190308","lastSeen":1574808391061},{"ieeeAddr":"0x000d6ffffef51948","type":"EndDevice","networkAddress":963,"model":"E1743","friendly_name":"Switch_Armoire1","manufacturerID":4476,"manufacturerName":"IKEA of Sweden","powerSource":"Battery","modelID":"TRADFRI on\/off switch","hardwareVersion":1,"softwareBuildID":"2.0.020","dateCode":"20180921","lastSeen":null},{"ieeeAddr":"0x000d6ffffef34653","type":"EndDevice","networkAddress":43146,"model":"E1743","friendly_name":"Switch_Armoire2","manufacturerID":4476,"manufacturerName":"IKEA of Sweden","powerSource":"Battery","modelID":"TRADFRI on\/off switch","hardwareVersion":1,"softwareBuildID":"2.2.008","dateCode":"20190410","lastSeen":null}]
00:04:24.269 [INFO ] [smarthome.event.ItemStateChangedEvent] - ZigbeeLogType changed from groups to devices

Any suggestions?

1 Like

@regissg, this thread is about mqtt1 & jsonpath solution. Please use the other thread linked above to discuss attribute transmission.

I am trying to add an ikea tradfri outlet linked through zigbee2mqtt.

I am able to switch it from an openhab sitemap. I am also able to switch it from Alexa but in that case the sitemap does not update the outlet state.

when looking at the MQTT traffic with MQTT.fx I could see that in both case the zigbee2mqtt/Prise/state has the proper ON/OFF payload. Same with the Openhab log tail that shows in both case the proper outlet state

Here is my thing setup:

Thing topic Prise "IKEA prise de test" {
Channels:
    Type switch : PowerSwitch "Ikea Prise" [ stateTopic="zigbee2mqtt/Prise/state", commandTopic="zigbee2mqtt/Prise/set", on="on", off="off" ]
}

my item setup

Switch prise1  "Prise de test"  <switch> { channel="mqtt:topic:myMQTTBroker:Prise:PowerSwitch" , alexa="Switchable"}

and my test sitemap

sitemap demo label="Main Menu" {
Frame {
    Switch item=prise1 
       }
}

What could explain that the sitemap does not to update ?

I want to share experience in Aqara Wireless Switch js rules .
I’m new to it so sorry if something is wrong.

for click

(function(x) {
var json = JSON.parse(x);
result=json.click
if (result == null ) { process.exit(-1); }
return result;
})(input)

and action

(function(x) {
var json = JSON.parse(x);
result=json.action
if (result == null ) { process.exit(-1); }
return result;
})(input)

It works for me. Let me know if something is wrong.