MQTT 2.4, ZigBee2MQTT, Xiaomi Aqara Sensors (sample config)

With Mqtt 2.5 the state change only to OPEN but not to CLOSED with this js.

Do you have a idea?

I still have to upgrade to 2.5, once I have done this I’ll get back to you. In the meantime I hope someone else can help you out.

I have done it with a .map transform in the mqtt.things and it works perfect.

Thanks for the help.

I have the same issue.
Could you please show me your mqtt.things and the .map transform?

Here my Thing:

Thing topic xiaomi_kontakt_badfenster “Kontakt Badfenster” @ “MQTT” {
Channels:
Type contact : contact “Kontakt” [ stateTopic = “zigbee2mqtt/xiaomi_kontakt_badfenster/contact”, transformationPattern=“MAP:TuerFensterKontakt.map” ]
Type number : voltage “Spannung” [ stateTopic = “zigbee2mqtt/xiaomi_kontakt_badfenster/voltage” ]
Type number : battery “Batterie” [ stateTopic = “zigbee2mqtt/xiaomi_kontakt_badfenster/battery” ]
Type number : linkquality “Verbindung” [ stateTopic = “zigbee2mqtt/xiaomi_kontakt_badfenster/linkquality” ]

And the Map Transform (TuerFensterKontakt.map):

true=CLOSED
false=OPEN

I hope it works for you.

@R-Rosenow: I think you should mention that your things are only working if you enable attribute: topic in zigbee2mqtt.

Reference: https://www.zigbee2mqtt.io/information/configuration.html

# Optional: experimental options
experimental:
  # Optional: MQTT output type: json, attribute or attribute_and_json (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"
  # attribute_and_json: both json and attribute (see above)
  output: 'json'

@R-Rosenow : i need help for the items in openhab.

May ZigBee works and i see the values of my Aqara Temperature Sensor in MQTT.fx.
But i get no informations with my items.
I use openhab 3

I have create a MQTT broker in the settings in openhab not over the code. the other MQTT works, so i dont want change it.

MQTT broker identifier : “mqtt:broker:brokermqtt”

My Zigbee device have the identifier : “zigbee2mqtt/TEMP_OG_LINKS” (i see it in MQTT.fx )

I think i need only the items.
I try:
Number TempOgLinks “Temperatur OG Links [%.1f °C]” {mqtt="<[brokermqtt:zigbee2mqtt/TEMP_OG_LINKS:state:JSONPATH:$.temperature]"}

But i get no Value in openhab.
My broker have an User and a password. But i think its not the problem. I want use this connection how the other parts, too.

Could anyone help me?

You need Items and Things, not just Items. openHAB 3 does not have the V1 MQTT Binding, which your configuration is for - you will need to reconfigure for the V2/V3 binding.

This may help:

OK Thanks die the example.
But I found no solution.

I have configurate a broker in Openhab3 with this setup:

UID: mqtt:broker:brokermqtt
label: MQTT Broker
thingTypeUID: mqtt:broker
configuration:
lwtQos: 0
publickeypin: true
keepAlive: 60
clientid: ce8047bb-1b32-453f-a9d1-d87f9932b061
secure: false
certificatepin: true
password: openhabian
qos: 0
reconnectTime: 60000
host: localhost
lwtRetain: true
enableDiscovery: true
username: openhabian

And now i wrote this things:

Bridge mqtt:broker:brokermqtt2 [ host=“localhost”, port=1883, secure=false, username=“openhabian”, password=“openhabian”]
{
// Contact sensors
Thing topic weathersensorentrancehallway “WeatherSensorEntranceHallway” {
Channels:
Type number : temperature “Temperature” [ stateTopic=“zigbee2mqtt/TEMP_OG_LINKS”, transformationPattern=“JSONPATH:$.temperature”]
Type number : humidity “Humidity” [ stateTopic=“zigbee2mqtt/TEMP_OG_LINKS”, transformationPattern=“JSONPATH:$.humidity”]
Type number : pressure “Pressure” [ stateTopic=“zigbee2mqtt/TEMP_OG_LINKS”, transformationPattern=“JSONPATH:$.pressure”]
Type number : voltage “Voltage” [ stateTopic=“zigbee2mqtt/TEMP_OG_LINKS”, transformationPattern=“JSONPATH:$.voltage”]
Type number : battery “Battery” [ stateTopic=“zigbee2mqtt/TEMP_OG_LINKS”, transformationPattern=“JSONPATH:$.battery”]}

items for example:

Number TemperatureEntranceHallway “Hal Temperatuur [%.1f °C]” {channel=“mqtt:topic:brokermqtt2:weathersensorentrancehallway:temperature”}

Which broker name is write in the frist line? mqtt:broker:brokermqtt that i have create in openhab3 or i need a new name (new broker)?

I get nothing informations with this item. I dont know thats wrong.
I think its the first line of the Thing?

How did you configure this Bridge? What is this a copy/paste from?

This has created a second Bridge to your broker. Not a problem, but just so you’re aware!

When you look in your OH3 UI, in the Things section, do you see either of these with a green ONLINE badge?

Is there a reason for not using the UI? Here’s a guide for setting up MQTT in openHAB 3, and here’s a guide for a simple bulb via zigbee2mqtt..

I can’t see anything immediately wrong with your configurations, but I’m on mobile so it’s not easy to see. Hopefully the links above might help…

I create the broker with the UI of openhab3 and create also items to use sonoff mqtt plugs. This works.

Ok than its a second Bridge … main thing it works :slight_smile:

Under the Things i see only my broker that i have creat over the UI.
I dont see a thing with the name brokermqtt2.

I tried to use the UI to create the things but it dont work.
The manuel for openhab 3 is very good but my thing does not go online.

i have change the configuration of zigbee. Now i see separate values for battery , temperature etc. in MQTT.fx so its works.

But if i write “zigbee2mqtt/TEMPOGLINKS/availability” in the “Availability Topic” the Thing goes offline. If i delete this line the Thing goes online. ( i have change the friendly name to TEMPOGLINKS, so the name is write )

maybe my zigbee2mgtt configuration is not correctly?

homeassistant: false
permit_join: true
mqtt:
base_topic: zigbee2mqtt
server: ‘mqtt://localhost:1883’
user: openhabian
password: openhabian
serial:
port: /dev/ttyACM0
disable_led: false
devices:
‘0x00158d0005866a98’:
friendly_name: ‘TEMPOGLINKS’
experimental:
output: attribute

It would be great if i can create the things over the UI.

I dont know how i can delete the user and passwort.
I have this in this configuration, in the mqtt broker (that i have create over the UI) and in the sonoff konfiguration. But it should work because i see all values in MQTT.fx

Let’s forget your configuration file, and start here. Can you show the configuration of your Thing which you tried to create in the UI? You could share the YAML from the Code tab.

The Thing that dont goes online

UID: mqtt:topic:brokermqtt:TemperaturSensor_DG_Links
label: Temperatur DG Links
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  availabilityTopic: zigbee2mqtt/TEMPOGLINKS/availability
  payloadAvailable: online
bridgeUID: mqtt:broker:brokermqtt

my broker:

UID: mqtt:broker:brokermqtt
label: MQTT Broker
thingTypeUID: mqtt:broker
configuration:
  lwtQos: 0
  publickeypin: true
  keepAlive: 60
  clientid: ef98a1f0-5ca1-47f8-a8c8-879b1f110a4c
  secure: false
  certificatepin: true
  password: openhabian
  qos: 0
  reconnectTime: 60000
  host: localhost
  lwtRetain: true
  enableDiscovery: true
  username: openhabian

zigbee2mqtt configuration:

homeassistant: false
permit_join: true
mqtt:
  base_topic: zigbee2mqtt
  server: 'mqtt://localhost:1883'
  user: openhabian
  password: openhabian
serial:
  port: /dev/ttyACM0
  disable_led: false
devices:
  '0x00158d0005866a98':
    friendly_name: 'TEMPOGLINKS'
experimental:
  output: attribute

Is this how your YAML is actually formatted? I don’t see any indentations? Can you edit your post and use code fences? Sandwich the YAML in-between three backticks ```

```

Like
This

```

i have change my YAML code. “…” for spaces. i dont know if you meen this but you see with lines are indented

No, use three backticks as suggested, then copy your YAML code back in.

i have change it now. it takes a few minutes :slight_smile:

I see this elements in MQTT.fx with the right values:

connect

now it works.

How often i get values from an aqara device? And when i get the first values?

My openhab device was turned Off maybe a half day.
I start it and i got no values from the aqara devices.
I have to Push the Button on all aqara Temperature devices. Thean i geht directly the values.

Could i Wale Up the aqara devices with openhab start or is it a configuration Part?
I think the aqara devices goes in a idle state?

I hope i dont must Push the Button in each devices If i restart openhab or Something Else.

The temp sensors send a message once per hour I think (not sure if it’s fixed, but it’s a long time), or every time one parameter changes. You can just touch or blow on the sensor to trigger it and see if that send updates after restarting.