MQTT Discovery light entity

Hi All,

I am writing some code for the MQTT discovery of a light-component.
I am trying to either implement it using default schema OR Json schema
(There is a different set of configuration variables depending on what schema you choose)

I started sending the discovery topic and payload for a default light-component to HA, and indeed an MQTT device is created. And I confirmed the “config” message that the MQTT broker received with the MQTT explorer.

{
  "name": "D_Lamp",
  "obj_id": "Dmqtt_lamp255C",
  "uniq_id": "mqtttst255CS",
  "sup_clrm": "rgb",
  "stat_t": "stat/mqtt_test255C/d_switch",
  "cmd_t": "cmnd/mqtt_test255C/d_switch",
  "bri_stat_t": "stat/mqtt_test255C/d_bright",
  "bri_cmd_t": "cmnd/mqtt_test255C/d_bright",
  "avty_t": "stat/mqtt_test255C/avail",
  "device": {
    "ids": "devdiscTST255C",
    "name": "Device Test255C"
  }
}

But the light component I want to create has an RGB strip. So I add a key
{“rgb_stat_t” , “d_rgbstate”}
(which is directly from the other example for a light with RGB
But when I then create the light, the config message for the light component is empty. (And any other entity created after the light, but in the same Device… is not created)
The same happens when I add the “rgb_cmd_t” (or both, as is done in an example on the MQTT light documentation

  • I have already made sure the Json [doc] size is big enough (1024 bytes)

So now my questions are:

  • how do I check what Config message is received by HA (is it in a logfile somewhere?)
  • Is it possible that some combination of keys/variables create conflicts? (Do I need to remove some key when my light has rgb for example?)

I can’t seem to get a light discovered with rgb and white.

Update:

Have tried rgbw (with its state and command topics) instead of rgb(with its state and command topics)
And this works … I get a light component with a color wheel etc

{
  "name": "D_Lamp",
  "obj_id": "Dmqtt_lamp255C",
  "uniq_id": "mqtttst255CS",
  "sup_clrm": "rgbw",
  "stat_t": "stat/mqtt_test255C/d_switch",
  "cmd_t": "cmnd/mqtt_test255C/d_switch",
  "bri_stat_t": "stat/mqtt_test255C/d_bright",
  "bri_cmd_t": "cmnd/mqtt_test255C/d_bright",
  "rgbw_stat_t": "stat/mqtt_test255C/d_rgb_ste",
  "rgbw_cmd_t": "cmnd/mqtt_test255C/d_rgb_cod",
  "avty_t": "stat/mqtt_test255C/avail",
  "device": {
    "ids": "devdiscTST255C",
    "name": "Device Test255C"
  }
}

Hello Oscar1,

By default the homeassistant discovery topic doesn’t start with cmnd or stat.

Are you using the right topics?

Hi Sir,
I am not sure what you mean by discovery topic doesnt start with cmnd

Does my topic show that?

stat_t and cmd_t are MQTT configuration variables, (am I using the wrong terminology?)

if using default, you have to set a ~ topic or every topic should start with ‘homeassistant’

Read the docs over again or look at some examples. I have quite a few in this blueprint…

Thanks a lot. I will have a look tomorrow.(its close to midnght here)

I am quite new to using MQTT.

In my understanding the line
"stat_t": "stat/mqtt_test255C/d_switch",
is used to indicate to Home assistant , that it should expect to find the state of this entity at the broker under topic “stat/mqtt_test255C/d_switch”

I organized my state topics to all start with stat, because then all the state messages are under the same header in the MQTT explorer.
All my command topics (where Home Assistant should publish commands for my device) start with cmnd. They all are under a header cmnd in the MQTT explorer

It would for an mqtt sensor.
If you do not change the default and want to use home assistant discovery, you need to use homeassistant/an_Integration/entity etc.

HA needs a specific task path to monitor and it starts with ‘homeassistant’. It can’t watch everything. You can change that (but please don’t), but it can only watch one top level topic like that.

That’s correct.

What is the topic you have chosen to publish the discovery payload you have configured?

Is it something like this:
homeassistant/light/foo/config

I think I found a mistake in the (arduino) code that creates the Config messages.

I use a char buffer to construct a the key-value pair for every single Config variables (and then copy that into the Json Document)

I think my buffer was too small
I used :
{"rgbw_stat_t" , "d_rgb_state" }

My Code then adds unique identifiers to creates a buffer with:
"rgbw_stat_t": "stat/mqtt_test255C/d_rgb_state"
where stat is for my organisation
mqtt_test is my Device and 255C is the last two digits of the Mac Address

The char buf[30] was only 30

Should work better now…

Thanks anyway for your fast response. Appreciate it.!

Glad to hear you found the source of the problem.

topic is:

homeassistant/sensor/mqtt_test255C/config

(example was for a sensor, should be different for a light. My code handles it correctly, because a light component can indeed be created)

Discovery topic looks fine (for a sensor). Anyways, the root cause was something completely different (truncation due to undersized buffer).

Spent way too much time on a sunday … LoL

Thanks Sir :slight_smile:

1 Like

Oh… Thank 123Taras too… I never checked who sent the message.