MQTT simple topic clarification

Home Assistant 0.114.2
MQTT broker 5.1 supervisor installed and configured.

Logs show my client connected:
1597755930: New client connected from 192.168.55.134 as esp32_greenhouse (p2, c1, k15, u’mqtt’).

It sends data every 60 seconds, which if I manually subscribe to the topic (Configuration > integrations > MQTT > configure):
homeassistant/greenhouse/temperature
I can see data coming in:

Message 0 received on homeassistant/greenhouse/temperature at 13:20:
23.5
QoS: 0 - Retain: false

BUT, i’ve got discovery to true in my configuration.yaml file like this:

mqtt:
  discovery: true
  discovery_prefix: homeassistant

Enable newly added entities set to ON. But yet the device/integration never appears.

Am I missing something in the topic I created as

homeassistant/greenhouse/temperature

Or something else why this doesn’t work?
thanks,
Andy

discovery_prefix: homeassistant is used to declare sensors, not to publish sensor data
so if your sensor is not able to generate the required data to allow HA to discover it, it won’t work.
If that’s the case, I suggest you change your MQTT settings to use a different topic (sensors for example) and publish your data there under the sensor name, e.g. sensors/greenhouse/temperature
Then you need to manually create a sensor in your config that pulls info from this newly created topic.

Hope this makes sense…

Aha, thank you for that explanation, yes that would confirm what’s happening.

So if I created this in configuration.yaml:

sensor:
    - platform: mqtt
      state_topic: 'homeassistant/greenhouse/temperature'
      name: 'Greenhouse Temperature'
      unit_of_measurement: '°C'

That would work manually. But if I want to autodiscover then I’d need to do a publish with the config payload.
So perhaps when the device first connects (boots up) it publishes the declaration of the sensor using topic:
homeassistant/sensor/greenhouse/temperature/config

And payload:

{"name": "Greenhouse Temperature", "state_topic": "sensor/temperature", "device_class": "sensor", "unique_id": "greenhouse_temperature"}

Sorry if this is a bit in-depth, is there a doc that has these methods/payloads that helps as I’m struggling to find one that definitively does this?

Thanks,
Andy

This is one of my auto-discovery messages for temperature :

topic : homeassistant/sensor/xiron_3201/temperature/config

message :


{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ value_json.TEMP }}","state_topic":"rflink/Xiron-3201","name":"eetkamer_temperature","unique_id":"eetkamer_temperature","device":{"identifiers":["xiron_3201"],"name":"xiron_3201","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}

1 Like

That’s ideal, thank you @francisp

That’s done the job, so I think if I make it submit that from my devices once at start up then periodically to ensure it doesn’t lose it, that’ll work.

Great, slowly getting the hang of this now!

One last question @francisp (sorry!)
When submitting your data, what topic do you use?

 homeassistant/sensor/xiron_3201/temperature

Or

homeassistant/sensor/xiron_3201/TEMP

Thanks!

In this case, data is arriving on rflink/xiron_3201