Openhab - zigbee2mqtt

Tags: #<Tag:0x00007f617da62fd0> #<Tag:0x00007f617da62e90> #<Tag:0x00007f617da62d78>

Hello Everyone,

Afters days of trial and error hopefully you can give me some hints.

I have a running openhab system mostly used to connect to my knx environment.
No i want to try some zigbee devices additionally.

I have successfully installed zigbee2mqtt and also installed the latest MQTT binding within OH.
Also added the Aqara temp sensor and can see the data in the logfile:

MQTT publish: topic ‘zigbee2mqtt/Tempsensor’, payload ‘{“battery”:74,“voltage”:2955,“temperature”:24.64,“humidity”:54.3,“pressure”:950.4,“linkquality”:34}’

My configuration file:

Things File:

Bridge mqtt:broker:mybroker “my MQTT” [ host=“localhost”, clientID=“openHAB2” ]

{

// Temp sensors

Thing topic Tempsensor “Tempsensor” {

Channels:

Type number : temperature "temperature" [stateTopic="zigbee2mqtt/Tempsensor/temperature"]

}
}

Item File

//Zigbee

Number temperature “Temperature [%.1f °C]” {channel=“mqtt:topic:mybroker:Tempsensor:temperature”}

I think i already tried all possible options without any luck.
Still no data in the sitemap or paperui/control

Thank you for your input and just let me know if you need more infos.

PS: i have enabled the homeassistant parameter to doublecheck the connection between OH and zigbee2mqtt only.

Assuming your MQTT broker itself is setup correctly, try to exchange your current Thing definition for the one below:

Bridge mqtt:broker:mybroker "my MQTT" [ host="localhost", clientID="openHAB2" ]
{
    // Temp sensors
    Thing topic Tempsensor "Tempsensor" {
        Channels:
            Type number : temperature "temperature" [
                stateTopic="zigbee2mqtt/Tempsensor",
                transformationPattern="JSONPATH:$.temperature"
            ]
    }
}

You will need to install the JSONPath transformation service through PaperUI -> Add-ons -> Transformations -> JSONPath Transformation -> Install


For fun, below is a full Thing configuration which will extract each payload item:

Bridge mqtt:broker:mybroker "my MQTT" [ host="localhost", clientID="openHAB2" ]
{
    // Temp sensors
    Thing topic Tempsensor "Tempsensor" {
        Channels:
            Type number : temperature "temperature" [
                stateTopic="zigbee2mqtt/Tempsensor",
                transformationPattern="JSONPATH:$.temperature"
            ]
            Type number : battery "Battery" [
                stateTopic="zigbee2mqtt/Tempsensor",
                transformationPattern="JSONPATH:$.battery"
            ]
            Type number : voltage "Voltage" [
                stateTopic="zigbee2mqtt/Tempsensor",
                transformationPattern="JSONPATH:$.voltage"
            ]
            Type number : humidity "Humidity" [
                stateTopic="zigbee2mqtt/Tempsensor",
                transformationPattern="JSONPATH:$.humidity"
            ]
            Type number : pressure "Pressure" [
                stateTopic="zigbee2mqtt/Tempsensor",
                transformationPattern="JSONPATH:$.pressure"
            ]
            Type number : linkquality "Linkquality" [
                stateTopic="zigbee2mqtt/Tempsensor",
                transformationPattern="JSONPATH:$.linkquality"
            ]
    }
}

And your items might look something like

Number temperature "Temperature [%.1f °C]" {channel="mqtt:topic:mybroker:Tempsensor:temperature"}
Number battery "Battery [%.1f %%]" {channel="mqtt:topic:mybroker:Tempsensor:battery"}
Number voltage "Voltage [%d mV]" {channel="mqtt:topic:mybroker:Tempsensor:voltage"}
Number humidity "Humidity [%.1f %%]" {channel="mqtt:topic:mybroker:Tempsensor:humidity"}
Number pressure "Pressure [%.1f]" {channel="mqtt:topic:mybroker:Tempsensor:pressure"}
Number linkquality "Linkquality [%d]" {channel="mqtt:topic:mybroker:Tempsensor:linkquality"}

Thank you for your quick response.
Tried your settings without success - still no data
If it is my correct understanding i do not need to add the transformationPattern if i use

experimental:
output: attribute

correct?

True. But you said that your MQTT payload was

{"battery":74,"voltage":2955,"temperature":24.64,"humidity":54.3,"pressure":950.4,"linkquality":34}

which is JSON.

Have you used a program such as MQTT Explorer or mqtt.fx to see what the actual messages are on the zigbee2mqtt/Tempsensor topic? If not, I highly recommend you do, and report back!

now i can see following log in OH:
020-09-02 21:26:53.994 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload ‘{“battery”:74,“voltage”:2955,“temperature”:22.56,“humidity”:57.71,“pressure”:950.7,“linkquality”:39}’ not supported by type ‘NumberValue’

via MQTTfx:

zigbee2mqtt/Tempsensor
{“battery”:74,“voltage”:2955,“temperature”:22.56,“humidity”:57.71,“pressure”:950.7,“linkquality”:39}

What is your exact Thing configuration when you get that log warning? It looks like you’re not applying the transformation. Please use code fences:

```
Sandwich your code between three back ticks
```

It looks like you are still receiving JSON strings. Did you re-start zigbee2mqtt after you applied the configuration.yaml changes?

