Sensor unknown value

Tags: #<Tag:0x00007f3f1764d108>

Hi, I’am new in Hassio and I don’t find/get my sensor value in frontend panel.
I use zigbee2mqtt dongle and I see in de Zigbee2mqtt log:

zigbee2mqtt:info 7/17/2019, 9:30:47 AM MQTT publish: topic 'zigbee2mqtt/xiaomi_temp_living', payload '{"temperature":22.35,"linkquality":47,"humidity":97.77,"pressure":1014,"battery":97,"voltage":2995}'

In my configuration.yaml I have:

sensor:
  
  - platform: mqtt
    state_topic: "zigbee2mqtt/xiaomi_temp_living"
    name: "Living Temperatuur"
    unit_of_measurement: "°C" 
    value_template: "{{ value_json.temperature }}"

But I don’t get the temperature value in my frontend panel, I get unknown.

What is wrong? Please advice.
Many thanks

  • Which MQTT Broker are you using?
  • Have you configured Home Assistant to connect to the broker?

I use mosquitto and hassio.
The broker is working when I connect a esp8266 directly with a payload to mosquitto.

# Mqtt
mqtt:
  broker: homeassistant 
  discovery: true 
  discovery_prefix: homeassistant
  birth_message:
    topic: 'hass/status'
    payload: 'online'
  will_message:
    topic: 'hass/status'
    payload: 'offline'

  
sensor:
  
  - platform: mqtt                          # That is working
    state_topic: "sensor/slkamer/temp"
    name: "Slaapkamer Temperatuur"
    unit_of_measurement: "°C"
   
  - platform: mqtt                          # That is working
    state_topic: "sensor/slkamer/hum"
    name: "slaapkamer vochtigheid"
    unit_of_measurement: "%" 
    
  - platform: mqtt                           # That is NOT working
    state_topic: "zigbee2mqtt/xiaomi_temp_living"
    name: "Living Temperatuur"
    unit_of_measurement: "°C" 
    value_template: "{{ value_json.temperature }}"

So I think the connection from home assistant to mosquitto is ok.

OK, so we are confident that Home Assistant is connected to the broker and can receive MQTT messages.

Let’s try an experiment. Create this simple sensor.

  - platform: mqtt
    state_topic: "zigbee2mqtt/xiaomi_temp_living"
    name: "Test Sensor"

It should report the entire message that it receives:

{"temperature":22.35,"linkquality":47,"humidity":97.77,"pressure":1014,"battery":97,"voltage":2995}```

I added the extra sensor in configuration.yaml

#Sensors
sensor:
  # Weather prediction
  - platform: yr
  
  - platform: mqtt
    state_topic: "sensor/slkamer/temp"
    name: "Slaapkamer Temperatuur"
    unit_of_measurement: "°C"
   
  - platform: mqtt
    state_topic: "sensor/slkamer/hum"
    name: "slaapkamer vochtigheid"
    unit_of_measurement: "%" 
    
  - platform: mqtt
    state_topic: "zigbee2mqtt/xiaomi_temp_living"
    name: "Living Temperatuur"
    unit_of_measurement: "°C" 
    value_template: "{{ value_json.temperature }}"
    
  - platform: mqtt
    state_topic: "zigbee2mqtt/xiaomi_temp_living"
    name: "Test Sensor"

then I had a look in the states and see:

Now you can see that there are 2 sensors with unknown. Or do I have to look somewhere else?

sensor.test_sensor is acting as a simple MQTT client, subscribed to the topic zigbee2mqtt/xiaomi_temp_living. The result of this test suggests that no messages are published to that topic.

Whenever one is faced with debugging an MQTT problem, I always suggest using an MQTT client (I recommend MQTT Explorer but even mosquitto_sub will do the job) to serve as an independent observer. Use the client to subscribe to the topic and examine the contents of the received messages.

Thanks, I will install MQTT explorer and do a test to the topic and let you know what the result is.

I’am Back.
I downloaded the mqtt explorer and connected with hassio IP address
Then I see the esp8266 topic temp en hum
Some switches that comes from another esp8266 but no zigbee2mqtt topics
see picture

Where can I find the zigbee2mqtt topics?

You will have to check the configuration of zigbee2mqtt because MQTT Explorer is showing that the broker located at 192.168.1.11 does not contain the topic: zigbee2mqtt/xiaomi_temp_living That explains why the state is unknown for both sensor.living_temperatur and sensor.test_sensor.

That the zigbee2mqtt configuration:

devices:
  '0x00158d0003498ebc':
    friendly_name: xiaomi_temp_living
    retain: false
homeassistant: true
mqtt:
  base_topic: zigbee2mqtt
  discovery: true
  server: mqtt://homeassistant
permit_join: true
serial:
  port: /dev/ttyACM0

I don’t use zigbee2mqtt so I’m not qualified to answer questions about its configuration. However, according to the zigbee2mqtt’s documentation, there are several other parameters that can be used to configure it. For example, have you set a username and password on your broker? If you did, then you may need to configure zigbee2mqtt’s user and password options. Also, I don’t see a discovery option in zigbee2mqtt’s documentation. I know that’s an option in the configuration of Home Assistant’s MQTT integration.

Many thanks, Problem solved. I have to put the username and password in the config.

Glad to hear it’s working now.

Please mark my post with the ‘Solution’ indicator. It will make it easier for other users to find it should they encounter a similar problem.