# Zigbee2mqtt command

**URL:** <https://community.openhab.org/t/zigbee2mqtt-command/70105>\
**Category:** Bindings\
**Created:** [March 13, 2019, 12:47am UTC](https://community.openhab.org/t/zigbee2mqtt-command/70105 "2019-03-13T00:47:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![medalle23](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@medalle23](https://community.openhab.org/u/medalle23)\
**Post date:** [March 13, 2019, 12:47am UTC](https://community.openhab.org/t/zigbee2mqtt-command/70105/1 "2019-03-13T00:47:48Z")

</div>

Hello,I searched in vain how to write a post, that’s why I write to you directly inbox  
i have problem with zigbee2mqtt.  
i use xiaomi aqara device. For aqara switch, (wall switch, socket plug, wireless switch).. i don’t understand how to send command. i can’t control device via openhab. please help

.thing file

```csv
Bridge mqtt:broker:mybroker [host="localhost", port=1883, secure=false]
{
// Door sensors
Thing topic doorsensor1 "doorsensor1" {
Channels:
    Type contact : contact "Contact" [stateTopic="zigbee2mqtt/doorsensor1", transformationPattern="JS:getZigbeeContact2Contact.js"]
    Type number : voltage "Voltage" [stateTopic="zigbee2mqtt/doorsensor1", transformationPattern="JSONPATH:$.voltage"]
    Type number : battery "Battery" [stateTopic="zigbee2mqtt/doorsensor1", transformationPattern="JSONPATH:$.battery"]
    Type number : linkquality "Linkquality" [stateTopic="zigbee2mqtt/doorsensor1", transformationPattern="JSONPATH:$.linkquality"]

}

Thing topic wirelessdoubleswitch1 "wirelessdoubleswitch1" {
Channels:
    Type string : click "Click" [stateTopic="zigbee2mqtt/wirelessdoubleswitch1", commandTopic="zigbee2mqtt/wirelessdoubleswitch1/system/set", transformationPattern="JS:getZigbeeClick.js"]
    Type number : voltage "Voltage" [stateTopic="zigbee2mqtt/wirelessdoubleswitch1", transformationPattern="JSONPATH:$.voltage"]
    Type number : battery "Battery" [stateTopic="zigbee2mqtt/wirelessdoubleswitch1", transformationPattern="JSONPATH:$.battery"]
    Type number : linkquality "Linkquality" [stateTopic="zigbee2mqtt/wirelessdoubleswitch1", transformationPattern="JSONPATH:$.linkquality"]
}

Thing topic wallsocketplug1 "wallsocketplug1" {
Channels:
    Type switch : command "State" [stateTopic="zigbee2mqtt/wallsocketplug1", commandTopic="zigbee2mqtt/wallsocketplug1/system/set", transformationPattern="JSONPATH:$.power"]
    Type number : power "Power" [stateTopic="zigbee2mqtt/wallsocketplug1", transformationPattern="JSONPATH:$.power"] 
    Type number : voltage "Voltage" [stateTopic="zigbee2mqtt/wallsocketplug1", transformationPattern="JSONPATH:$.consumption"]
    Type number : temperature "Temperature" [stateTopic="zigbee2mqtt/wallsocketplug1", transformationPattern="JSONPATH:$.temperature"]
    Type number : battery "Battery" [stateTopic="zigbee2mqtt/wallsocketplug1", transformationPattern="JSONPATH:$.battery"]
    Type number : linkquality "Linkquality" [stateTopic="zigbee2mqtt/wallsocketplug1", transformationPattern="JSONPATH:$.linkquality"]
}

Thing topic wallsingleswitch1 "wallsingleswitch1" {
Channels:
    Type switch : command "State" [stateTopic="zigbee2mqtt/wallsingleswitch1", commandTopic="zigbee2mqtt/wallsingleswitch1/state"]
    Type number : power "Power" [stateTopic="zigbee2mqtt/wallsingleswitch1", transformationPattern="JSONPATH:$.power"] 
    Type number : voltage "Voltage" [stateTopic="zigbee2mqtt/wallsingleswitch1", transformationPattern="JSONPATH:$.consumption"]
    Type number : temperature "Temperature" [stateTopic="zigbee2mqtt/wallsingleswitch1", transformationPattern="JSONPATH:$.temperature"]
    Type number : battery "Battery" [stateTopic="zigbee2mqtt/wallsingleswitch1", transformationPattern="JSONPATH:$.battery"]
    Type number : linkquality "Linkquality" [stateTopic="zigbee2mqtt/wallsingleswitch1", transformationPattern="JSONPATH:$.linkquality"]
}

/*
Thing topic aqaradoorsensor2 "Door Sensor 2" @ "Upper Floor" {
        Channels:
            Type contact : status "Status" [stateTopic="mqtt/zigbee2mqtt/Aqara_DoorSensor2", transformationPattern="JS:doorsensor.js"]
            Type number : voltage "Voltage"[stateTopic="mqtt/zigbee2mqtt/Aqara_DoorSensor2", transformationPattern="JSONPATH:$.voltage"]
            Type number : battery "Battery"[stateTopic="mqtt/zigbee2mqtt/Aqara_DoorSensor2", transformationPattern="JSONPATH:$.battery"]
            Type number : linkquality "RSSI"[stateTopic="mqtt/zigbee2mqtt/Aqara_DoorSensor2", transformationPattern="JSONPATH:$.linkquality"]

    } 
*/

// Weather sensors
Thing topic humiditysensor1 "humiditysensor1" {
Channels:
    Type number : temperature "Temperature" [stateTopic="zigbee2mqtt/humiditysensor1", transformationPattern="JSONPATH:$.temperature"]
    Type number : humidity "Humidity" [stateTopic="zigbee2mqtt/humiditysensor1", transformationPattern="JSONPATH:$.humidity"]
    Type number : pressure "Pressure" [stateTopic="zigbee2mqtt/humiditysensor1", transformationPattern="JSONPATH:$.pressure"]
    Type number : voltage "Voltage" [stateTopic="zigbee2mqtt/humiditysensor1", transformationPattern="JSONPATH:$.voltage"]
    Type number : battery "Battery" [stateTopic="zigbee2mqtt/humiditysensor1", transformationPattern="JSONPATH:$.battery"]
    Type number : linkquality "Linkquality" [stateTopic="zigbee2mqtt/humiditysensor1", transformationPattern="JSONPATH:$.linkquality"]

}

//Motion sensors
Thing topic motionsensor1 "motionsensor1" {
Channels:
    Type switch : motion "Motion" [stateTopic="zigbee2mqtt/motionsensor1", transformationPattern="JS:getZigbeeOccupancy2Switch.js"]
    Type number : brightness "Brightness" [stateTopic="zigbee2mqtt/motionsensor1", transformationPattern="JSONPATH:$.illuminance"]
    Type number : voltage "Voltage" [stateTopic="zigbee2mqtt/motionsensor1", transformationPattern="JSONPATH:$.voltage"]
    Type number : battery "Battery" [stateTopic="zigbee2mqtt/motionsensor1", transformationPattern="JSONPATH:$.battery"]
    Type number : linkquality "Linkquality" [stateTopic="zigbee2mqtt/motionsensor1", transformationPattern="JSONPATH:$.linkquality"]
}

/*
//Water Sensors
Thing topic watersensormeteringcloset "WaterSensorMeteringCloset" {
Channels:
    Type contact : contact "Contact" [stateTopic="zigbee2mqtt/LeakageMeteringCloset", transformationPattern="JS:getZigbeeLeak2Contact.js"]
    Type number : voltage "Voltage" [stateTopic="zigbee2mqtt/LeakageMeteringCloset", transformationPattern="JSONPATH:$.voltage"]
    Type number : battery "Battery" [stateTopic="zigbee2mqtt/LeakageMeteringCloset", transformationPattern="JSONPATH:$.battery"]
}
*/
}

```

.items

```csv
// Xiaomi Aqara wireless buttons WXKG01LM
Group gZigbeeButton "Zigbee Buttons"

String WirelessDoubleSwitch1Button "Click [%s]" <button> (gZigbeeButton) ["Switchable"] { channel="mqtt:topic:mybroker:wirelessdoubleswitch1:click" }
Number WirelessDoubleSwitch1LinkQuality "Réseau [%d]" <network> (gZigbeeButton) { channel="mqtt:topic:mybroker:wirelessdoubleswitch1:linkquality" }
Number WirelessDoubleSwitch1Voltage "Voltage [%d mV]" <energy> (gZigbeeButton) { channel="mqtt:topic:mybroker:wirelessdoubleswitch1:voltage" }
Number WirelessDoubleSwitch1Battery "Batterie [%.1f %%]" <battery> (gZigbeeButton) { channel="mqtt:topic:mybroker:wirelessdoubleswitch1:battery" }

// Xiaomi Aqara temperature, humidity and pressure sensor WSDCGQ11LM
Group gZigbeeSensor "Zigbee Sensors"

Number HumiditySensor1Temperature "Temperature [%.2f °C]" <temperature> (gZigbeeSensor) ["CurrentTemperature"] { channel="mqtt:topic:mybroker:humiditysensor1:temperature" }
Number HumiditySensor1Humidity "Humidité [%.2f %%]" <humidity> (gZigbeeSensor) ["CurrentHumidity"] { channel="mqtt:topic:mybroker:humiditysensor1:humidity" }
Number HumiditySensor1Pressure "Pression [%d hPa]" <pressure> (gZigbeeSensor) { channel="mqtt:topic:mybroker:humiditysensor1:pressure" }
Number HumiditySensor1Voltage "Voltage [%d mV]" <energy> (gZigbeeSensor) { channel="mqtt:topic:mybroker:humiditysensor1:voltage" }
Number HumiditySensor1Battery "Batterie [%.1f %%]" <battery> (gZigbeeSensor) { channel="mqtt:topic:mybroker:humiditysensor1:battery" }
Number HumiditySensor1LinkQuality "Réseau [%d]" <qualityofservice> (gZigbeeSensor) { channel="mqtt:topic:mybroker:humiditysensor1:linkquality" }

Contact DoorSensor1 "Porte [%s]" <door> (gZigbeeSensor) ["Switchable"] { channel="mqtt:topic:mybroker:doorsensor1:contact" }
Number DoorSensor1Voltage "Voltage [%d mV]" <energy> (gZigbeeSensor) { channel="mqtt:topic:mybroker:doorsensor1:voltage" }
Number DoorSensor1Battery "Batterie [%.1f %%]" <battery> (gZigbeeSensor) { channel="mqtt:topic:mybroker:doorsensor1:battery" }
Number Doorsensor1LinkQuality "Réseau [%d]" <qualityofservice> (gZigbeeSensor) { channel="mqtt:topic:mybroker:doorsensor1:linkquality" }

String MotionSensor1 "Mouvement [%s]" <motion> (gZigbeeSensor) ["Switchable"] { channel="mqtt:topic:mybroker:motionsensor1:motion" }
Number MotionSensor1Brightness "Luminescance [%d lumen]" <sun> (gZigbeeSensor) { channel="mqtt:topic:mybroker:motionsensor1:brightness" }
Number MotionSensor1Voltage "Voltage [%d mV]" <energy> (gZigbeeSensor) { channel="mqtt:topic:mybroker:motionsensor1:voltage" }
Number MotionSensor1Battery "Batterie [%.1f %%]" <battery> (gZigbeeSensor) { channel="mqtt:topic:mybroker:motionsensor1:battery" }
Number MotionSensor1LinkQuality "Réseau [%d]" <qualityofservice> (gZigbeeSensor) { channel="mqtt:topic:mybroker:motionsensor1:linkquality" }

Switch WallSocketPlug1 "Etat [%s]" <poweroutlet_eu> (gZigbeeSensor) ["Switchable"] { channel="mqtt:topic:mybroker:wallsocketplug1:command" }
Number WallSocketPlug1Power "Puissance [%d watt]" <line> (gZigbeeSensor) { channel="mqtt:topic:mybroker:wallsocketplug1:power" }
Number WallSocketPlug1Voltage "Voltage [%d mV]" <energy> (gZigbeeSensor) { channel="mqtt:topic:mybroker:wallsocketplug1:voltage" }
Number WallSocketPlug1Temperature "Temperature [%.2f °C]" <temperature> (gZigbeeSensor) { channel="mqtt:topic:mybroker:wallsocketplug1:temperature" }
Number WallSocketPlug1Consumption "Batterie [%.1f %%]" <line> (gZigbeeSensor) { channel="mqtt:topic:mybroker:wallsocketplug1:consumption" }
Number WallSocketPlug1LinkQuality "Réseau [%d]" <qualityofservice> (gZigbeeSensor) { channel="mqtt:topic:mybroker:wallsocketplug1:linkquality" }

Switch WallSingleSwitch1 "Etat [%s]" <light> (gZigbeeSensor) ["Switchable"] { channel="mqtt:topic:mybroker:wallsingleswitch1:command:ON" }
Number WallSingleSwitch1Power "Puissance [%d watt]" <line> (gZigbeeSensor) { channel="mqtt:topic:mybroker:wallsingleswitch1:power" }
Number WallSingleSwitch1Voltage "Voltage [%d mV]" <energy> (gZigbeeSensor) { channel="mqtt:topic:mybroker:wallsingleswitch1:voltage" }
Number WallSingleSwitch1Temperature "Temperature [%.2f °C]" <temperature> (gZigbeeSensor) { channel="mqtt:topic:mybroker:wallsingleswitch1:temperature" }
Number WallSingleSwitch1Consumption "Batterie [%.1f %%]" <line> (gZigbeeSensor) { channel="mqtt:topic:mybroker:wallsingleswitch1:consumption" }
Number WallSingleSwitch1LinkQuality "Réseau [%d]" <qualityofservice> (gZigbeeSensor) { channel="mqtt:topic:mybroker:wallsingleswitch1:linkquality" }

```

---

<div class="post-metadata">

**Author:** ![vzorglub](https://community.openhab.org/user_avatar/community.openhab.org/vzorglub/32/17166_2.png) [@vzorglub](https://community.openhab.org/u/vzorglub)\
**Post date:** [March 13, 2019, 7:41am UTC](https://community.openhab.org/t/zigbee2mqtt-command/70105/2 "2019-03-13T07:41:31Z")

</div>



---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [March 15, 2019, 12:32am UTC](https://community.openhab.org/t/zigbee2mqtt-command/70105/3 "2019-03-15T00:32:18Z")

</div>

I suggest starting with a single device such as the wallsocketplug1. After successfully switching the device on and off then work to add the other values.

Once you have a single device and all it’s values working move to the next device.

---

<div class="post-metadata">

**Author:** ![mokoshakalaka](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/a88e57/32.png) [@mokoshakalaka](https://community.openhab.org/u/mokoshakalaka)\
**Post date:** [April 10, 2019, 7:13am UTC](https://community.openhab.org/t/zigbee2mqtt-command/70105/4 "2019-04-10T07:13:54Z")

</div>

Hi,

I had the same problem trying to get the Xiaomi Aqara socket (ZNCZ02LM) going on openhab using zigbee2mqtt.

I don’t know if you have figured it out yet but the type in your things file:

```csv
Type switch : command "State" [stateTopic="zigbee2mqtt/wallsocketplug1", commandTopic="zigbee2mqtt/wallsocketplug1/system/set", transformationPattern="JSONPATH:$.power"]

```

You need to:

1.) Remove “system” from your commandTopic (see zigbee2mqtt documentation under “zigbee2mqtt/[DEVICE\_ID]/set” section: [Zigbee2MQTT](https://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html))  
2.) Add , on=“ON”, off=“OFF” parameters

```csv
Type switch : command "State" [stateTopic="zigbee2mqtt/wallsocketplug1", commandTopic="zigbee2mqtt/wallsocketplug1/set", on="ON", off="OFF"]

```

My Setup is as follows:

**Zigbee2mqtt Configuration:** (/opt/zigbee2mqtt/data/configuration.yaml)

```csv
devices:
  '0x00158d0002165834':
    friendly_name: aqara_socket_1
    retain: false

```

**Things:** (aqara\_sockets.thing)

```csv
Bridge mqtt:broker:mosquitto [host="192.X.X.X", secure=false, username="user", password="pass"] {
    // Aqara Socket 1
    Thing topic zigbeeAqaraSocket1 "Living Room Socket" {
    Channels:
        Type switch : state [stateTopic="zigbee2mqtt/aqara_socket_1", commandTopic="zigbee2mqtt/aqara_socket_1/set", on="ON", off="OFF"]
        Type number : temperature [stateTopic="zigbee2mqtt/aqara_socket_1", transformationPattern="JSONPATH:$.temperature"]
        Type number : consumption [stateTopic="zigbee2mqtt/aqara_socket_1", transformationPattern="JSONPATH:$.consumption"]
        Type number : voltage [stateTopic="zigbee2mqtt/aqara_socket_1", transformationPattern="JSONPATH:$.voltage"]
        Type number : power [stateTopic="zigbee2mqtt/aqara_socket_1", transformationPattern="JSONPATH:$.power"]
        Type number : linkquality [stateTopic="zigbee2mqtt/aqara_socket_1", transformationPattern="JSONPATH:$.linkquality"]
    }
}

```

**Items:** (aqara\_sockets.item)

```csv
// Xiaomi Aqara socket ZNCZ02LM
Group gZigbeeAqaraSocket1 "Zigbee Aqara Socket 1"

Switch ZigbeeAqaraSocket1State "Living Room Socket State [%s]" <poweroutlet> (gZigbeeAqaraSocket1) ["Switchable"] { channel="mqtt:topic:mosquitto:zigbeeAqaraSocket1:state" }
Number ZigbeeAqaraSocket1Temperature "Living Room Socket Temperature [%.1f °C]" <temperature> (gZigbeeAqaraSocket1) ["CurrentTemperature"] { channel="mqtt:topic:mosquitto:zigbeeAqaraSocket1:temperature" }
Number ZigbeeAqaraSocket1LinkQuality "Living Room Socket Link Quality [%d]" <network> (gZigbeeAqaraSocket1) { channel="mqtt:topic:mosquitto:zigbeeAqaraSocket1:linkquality" }
Number ZigbeeAqaraSocket1Voltage "Living Room Socket Voltage [%d mV]" <energy> (gZigbeeAqaraSocket1) { channel="mqtt:topic:mosquitto:zigbeeAqaraSocket1:voltage" }
Number ZigbeeAqaraSocket1Power "Living Room Socket Power [%d mV]" <energy> (gZigbeeAqaraSocket1) { channel="mqtt:topic:mosquitto:zigbeeAqaraSocket1:power" }
Number ZigbeeAqaraSocket1Consumption "Living Room Socket Consumption [%d mV]" <energy> (gZigbeeAqaraSocket1) { channel="mqtt:topic:mosquitto:zigbeeAqaraSocket1:consumption" }

```

**Sitemap:** (aqara\_sockets.sitemap)

```csv
sitemap aqara_sockets label="Smart Sockets" {
    Frame label="Zigbee devices" {
        Group item=gZigbeeAqaraSocket1
    }
}

```

**Logs:**

In Basic UI, when you toggle the switch, you should see something similar in the openhab event log ([http://openhabianpi:9001/](http://openhabianpi:9001/))

```csv
2019-04-10 02:15:00.699 [ome.event.ItemCommandEvent] - Item 'ZigbeeAqaraSocket1State' received command ON

2019-04-10 02:15:00.717 [nt.ItemStatePredictedEvent] - ZigbeeAqaraSocket1State predicted to become ON

2019-04-10 02:15:00.751 [vent.ItemStateChangedEvent] - ZigbeeAqaraSocket1State changed from NULL to ON

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

2019-04-10 02:15:00.953 [WARN] [eneric.internal.generic.ChannelState] - Command '{"state":"ON","linkquality":78,"power":0,"voltage":227.8,"consumption":0,"temperature":25}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"state":"ON","linkquality":78,"power":0,"voltage":227.8,"consumption":0,"temperature":25}

```

And in your zigbee2mqtt log (/opt/zigbee2mqtt/data/log/2019-04-10.02-06-10/log.txt) you should see:

```csv
4/10/2019, 2:15:00 AM - info: Zigbee publish to device '0x00158d0002165834', genOnOff - on - {} - {"manufSpec":0,"disDefaultRsp":0} - null
4/10/2019, 2:15:00 AM - info: MQTT publish: topic 'zigbee2mqtt/aqara_socket_1', payload '{"state":"ON","linkquality":78,"power":0,"voltage":227.8,"consumption":0,"temperature":25}'

```

---

<div class="post-metadata">

**Author:** ![TommySharp](https://community.openhab.org/user_avatar/community.openhab.org/tommysharp/32/2171_2.png) [@TommySharp](https://community.openhab.org/u/TommySharp)\
**Post date:** [October 19, 2019, 8:52pm UTC](https://community.openhab.org/t/zigbee2mqtt-command/70105/5 "2019-10-19T20:52:33Z")

</div>

Any tips on how to do this all in the items file?  
It’s just MQTT so should be possible…

---

<div class="post-metadata">

**Author:** ![job](https://community.openhab.org/user_avatar/community.openhab.org/job/32/37738_2.png) [@job](https://community.openhab.org/u/job)\
**Post date:** [October 20, 2019, 9:32am UTC](https://community.openhab.org/t/zigbee2mqtt-command/70105/6 "2019-10-20T09:32:05Z")

</div>

If you use the mqtt1 binding, all the information has to be stored in the items file.

With mqtt2 this is not possible because the topic structure is defined on thing level. The item level just references it.

Here are plenty of examples to use zigbee2mqtt with the mqtt1 binding. You can use JSONPATH transformation directly, but I decided against because of the dynamic message structure and constant exception due to that.

> [@Howto use zigbee2mqtt with openHAB, removing proprietary bridges / gateways](https://community.openhab.org/t/howto-use-zigbee2mqtt-with-openhab-removing-proprietary-bridges-gateways/48768):
>
> If you want to use zigbee2mqtt with openHAB, please advance to the next level. The following is a far nicer implementation of the same stuff, just with the mqtt2 binding and a new option of zigbee2mqtt The old stuff, if you prefer the mqtt1 binding and too many tranformations, please go ahead. Recently io discovered [zigbee2mqtt](https://github.com/Koenkk/zigbee2mqtt/blob/master/README.md), which made me think of getting rid of my hue bridge and being able to use a large number of cheap sensors. This works pretty well. I already joined 15 devices (inclu…

---

<div class="post-metadata">

**Author:** ![TommySharp](https://community.openhab.org/user_avatar/community.openhab.org/tommysharp/32/2171_2.png) [@TommySharp](https://community.openhab.org/u/TommySharp)\
**Post date:** [October 20, 2019, 11:45pm UTC](https://community.openhab.org/t/zigbee2mqtt-command/70105/7 "2019-10-20T23:45:34Z")

</div>

Thanks @Job I had not been keeping up so wasn’t aware that the new MQTT binding required things…  
I am still using the old V1 MQTT binding so will look in your mentioned topic for reference.

Thanks!
