Need help setting up MQTT sensor

Hi there! I’m struggling to connect a sensor via MQTT and display it in HA.

Sending the MQTT message via wifi, mosquitto and displaying in node-red works:
Schermafbeelding 2021-07-20 om 16.45.14
The -1 is the value from the sensor. “Online” is a string I let my esp32 put out as its first message.

Now I would like to display the values in HA. So I tried setting up the sensor like this:

# MQTT
- platform: mqtt
  name: Plant moisture sensor
  state_topic: "home/sensor/plant1"
  unique_id: "sensor.plant_moisture"
  availability:
    - topic: "home/sensor/plant1"
    - payload_available: "online"

Under entities, I can see it was added via the mqtt integration:


But the status of it remains “Restored”, and when I try to display the value in the dashboard it says “unavailable”.

I’m lost and don’t know where to look for. I’m also quite new to this so forgive me :smile:

Any thoughts anyone? Thanks

Found the solution to my problem: I had setup my mqtt broker with a seperate username / password and didn’t set it in the configuration of HA.

I guess that was the reason the sensor was found, but it wasn’t readable because of the wrong credentials.