ESP32 - MQTT Device Discovery

Hello

I’m trying to include a ESP32 to HA via the new MQTT Device Discovery feature. Currently the ESP32 does nothing, it only sends the mqtt message to the “homeassistant/device/3823147816S/config” topic telling that the device has a light entity.

But HA doesn’t discover it.

Can someone tell me what is wrong, incoherent or missing please?

    {
      "device": {
        "name": "My MQTT Device",
        "ids": [
          "mymqttdevice01"
        ]
      },
      "o": {
        "name": "foobar",
        "mf": "",
        "mdl": "ESP32",
        "sw": "1.24",
        "hw": "0.45",
        "cu": "http://192.168.1.226/config"
      },
      "cmps": {
        "3823147816S": {
          "p": "light",
          "name": "My MQTT Light",
          "obj_id": "mqtt_light",
          "uniq_id": "3823147816S",
          "stat_t": "stat/mydevice/switch",
          "cmd_t": "cmnd/mydevice/switch",
          "brightness": "true",
          "bri_scl": "100",
          "bri_stat_t": "stat/mydevice/brightness",
          "bri_cmd_t": "cmnd/mydevice/brightness"
        }
      }
    }

Thank you

Hi,
Start simple, build up - and more importantly, use the search facility on this forum for worked MQTT Discovery examples to adapt:

# Send a MQTT Discovery message to create a soil moisture sensor
# Note the difference between the DEVICE name and the moisture ENTITY (allowing several sensor channels)
# Note the additional DEVICE parameters such as manufacturer, version, and the 'suggested_location' which can be used to set the Area
# Note the additional ENTITY  parameters such as an icon, the device class and unit of measurement which both allow long-term logging to give the user data graphs.
mosquitto_pub -r -h 127.0.0.1 -p 1883 -t 'homeassistant/sensor/grow-1_chan1/config' --retain -m '{"name":"Channel 1 ENTITY", "stat_t":"tele/grow-1/SENSOR", "val_tpl":"{{value_json.Channel1}}", "avty_t":"tele/grow-1/LWT", "pl_avail":"Online", "pl_not_avail":"Offline", "uniq_id":"grow-1_chan1", "dev": {"ids":["grow-1"], "name":"Grow 1 DEVICE", "mf":"Great Devices", "mdl":"Grow Sensor", "sw":"0.2", "sa":"Conservatory"}, "icon":"mdi:sprout", "dev_cla":"humidity", "unit_of_meas":"%", "expire_after":"1200", "frc_upd": true}'

MQTT discovery is instant, so you should be able to quickly prototype your code quickly.

If you need more help, the community needs details like:

  • What software / firmware / language / other are you using for this?
  • What entity are you trying to create? (light / switch / dimmer - all different)
  • What does MTT Explorer show in your topics?

If this helps, :heart: this post!

1 Like

I have got the temperature, voltage, power, current sensors to be recognized :grinning:
You were right, start simple and build up.

But there is one entity I don’t know how to program.
I need a light entity where I can adjust the brightness and also the color temperature (1800-4000K)

I found out how to do it for the brightness, but not for the color_temp.
Any help please?

"cmps": {
    "bla1": {
      "p": "light",
      "name" : "mqtt_json_light_1",
      "obj_id": "mqtt_light",
      "uniq_id": "3823147816S",
      "state_topic" : "home/light1",
      "command_topic" : "home/light1/set",
      "brightness" : true,
      "brightness_scale" : 255,
      "supported_color_modes" : ["COLOR_TEMP"],
      "color_mode_state_topic" : "home/light1/colortemp/set",
      "bri_stat_t": "stat/mydevice/brightness",
      "bri_cmd_t": "cmnd/mydevice/brightness"
    }
	}