[fixed/closed] Newbie question New setup - MQTT sensors not showing up in entities

Hi all
Am fairly new to HA and feel i’m missing something pretty fundamental. I’m running the zigbee2mqtt bridge- I have set it up without any errors (finally) however the MQTT sensor does not show up on the UI or as an entity. I have tried a lot of different syntax in the config file to no avail. Config runs without errors, the bridge is working, I can see the MQTT messages are being posted (i.e. subscribing to zigbee2mqtt/bridge/state shows messages ‘online’ when addon is restarted) and the bridge is running properly but nothing on the UI or in dev-states… What have I overlooked?
(i created the random sensor and the ‘tester’ mqtt sensor just to see if anything comes up- random shows up but not the ‘tester’.)

my config below

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 0
  longitude: 0
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 0
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: UTC
  # Customization file
  customize: !include customize.yaml

# Show links to resources in log and frontend
introduction:

# Enables the frontend
frontend:

# Enables configuration UI
config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time
history:

# View all events in a logbook
logbook:

# Enables a map showing the location of tracked devices
map:

# Track the sun
sun:


# Text to speech
tts:
  - platform: google

# Cloud
cloud:


# Uncomment below to use split configs

# group: !include groups.yaml
# automation: !include automations.yaml
# script: !include scripts.yaml



panel_iframe:
  configurator:
    title: Configurator
    icon: mdi:wrench
    url: http://hassio.local:3218
    
mqtt:
  broker: mqqt://hassio.local
  port: 1883
  username: myusr
  password: mypass
  client_id: home-assistant-1
  discovery: true
  discovery_prefix: homeassistant
  birth_message:
    topic: 'hass/status'
    payload: 'online'
  will_message:
    topic: 'hass/status'
    payload: 'offline'
    

# Zigbee2MQTT  GUI Config below

input_boolean:
  zigbee_permit_join:
    name: Allow devices to join
    initial: off
    icon: mdi:cellphone-wireless

timer:
  zigbee_permit_join:
    name: Time remaining
    duration: 600
    

sensor:
  - platform: mqtt
    name: Bridge state
    state_topic: "zigbee2mqtt/bridge/state"
    availability_topic: "zigbee2mqtt/bridge/state"
    icon: mdi:router-wireless
  - platform: random
  
  - platform: mqtt
    name: tester
    state_topic: "test/test"
    

group:
  zigbee_group:
    name: Zigbee
    entities:
      - input_boolean.zigbee_permit_join
      - timer.zigbee_permit_join
      - sensor.bridge_state
automation:
  - id: enable_zigbee_join
    alias: Enable Zigbee joining
    hide_entity: true
    trigger:
      platform: state
      entity_id: input_boolean.zigbee_permit_join
      to: 'on'
    action:
    - service: mqtt.publish
      data:
        topic: zigbee2mqtt/bridge/config/permit_join
        payload: 'true'
    - service: timer.start
      data:
        entity_id: timer.zigbee_permit_join
  - id: disable_zigbee_join
    alias: Disable Zigbee joining
    trigger:
    - entity_id: input_boolean.zigbee_permit_join
      platform: state
      to: 'off'
    action:
    - data:
        payload: 'false'
        topic: zigbee2mqtt/bridge/config/permit_join
      service: mqtt.publish
    - data:
        entity_id: timer.zigbee_permit_join
      service: timer.cancel
    hide_entity: true
  - id: disable_zigbee_join_timer
    alias: Disable Zigbee joining by timer
    hide_entity: true
    trigger:
    - platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.zigbee_permit_join
    action:
    - service: mqtt.publish
      data:
        topic: zigbee2mqtt/bridge/config/permit_join
        payload: 'false'
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.zigbee_permit_join

Can you paste these here, so we can match your configuration to the messages being sent.

Log from zigbee2mqtt:

