Connecting Aqara Sensors via CC2531 USB Stick

Hi community,

I’m new to OpenHAB and was happy to be able to get Openhabian running. My plan is to connect to an Aqara Temperature and Humidity Sensor. Therefore I have a CC2531 USB Stick already flashed with Koenkk Z-Stack-firmware (Z-Stack_Home_1.2). I was able to create the openHAB Zigbee Binding and create the thing CC2531EMK Coordinator. This thing shows ONLINE as the status.

Here my problem starts. My idea was to create the thing Temperature Sensor by clicking on the plus dot, selcting the only binding I have (zigbee) and pushing the button on the sensor until the sensor flashes several times. My expectation was that if I let openHAB scan at the same time the sensor would appear to be selected. But this does not happen.

Any idea what I missed or did wrong?

Kind regards,
Günther

  • Platform information:
    • Hardware: Raspi 4 B, 2GB
    • OS: Openhabian
    • Java Runtime Environment: sorry, don’t know yet
    • openHAB version: 3
  • Issue of the topic: see above

If you are using the zigbee-binding with CC2531-Stick you have to be sure to use the correct firmware

Here this is mentioned in the binding-documentation.

With the correct firmware, it works just like you expected, if I remember this correct.

I thought this too

But the OP mentions they have

The documentation says

The custom firmware from Zigbee2MQTT can also be used, and has been reported working by some users.

and the link points to here which is the page for Z-Stack_Home_1.2! So the OP is using a firmware that “can also be used”.

There’s no guarantees in any of this, though, so @Guenther if you’re able to you might want to try the other firmware linked from the documentation, or go all in with KoenK and just use Zigbee2MQTT!

1 Like

Thank you for your input. I understand that if my CC2531 has the Koenkk firmware that this should be used with a MQTT Binding in openhab. So I choosed to try out Zigbee2MQTT according to Running Zigbee2MQTT | zigbee2mqtt.io.

When I start zigbee2mqtt the initialization looks ok. The green led on the CC2531 lights up and zigbee2mqtt is trying to connect to a MQTT server.