Yes always restarting the zigbee service after applying changes.

Bridge mqtt:broker:mybroker "my MQTT" [ host="localhost", clientID="openHAB2" ]
{

// Temp sensors
    Thing topic Tempsensor "Tempsensor" {
        Channels:
            Type number : temperature "temperature" [
                stateTopic="zigbee2mqtt/Tempsensor",
                transformationPattern="JSONPATH:$.temperature"
            ]
    
	
}

}

Additional warning in the OH log:

2020-09-02 21:34:39.596 [WARN ] [t.generic.ChannelStateTransformation] - Transformation service JINJA for pattern {{ value_json.linkquality }} not found!

2020-09-02 21:34:39.597 [WARN ] [t.generic.ChannelStateTransformation] - Transformation service JINJA for pattern {{ value_json.pressure }} not found!

2020-09-02 21:34:39.598 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload '{"battery":74,"voltage":2955,"temperature":23.38,"humidity":55.9,"pressure":950.7,"linkquality":42}' not supported by type 'NumberValue'

2020-09-02 21:34:39.599 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload '{"battery":74,"voltage":2955,"temperature":23.38,"humidity":55.9,"pressure":950.7,"linkquality":42}' not supported by type 'NumberValue'

2020-09-02 21:34:39.599 [WARN ] [t.generic.ChannelStateTransformation] - Transformation service JINJA for pattern {{ value_json.pressure }} not found!

2020-09-02 21:34:39.601 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload '{"battery":74,"voltage":2955,"temperature":23.38,"humidity":55.9,"pressure":950.7,"linkquality":42}' not supported by type 'NumberValue'

Should i try to modifiy the config and remove:

experimental:
output: attribute

while using transformation pattern?

I think you should start by getting rid of the “homeassistant parameter” that you set. You’re manually creating configuration files, so you won’t need auto-discovery stuff.

Then see what the output from zigbee2mqtt is.

Do you mean the zigbee2mqtt service?

Here is a very simple configuration for a lightbulb via zigbee2mqtt, which might help:

And a slightly more advanced configuration for a switch/button:

Yes i mean the zigbee2mqtt service:

I have now modified the configuration.file:

homeassistant: false
permit_join: true
mqtt:
  base_topic: zigbee2mqtt
  server: 'mqtt://localhost'
serial:
  port: /dev/ttyACM0
  advanced:
    network_key: GENERATE
'\n\nadvanced:\n    network_key': GENERATE
devices:
  '0x00158d0004610907':
    friendly_name: 'Tempsensor'`

LogFile from zigbee2mqtt:

info  2020-09-02 21:42:35: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload 'online'
info  2020-09-02 21:42:35: MQTT publish: topic 'zigbee2mqtt/Tempsensor', payload '{"battery":74,"voltage":2955,"temperature":23.38,"humidity":57.06,"pressure":950.7,"linkquality":28}'
info  2020-09-02 21:42:35: MQTT publish: topic 'zigbee2mqtt/bridge/config', payload '{"version":"1.14.3","commit":"77f3e54","coordinator":{"type":"zStack12","meta":{"transportrev":2,"product":0,"majorrel":2,"minorrel":6,"maintrel":3,"revision":20190608}},"network":{"panID":6754,"extendedPanID":"0xdddddddddddddddd","channel":11},"log_level":"info","permit_join":true}'

OH Log:

2020-09-02 21:42:36.057 [WARN ] [t.generic.ChannelStateTransformation] - Transformation service JINJA for pattern {{ value_json.battery }} not found!

2020-09-02 21:42:36.060 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload '{"battery":74,"voltage":2955,"temperature":23.38,"humidity":57.06,"pressure":950.7,"linkquality":28}' not supported by type 'NumberValue'

2020-09-02 21:42:36.062 [WARN ] [t.generic.ChannelStateTransformation] - Transformation service JINJA for pattern {{ value_json.linkquality }} not found!

2020-09-02 21:42:36.063 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload '{"battery":74,"voltage":2955,"temperature":23.38,"humidity":57.06,"pressure":950.7,"linkquality":28}' not supported by type 'NumberValue'

2020-09-02 21:42:36.065 [WARN ] [t.generic.ChannelStateTransformation] - Transformation service JINJA for pattern {{ value_json.pressure }} not found!

2020-09-02 21:42:36.066 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload '{"battery":74,"voltage":2955,"temperature":23.38,"humidity":57.06,"pressure":950.7,"linkquality":28}' not supported by type 'NumberValue'

`Yes i have already checked all different mqtt HowTo over the last days and it looks quite simple :wink:

Have you previously tried to set this sensor up using PaperUI? I’m suspicious of the JINJA warnings. You need to make sure any auto generated or PaperUI generated Things and Items are completely deleted - they don’t play well together with file configurations.

Absolutly tried everything :wink:
Maybe a good option to uninstall the mqqt binding in OH and reinstall to have a fresh setup?
(if during the unistall everything else related to the binding will be deleted?)

It is finally working!!!
restartet the OH service again and now the Temp value is filled.
No idea why but anyway thank you very much for your patience

What version of openHAB are you using? Older versions required a restart after changing Things files due to a bug.

openHAB 2.5.3-1 (Release Build)

Yeah, that’ll probably be it then. I’m on 2.5.5 and don’t have that issue any longer.

Anyway, well done on fixing it! Hopefully the extended example in my first post is also useful!