[Info] Configuration file found. Will overwrite configurable               fields with values from add-on configuration
[Info] Configuration written to /share/zigbee2mqtt/configuration.yaml
2018-12-12T05:41:24: PM2 log: Launching in no daemon mode
2018-12-12T05:41:25: PM2 log: App [npm:0] starting in -fork mode-
2018-12-12T05:41:25: PM2 log: App [npm:0] online
> [email protected] start /zigbee2mqtt-0.2.0
> node index.js
		Zigbee2mqtt requires node version >=8.11 10, you are running v8.11.4!
  zigbee2mqtt:info 2018-12-12 05:41:32 Logging to directory: '/share/zigbee2mqtt/log/2018-12-12.05-41-32'
  zigbee2mqtt:info 2018-12-12 05:41:34 Starting zigbee2mqtt version 0.2.0 (commit #unknown)
  zigbee2mqtt:info 2018-12-12 05:41:34 Starting zigbee-shepherd
  zigbee2mqtt:info 2018-12-12 05:41:35 zigbee-shepherd started
  zigbee2mqtt:info 2018-12-12 05:41:35 Coordinator firmware version: '20180815'
  zigbee2mqtt:info 2018-12-12 05:41:35 Currently 0 devices are joined:
  zigbee2mqtt:warn 2018-12-12 05:41:35 `permit_join` set to  `true` in configuration.yaml.
  zigbee2mqtt:warn 2018-12-12 05:41:35 Allowing new devices to join.
  zigbee2mqtt:warn 2018-12-12 05:41:35 Set `permit_join` to `false` once you joined all devices.
  zigbee2mqtt:info 2018-12-12 05:41:35 Zigbee: allowing new devices to join.
  zigbee2mqtt:info 2018-12-12 05:41:35 Connecting to MQTT server at mqtt://192.168.0.3:1883
  zigbee2mqtt:info 2018-12-12 05:41:36 zigbee-shepherd ready
  zigbee2mqtt:info 2018-12-12 05:41:36 Connected to MQTT server
  zigbee2mqtt:info 2018-12-12 05:41:36 MQTT publish, topic: 'zigbee2mqtt/bridge/state', payload: 'online'

log from mosquitto:

[INFO] Setup mosquitto configuration
[INFO] Found local users inside config
[INFO] Initialize Hass.io Add-on services
[INFO] Initialize Home Assistant discovery
[INFO] Start Mosquitto daemon
1544592921: mosquitto version 1.4.15 (build date 2018-03-04 15:35:59+0000) starting
1544592921: Config loaded from /etc/mosquitto.conf.
1544592921: *** auth-plug: startup
1544592921: ** Configured order: http
1544592921: Opening ipv4 listen socket on port 1883.
1544592921: Opening ipv6 listen socket on port 1883.
1544592921: Opening websockets listen socket on port 1884.
1544592921: Opening ipv4 listen socket on port 8883.
1544592921: Opening ipv6 listen socket on port 8883.
1544592921: Opening websockets listen socket on port 8884.
1544592921: Warning: Mosquitto should not be run as root/administrator.
1544592962: New connection from 172.30.32.1 on port 1883.
[INFO] found myusr on local database
1544592963: New client connected from 172.30.32.1 as mqttjs_95bb0da9 (c1, k60, u'myusr').
1544593255: New connection from 172.30.32.1 on port 1883.
[INFO] found myusr on local database
1544593255: New client connected from 172.30.32.1 as mosqsub|25-core-ssh (c1, k60, u'myusr').
1544593272: Socket error on client mqttjs_95bb0da9, disconnecting.
1544593296: New connection from 172.30.32.1 on port 1883.
[INFO] found myusr on local database
1544593296: New client connected from 172.30.32.1 as mqttjs_8c87e9d3 (c1, k60, u'myusr').
1544594722: Saving in-memory database to /data/mosquitto.db.
1544595040: Socket error on client mosqsub|25-core-ssh, disconnecting.

entering the following in putty returns ‘online’:

mosquitto_sub -h 192.168.0.3 -t zigbee2mqtt/bridge/state -u myusr -P                         mypass
online

my zigbee2mqtt config from web ui:

{
  "data_path": "/share/zigbee2mqtt",
  "homeassistant": true,
  "permit_join": true,
  "mqtt_base_topic": "zigbee2mqtt",
  "mqtt_server": "mqtt://192.168.0.3:1883",
  "serial_port": "/dev/ttyACM0",
  "mqtt_user": "myusr",
  "mqtt_pass": "mypass"
}

my mosquitto config from web ui:

{
  "logins": [
    {
      "username": "myusr",
      "password": "mypass"
    }
  ],
  "anonymous": false,
  "customize": {
    "active": false,
    "folder": "mosquitto"
  },
  "certfile": "certificate.pem",
  "keyfile": "privkey.pem"
}

Is it an error in my config to do with auth / connection between HA and mosquitto maybe?

Oops- just checked the ha log…

2018-12-12 06:31:54 ERROR (MainThread) [homeassistant.components.mqtt] Failed to connect due to exception: [Errno -2] Name does not resolve
2018-12-12 06:32:03 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 350, in _async_add_entity
    await entity.async_added_to_hass()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/sensor/mqtt.py", line 136, in async_added_to_hass
    await MqttAvailability.async_added_to_hass(self)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 842, in async_added_to_hass
    await self._availability_subscribe_topics()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 876, in _availability_subscribe_topics
    'qos': self._availability_qos}})
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/subscription.py", line 39, in async_subscribe_topics
    hass, topic[0], topic[1], topic[2], topic[3])
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 306, in async_subscribe
    topic, msg_callback, qos, encoding)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 688, in async_subscribe
    await self._async_perform_subscription(topic, qos)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 723, in _async_perform_subscription
    _raise_on_error(result)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 808, in _raise_on_error
    'Error talking to MQTT: {}'.format(mqtt.error_string(result_code)))
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected.
2018-12-12 06:32:03 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 350, in _async_add_entity
    await entity.async_added_to_hass()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/sensor/mqtt.py", line 177, in async_added_to_hass
    message_received, self._qos)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 306, in async_subscribe
    topic, msg_callback, qos, encoding)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 688, in async_subscribe
    await self._async_perform_subscription(topic, qos)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 723, in _async_perform_subscription
    _raise_on_error(result)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 808, in _raise_on_error
    'Error talking to MQTT: {}'.format(mqtt.error_string(result_code)))
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected.

sooo HA isn’t connecting to mosquitto broker?

Turns out I had an empty integration set for MQTT and it was overridding the mosquitto config details… still learning how ‘integrations’ work with configuration.yaml anyway removed and re-added the addon, re-did the integration and it is all good now.

2 Likes

Sorry can you please explain more how we fix it, i have the same problem, witch addon have you re-added MQTT or zigbee2mqtt ? Have you had something in you HA config file?

1 Like