Zigbee2MQTT:info 2021-01-19 13:37:22: Starting Zigbee2MQTT version 1.17.0 (commit #07cdc9d)
Zigbee2MQTT:info 2021-01-19 13:37:22: Starting zigbee-herdsman (0.13.46)
Zigbee2MQTT:info 2021-01-19 13:37:26: zigbee-herdsman started
Zigbee2MQTT:info 2021-01-19 13:37:26: Coordinator firmware version: ‘{“meta”:{“maintrel”:3,“majorrel”:2,“minorrel”:6,“product”:0,“revision”:20190608,“transportrev”:2},“type”:“zStack12”}’
Zigbee2MQTT:info 2021-01-19 13:37:26: Currently 0 devices are joined:
Zigbee2MQTT:warn 2021-01-19 13:37:26: permit_join set to true in configuration.yaml.
Zigbee2MQTT:warn 2021-01-19 13:37:26: Allowing new devices to join.
Zigbee2MQTT:warn 2021-01-19 13:37:26: Set permit_join to false once you joined all devices.
Zigbee2MQTT:info 2021-01-19 13:37:26: Zigbee: allowing new devices to join.
Zigbee2MQTT:info 2021-01-19 13:37:26: Connecting to MQTT server at mqtt://localhost
Zigbee2MQTT:error 2021-01-19 13:37:36: Not connected to MQTT server!

At that point I added the MQTT Binding and the MQTT Broker in openhab. However zigbee2mqtt still can’t connet to the MQTT server and the MQTT Broker states ERROR COMM. The error message of the MQTT Broker is:

Status:

OFFLINE

COMMUNICATION_ERROR

io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:1883

Any idea what I did wrong?

You’re on openHAB 3, which doesn’t have an MQTT Broker. You need to install one separately, such as Mosquitto.

Once that’s done, point zigbee2mqtt to your MQTT broker by editing its configuration.yaml.

Once that’s done, connect openHAB to the MQTT broker via a Broker Thing..

Once that’s done, create a Generic MQTT Thing for your Aqara device. This tutorial goes into detail on a Generic MQTT Thing.

2 Likes

Or as an alternative use the Homeassistant-support in zigbee2mqtt to enable OpenHAB autodiscovery.

This way your zigbee devices will automatically show up in your inbox without textual configuration.

1 Like

Ooh, where’s that UI from?

It´s integrated in zigbee2mqtt since 1.15.0 (Oct 2020)

3 Likes

Awesome! Time to enable that in the YAML!

Great community! Thanks.

I found out that you can install mosquitto from opnehabian-config. That worked so far as in the openhab UI the thing MQTT Broker could establish a connection. Next step will be to install zigbee2mqtt.

However there is a small disadvantage. After reboot of the raspi mosquitto fails to be started as a background service. Starting from the command line fails. When I install mosquitto from openhabian-config again it is up and running. I installed it from the command line but this did not change anything.

So far I can now continue with zigbee2mqtt and I am very thankful for the support :slightly_smiling_face:

Here is my experience with zigbee2mqtt:

Installation went ok. Starting from the command line works also. When I pair the sensor I can see the log messages :slight_smile:

But:

  1. Recognizing the sensor in openHAB is unsuccsesful. I click on the plus sign to add a thing. I select the only available Binding MQTT Brocker and click on Scan. Nothing happens. In the ssh window where zigbee2mqtt is running I can see the messages from the sensor.

  2. As described before mosquitto fails to start as a service in the background. So I started it from openhabian-config. As long as the raspi is not shut down mosquitto is running.

  3. Also the attempt to start zigbee2mqtt as a service in the background fails.

I would like to resolve topic 1 first. zigbee2mqtt shows

Zigbee2MQTT:info 2021-01-21 12:38:52: MQTT publish: topic ‘zigbee2mqtt/0x00158d000484e752’, payload ‘{“battery”:100,“humidity”:53.94,“linkquality”:168,“pressure”:987,“temperature”:23.93,“voltage”:3125}’

While this is the communication between the sensor and zigbee2mqtt I wonder how I can check what arrives in mosquitto. Any idea?

Kind regards,
Günther

mosquitto_sub -d -t zigbee2mqtt/#

this should show you log for all messages arrived to mosquitto from zigbee2mqtt topic.

Your log snippet actually shows what zigbee2mqtt is publishing to MQTT, not the comms between the sensor and zigbee2mqtt.

As @smarthomepch suggests, you could use mosquitto_sub, or if you want something with a UI try MQTT Explorer or mqtt.fx.

It’s been a while but I catched up again. Mosquitto and zigbee2mqtt are running on startup in the background. The Aqara sensor is connected to zigbee2mqtt. I can see the messages of zigbee2mqtt (in a ssh session logging made visual by sudo journalctl -u zigbee2mqtt.service -f) as:

May 29 11:09:24 openhabian npm[702]: Zigbee2MQTT:info 2021-05-29 11:09:24: MQTT publish: topic ‘zigbee2mqtt/0x00158d000484e752’, payload ‘{“battery”:100,“humidity”:51.34,“linkquality”:186,“pressure”:967,“temperature”:24.58,“voltage”:3125}’

For mosquitto I opened a second ssh session and started showing the log by
mosquitto_sub -d -t zigbee2mqtt/#

From the log there it looks like mosquitte knows the sensor. But I can’t see any message with the data the sensor is providing. In OpenHAB UI I can create a Generic MQTT Thing with a channel and an item. The item shows always NULL.

There is no error message.

What is necessary to get mosquitto taking over the data provided by zigbee2mqtt and providing to OpenHAB?

Kind regards,
Günther

Have you done

At the moment I can’t see any proof that you have a successful connection between zigbee2mqtt and your Mosquitto broker.

Does it? Can you show us this log? Note that you can point mosquitto_sub to any topic you like - it will never tell you that the topic isn’t in use, because some device might suddenly publish to it in the future…

If zigbee2mqtt isn’t communicating properly with Mosquitto then openHAB will definitely not be able to see the sensor!

Hi hafniumzinc,

Thank you for your reply.

In the configuration.yaml these lines are pointing to the MQTT broker

mqtt:
base_topic: zigbee2mqtt
server: 'mqtt://localhost'
advanced:
network_key: GENERATE

mosquitto_sub gives me

openhabian@openhabian:~ $ mosquitto_sub -d -t zigbee2mqtt/#
Client mosqsub|2510-openhabian sending CONNECT
Client mosqsub|2510-openhabian received CONNACK (0)
Client mosqsub|2510-openhabian sending SUBSCRIBE (Mid: 1, Topic: zigbee2mqtt/#, QoS: 0)
Client mosqsub|2510-openhabian received SUBACK
Subscribed (mid: 1): 0
Client mosqsub|2510-openhabian received PUBLISH (d0, q0, r1, m0, 'zigbee2mqtt/bridge/state', ... (6 bytes))
...

and much further into the logging I can see that mosquitto is receiving the data:

Client mosqsub|2510-openhabian received PUBLISH (d0, q0, r0, m0, 'zigbee2mqtt/0x00158d000484e752', ... (102 bytes)) {"battery":100,"humidity":58.04,"linkquality":176,"pressure":953.7,"temperature":22.89,"voltage":3125}

So far mosquitto receives the data. But why can’t I see this in my OpenHAB Thing (Channel and Item created)?

Kind regards,
Günther

You’ll have to show your full configuration for your Thing and Item to answer this question.

Two things are created. The MQTT Broker and a Generic MQTT Thing. Both are showing ONLINE.

The code of the Generic MQTT Thing and the channel for the temperature is:

UID: mqtt:topic:c952b93aaa:ed52ffe832
label: Generic MQTT Thing
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:c952b93aaa
channels:
- id: temperature
channelTypeUID: mqtt:number
label: Air Temperature
description: ""
configuration:
transformationPattern: JSONPATH:$.temperature

To display the value I created an item with the profile JSONPATH. The JSONPATH Expression is

$.temperature

The item shows NULL.

Kind regards,
Günther

Your Air Temperature Channel doesn’t look like it is subscribed to any topic. You will need to add

zigbee2mqtt/0x00158d000484e752

into the MQTT State Topic field of the UI.

That was the missing part. Now I have the value in OpenHAB.

Thank you very much!