Howto add MQTT Thing

It is late here and I am out of ideas.

libmosquitto1/oldstable,now 2.0.11-1 amd64 [Installiert,automatisch]
mosquitto-clients/oldstable,now 2.0.11-1 amd64 [installiert]
mosquitto/oldstable,now 2.0.11-1 amd64 [installiert]

No Problem. Thanks for your patience and time. Have a good night.

Please post your mqtt thing/channel config. Or did I miss you posted it already.

Yes i posted it before. I think the problem is on the host self. So if i dont get data with command mosquitto_sub, oH will not work too.

Just had a thought. What is the mosquito broker running on ip address? That ip had to go in the yaml of zigbee2mqtt.

if the following is what you refer to, that this cannot work

State topic is not identical to published topic.
Please post the complete code of your mqtt thing/channels!

You need the IP of the mosquitto broker. That goes in the zigbee2mqtt configuration.yaml
Restart zigbee2mqtt
Run this:

mosquitto_sub -h IP-of_the_broker -v -t "zigbee2mqtt/#"

eg mosquitto_sub -h 192.168.1.164 -v -t "zigbee2mqtt/#"

It should work.

My assumption was you had the broker, zigbee2mqtt and OH on the one server like I do.

If you get something back from the mosquitto_sub command then in OH you add the IP of the broker and it should work.

Thats what we have done before too: Howto add MQTT Thing - #31 by ubeaut right?

Thanks, but i think as long as mosquitto_sub do not work, oH wont work too.

What about checking if mosquitto publishes anything by using


mosquitto_sub -h IP-of_the_broker -v -t "#"

In both cases i get an result, but it does not show the device informations.

Could you please post the results, so we can see what is coming back.
It is really hard to give support if we just receive yes or no answers.

@TasteIT I will post my configs later this evening, so you can compare with yours.
What I can already tell, I have
zigbee2mqtt running on a Pi Zero W with some Zigbee window contacts
mosquito on a NUC also running my old openHAB 3 installation
openHAB 4 on another NUC with mqtt binding reading the information from my contacts.
That’s 3 different machines in the game and all is playing together nicely.

Perhaps I can also post examples where I use only two machines, one for zgbee2mqtt and one for openHAB and mosquito…

Did you do (or do you need to do) step 1a of the following post?

OK, here we go with my sample configs:

/etc/mosquitto/mosquitto.conf [this is mosquitto 3.1 on my openHAB 3 machine]

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

configuration.yaml for zigbee2mqtt on seperate Pi Zero

homeassistant: false
permit_join: true
mqtt:
  base_topic: zigbee2mqtt
  server: mqtt://192.168.x.x [IP of the machine running mosquitto]
serial:
  port: /dev/ttyACM0
advanced:
  network_key:
       ***redacted***
  log_level: debug
frontend: true
devices:
  '0xec_redacted':
    friendly_name: WindowContactOffice

Thing MQTT Broker

UID: mqtt:broker:mosquitto
label: Mosquitto MQTT Broker
thingTypeUID: mqtt:broker
configuration:
  lwtQos: 0
  publickeypin: true
  clientid: ***autogenerated***
  keepAlive: 60
  hostnameValidated: true
  birthRetain: true
  secure: false
  certificatepin: true
  shutdownRetain: true
  protocol: TCP
  qos: 0
  reconnectTime: 60000
  mqttVersion: V3
  host: 192.168.x.x [IP of my openHAB3 machine running mosquitto 3.1]
  lwtRetain: true
  enableDiscovery: true

Thing WindowContactOffice

UID: mqtt:topic:mosquitto:windowContactOffice
label: Fensterkontakt Arbeitszimmer
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:mosquitto
location: Office
channels:
  - id: state
    channelTypeUID: mqtt:contact
    label: Kontaktstatus
    description: null
    configuration:
      stateTopic: zigbee2mqtt/WindowContactOffice
      transformationPattern: JSONPATH:$.contact
      off: "true"
      on: "false"
  - id: lowBattery
    channelTypeUID: mqtt:switch
    label: Niedrige Batterieladung
    description: null
    configuration:
      stateTopic: zigbee2mqtt/WindowContactOffice
      transformationPattern: JSONPATH:$.battery_low
      off: "false"
      on: "true"

Hope this helps…

Yes my mosquitto.conf has the allow_anonymous = true in it.

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /run/mosquitto/mosquitto.pid
listener 1883
allow_anonymous true
persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

Is your set up like this:
Mosquitto and Openhab on the same server?
Zigbee2mqtt server on a different server?

yes its setup like this

My setup
Host1 = Mosquitto and Zigbee2MQTT | Host2 = openHAB

# cat /etc/mosquitto/mosquitto.conf 
pid_file /run/mosquitto/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
#password_file /etc/mosquitto/passwd
allow_anonymous true
listener 1883
# cat /opt/zigbee2mqtt/data/configuration.yaml 
homeassistant: false
frontend: true
mqtt:
  base_topic: zigbee2mqtt
  server: mqtt://localhost
#  user: User
#  password: 'nothing'
serial:
  port: /dev/ttyUSB0
advanced:
  network_key:
    - 249
    - 79
    - 174
    - 176
    - 179
    - 213
    - 199
    - 251
    - 219
    - 85
    - 179
    - 210
    - 72
    - 164
    - 122
    - 229
  pan_id: 56003
  ext_pan_id:
    - 108
    - 149
    - 206
    - 63
    - 171
    - 253
    - 61
    - 226
  homeassistant_legacy_entity_attributes: false
  legacy_api: false
  legacy_availability_payload: false
  log_level: debug
device_options:
  legacy: false
devices:
  '0x00124b002a50e60c':
    friendly_name: DoorWindow

openHab Broker

UID: mqtt:broker:62700f885a
label: MQTT Broker
thingTypeUID: mqtt:broker
configuration:
  lwtQos: 0
  publickeypin: true
  clientid: 705a46XXX84b920c
  keepAlive: 60
  hostnameValidated: true
  birthRetain: true
  secure: false
  certificatepin: true
  shutdownRetain: true
  protocol: TCP
  qos: 0
  reconnectTime: 60000
  port: 1883
  mqttVersion: V3
  host: servername
  lwtRetain: true
  enableDiscovery: true

Thing Channel

UID: mqtt:topic:62700f885a:84c2c6df90
label: Lini-Fenster MQTT
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:62700f885a
location: Room
channels:
  - id: DoorWindow-State
    channelTypeUID: mqtt:contact
    label: Open/Closed
    description: ""
    configuration:
      stateTopic: zigbee2mqtt/DoorWindow
      transformationPattern: REGEX:(.*contact.*)∩JSONPATH:$.contact
      off: "true"
      on: "false"

Should be the IP address of host1 in the zigbee2mqtt.yaml

Should be the IP address of host1 in the OH broker.

1 Like