Help getting MQTT (Mosquitto) to display as sensor

Hi,

I’ve been trying to monitor CO2 levels in my office and have setup a RaspberryPi Zero to send sensor data via MQTT to HA. I believe I have followed the instructions to install the Mosquitto Broker using the Hass.io addins screen.

CONFIGURATION.YAML

mqtt:
  broker: 192.168.0.61
  port: 1883
  username: myuser
  password: somepass
  birth_message:
    topic: 'hass/status'
    payload: 'online'
  will_message:
    topic: 'hass/status'
    payload: 'offline'

sensor:
  - platform: mqtt
    name: "Roaming CO2"
    state_topic: "sensors/test"
    unit_of_measurement: "ppm"

To test that Mosquitto is working, i have installed the Mosquitto client tools on my laptop (Win10) and done the following to subscribe and then publish data to the topic. This appears to work and I get the value returned successfully.

TEST SUBSCRIBE

mosquitto_sub -h 192.168.0.61 -p 1883 -u myuser -P somepass -d -t sensors/test

TEST PUBLISH

mosquitto_pub.exe -h 192.168.0.61 -p 1883 -u myuser -P somepass -t sensors/test -m "899"

Unfortunately I never see the sensor appear on my dashboard. I’m still quite new at this and would appreciate any tips or guidance on what I might be doing wrong.

Thanks

Does the sensor show up in Dev Tools/states?
You need to configure MQTT Discovery.

Thanks @VDRainer. I added the discovery: true setting to configuration.yaml as suggested but it hasn’t helped. I do not see the sensor in Dev Tools/States.

Any other tips I could try?

mqtt:
  discovery: true
  broker: !secret mqtt_broker
  port: !secret mqtt_port
  username: !secret mqtt_user_name
  password: !secret mqtt_password
  birth_message:
    topic: 'hass/status'
    payload: 'online'
  will_message:
    topic: 'hass/status'
    payload: 'offline'

Do you generate the accesscontrollist as dirscribed here?: https://www.home-assistant.io/addons/mosquitto/#using-mosquitto-with-hassio

Your generated user and the user “homeassistant” must be stored there to use discovery.