Mttq light triggers MQTT log, but doesn't show up - going nuts here! help please. #coronamakingmegonuts

So, i’ve got the updates and states command comming into MQTT log:

this is the config in my selfmade milight hub:

and this is the code in my configuration.yaml file:

light:
  - platform: mqtt
    name: "ledstrip2"
    command_topic: "milight/commands/:0xAAAA/:rgb_cct/:1 "
    state_topic: "milight/states/:0xAAAA/:rgb_cct/:1"
    qos: 1
    optimistic: false
    retain: true

and if I look in the integrations, MQTT has no devices.
with the above code a device is created but doesn’t do anything:

entity created through config

config in mqtt:

logins:
  - username: xxx
    password: yyy
anonymous: false
customize:
  active: false
  folder: mosquitto
certfile: fullchain.pem
keyfile: privkey.pem
require_certificate: false

so what am I doing wrong? why don’t i see an entity with working knows?

i started from scratch,
changed my command and state topics to something different.

I don’t understand that, while in developper tool, i clearly am getting all the info when listening to all topics #:

Message 4 received on milight/states/0xAAAA/rgbw/1 at 2:58 PM:
{
    "state": "ON",
    "brightness": 255,
    "color_temp": 370,
    "bulb_mode": "white",
    "color": {
        "r": 255,
        "g": 255,
        "b": 255
    }
}
QoS: 0 - Retain: true
Message 3 received on milight/commands/0xAAAA/rgbw/1 at 2:58 PM:
ON
QoS: 0 - Retain: true
Message 2 received on milight/status/0xAAAA/w/1 at 2:58 PM:
{
    "status": "connected",
    "firmware": "milight-hub",
    "version": "1.10.5",
    "ip_address": "192.168.1.38",
    "reset_reason": "Software/System restart"
}
QoS: 0 - Retain: true
Message 1 received on milight/status/0xAAAA/rgb_cct/1 at 2:58 PM:
{
    "status": "connected",
    "firmware": "milight-hub",
    "version": "1.10.5",
    "ip_address": "192.168.1.38",
    "reset_reason": "Software/System restart"
}

I still don’t get anything that I can toggle in home assistant…
it’s like the configuration in configuration.yaml and the info from the log file are missing something, but everything is the same!

possibly because milight/states/0xAAAA/rgbw/1 is different than milight/states/:0xAAAA/:rgb_cct/:1 ?
Not sure I understand why you’d have a column in the topic… I’d personally try and keep it as simple as possible, e.g. all lowercaps, no special characters

1 Like

yes, i removed them between screenshots

they are exactly the same now, but I still don’t see anything.

because of the configuration code, it generates an entity, but it’s an empty one and if you click it, i get:

This entity does not have a unique ID, therefore its settings cannot be managed from the UI.
it doesn’t control the light at all.

That is a perfect normal message for mqtt devices configured in yaml. Nothing to worry about, and not the reason your light does not work.

i think there’s something wrong with what I have in the hub and in my configuration code…

i’m trying different things now.

command_topic: "milight/0xAAAA/rgbw/1"  is this **MQTT topic pattern** in hub settings?
state_topic: "milight/state/0xAAAA/rgbw/1"  is this **MQTT state topic pattern** in heb settings?

are these correct?

If this is the payload received on milight/states/0xAAAA/rgbw/1

{
    "state": "ON",
    "brightness": 255,
    "color_temp": 370,
    "bulb_mode": "white",
    "color": {
        "r": 255,
        "g": 255,
        "b": 255
    }
}

then that’s in JSON format.

An MQTT LIght can be configured to use one of three different schemas:

  1. Default
  2. JSON
  3. Template

See: Comparison of light MQTT schemas

In your light’s configuration, you have not specified which schema it should use so Home Assistant uses Default. This schema does not know how to extract parameters out of the payload received via the state_topic. You would need to (minimally) specify state_value_template.

Alternately, you can use the JSON schema. This schema expects the JSON payload to be in a very specific format (i.e. specific key-names). Here’s an example from the documentation:

{
  "brightness": 255,
  "color_temp": 155,
  "color": {
    "r": 255,
    "g": 180,
    "b": 200,
    "x": 0.406,
    "y": 0.301,
    "h": 344.0,
    "s": 29.412
  },
  "effect": "colorloop",
  "state": "ON",
  "transition": 2,
  "white_value": 150
}

You JSON payload uses the same key-names as in the example therefore it appears to be compatible with the JSON schema.

I suggest you review the documentation for JSON schema and then add schema: json to the light’s configuration (then restart Home Assistant). The light’s configuration will look something like this:

light:
  - platform: mqtt
    schema: json
    name: ledstrip2
    command_topic: milight/commands/0xAAAA/rgb_cct/1
    state_topic: milight/states/0xAAAA/rgb_cct/1
    qos: 1

If it fails to work then we need to revert to using either the Default or Template schema and creating templates for state, brightness, rgb_color, etc.

feel like I’m getting close. i’ve addapted the code to this:

light:
  - platform: mqtt
    name: rgb1
    schema: json
    command_topic: "milight/0xAAAA/rgb_cct/1/"
    state_topic: "milight/0xAAAA/rgb_cct/1/state"
    qos: 1

now when I use MQTT developer tools to listen to # topic, i receive the following config:

Message 19 received on homeassistant/light/milight_hub_3009912/rgb_cct_0xAAAA_1/config at 9:50 AM:
{
    "schema": "json",
    "name": "Ledstrip2",
    "command_topic": "milight/0xAAAA/rgb_cct/1",
    "state_topic": "milight/0xAAAA/rgb_cct/1/state",
    "device": {
        "manufacturer": "esp8266_milight_hub",
        "sw_version": "1.10.5",
        "identifiers": [
            3009912,
            43690,
            "rgb_cct",
            1
        ]
    },
    "availability_topic": "milight/0xAAAA/rgb_cct/1/status",
    "payload_available": "connected",
    "payload_not_available": "disconnected",
    "brightness": true,
    "effect": true,
    "effect_list": [
        "night_mode",
        "white_mode",
        "0",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8"
    ],
    "rgb": true,
    "color_temp": true
}
QoS: 0 - Retain: true

If I turn on the light via the milight hub itself (through it’s ip address), i get:

Message 24 received on milight/0xAAAA/rgb_cct/1/update at 9:59 AM:
{
    "state": "ON"
}
QoS: 0 - Retain: false

and the the state info:

Message 25 received on milight/0xAAAA/rgb_cct/1/state at 9:59 AM:
{
    "state": "ON",
    "brightness": 252,
    "color_temp": 266,
    "bulb_mode": "white",
    "color": {
        "r": 255,
        "g": 255,
        "b": 255
    }
}

If I turn on the light via home assistant entity ledstrip" i see:

Message 36 received on milight/0xAAAA/rgb_cct/1/update at 10:01 AM:
{
    "state": "ON"
}

which is exactly the same as when I do it via the hub itself… only… the light doesn’t turn on…

the complete setup in milight hub MQTT is this:

what am i missing? i’m losing it, really, something that should be so simple doesn’t seem to work…

You have revealed new information. I did not know that the device publishes its configuration to:

homeassistant/light/milight_hub_3009912/rgb_cct_0xAAAA_1/config

That topic is for the use of Home Assistant’s MQTT Discovery service.

Here’s what I suggest:

Add this to the mqtt: section of configuration.yaml

discovery: true

Remove (or comment out) the entire configuration you’ve created for “ledstrip2”.
Restart Home Assistant.
Go to Configuration > Integrations > MQTT and you should see your device automatically discovered.

the config part is new for me too…

I did what you told me.
in configuration.yaml i have this now:

mqtt:
  broker: 192.168.1.6
  port: 1883
  discovery: true

in the integration in MQTT i have the hub now as device.

and if I click it, I have:

so no entity I can use…

Maybe I have to start again from scratch all over, create new milight hub,…

So, I’ve got an entity now, that follows everything I do in the milight hub (via ip).

If I turn it on, my Lovelace lamp turns on. If I change colour/brightness,… In the hub, it shows that change on my Lovelace card. I’ve never gotten this far… But…It doesn’t work the other way around… The milight ledstrip doesn’t take orders from home assistant! If I turn off the light in the light entity, nothing happens (and the slider jumps back on after a few seconds)
So mqtt is only working in one direction (from the milight hub to home assistant…
Why is my milight hub not capturing the updates?

Probably because the command_topic, or the payload published to the command_topic, is incorrect.

this is the comparison of the two:

milight hub:

Message 90 received on milight/0xAAAA/rgb_cct/1/update at 8:41 AM:
{
    "brightness": 245
}

but when I change the brightness on the lovelace card i get 3 messages:

Message 312 received on milight/0xAAAA/rgb_cct/1 at 8:48 AM:
{
    "state": "ON",
    "brightness": 186
}

followed by:

Message 313 received on milight/0xAAAA/rgb_cct/1/update at 8:48 AM:
{
    "state": "ON"
}

and

Message 315 received on milight/0xAAAA/rgb_cct/1/update at 8:48 AM:
{
    "brightness": 186
}

I don’t understand why he first sends a command to milight/0xAAAA/rgb_cct/1 ?
and the commands it sends to /update don’t make a change on the hub…

It is due to the way you set your topics for the gateway in the webpage. There are 3 topics:

  • command (in your case it should be milight/:device_id/:device_type/:group_id); obviously, this is the topic where commands are being sent to the gateway;
  • state (milight/:device_id/:device_type/:group_id/state or equivalent, with floating /state/ part of the topic); this topic receives the full state of the bulb and should be different than command topic as it will loop indefinitely if you set them the same;
  • update or delta (milight_gw/:device_id/:device_type/:group_id/update); this includes only changes from previous state; in HA you need command and state topic only, you don’t need delta.

Might not seem obvious, but MiLight receives ONLY A SINGLE command at a time (think like “turn on bulb”, “change brightness to 255”, “turn off bulb”, “change RGB to 255,20,80”, etc). Update topic is the response of the gateway to this single command, even if the command topic includes a lot more information (the state topic includes the full assumed state of the bulb/led strip as a result of each command).

Hope that helps

hmm…
so my setup in my milight hub is:

my setup in configuration.yaml:

# Example configuration.yaml entry
mqtt:
  broker: 192.168.1.6
  port: 1883 
  username: XXXXX
  password: YYYYY

# Example configuration.yaml entry
light:
  - platform: mqtt
    name: Ledstrip00
    schema: json
    command_topic: "milight/0xBBBB/rgb_cct/1"
    state_topic: "milight/0xBBBB/rgb_cct/1/state"

code in Mosquitto broker:

logins:
  - username: XXXXX
    password: YYYYY
anonymous: true
customize:
  active: false
  folder: mosquitto
certfile: fullchain.pem
keyfile: privkey.pem
require_certificate: false

log:

1585149120: New connection from 192.168.1.6 on port 1883.
[INFO] found XXXXX on local database
1585149121: New client connected from 192.168.1.6 as auto-0C2A3295-9858-D4B6-9386-2BF6F3B99B4D (p2, c1, k60, u'XXXXX')

developper mode: MQTT test log, listen to topic # (this is when I turn light off and on on milight hub :

Message 9 received on milight/0xBBBB/rgb_cct/1/update at 4:14 PM:
{
    "state": "ON"
}

Message 10 received on milight/0xBBBB/rgb_cct/1/state at 4:14 PM:
{
    "state": "ON",
    "brightness": 0,
    "color_temp": 363,
    "bulb_mode": "white",
    "color": {
        "r": 255,
        "g": 255,
        "b": 255
    }
}

i see an entity that’s been created due to my automation code, called light,
but it’s a dead entity. it doesn’t do anything.

the part I don’t get is , when I start listening to #

it gets this config file info:


Message 65 received on homeassistant/light/milight_hub_6103229/rgb_cct_0xBBBB_1/config at 4:21 PM:
{
    "schema": "json",
    "name": "Ledstrip00",
    "command_topic": "milight/0xBBBB/rgb_cct/1",
    "state_topic": "milight/0xBBBB/rgb_cct/1/state",
    "device": {
        "manufacturer": "esp8266_milight_hub",
        "sw_version": "1.10.5",
        "identifiers": [
            6103229,
            48059,
            "rgb_cct",
            1
        ]
    },
    "availability_topic": "milight/0xBBBB/rgb_cct/1/status",
    "payload_available": "connected",
    "payload_not_available": "disconnected",
    "brightness": true,
    "effect": true,
    "effect_list": [
        "night_mode",
        "white_mode",
        "0",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8"
    ],
    "rgb": true,
    "color_temp": true
}

where does it get this homeassistant/light/milight_hub_6103229/rgb_cct_0xBBBB_1/config from? do i need to adapt my topics to this format?

homeassistant/light/milight_hub_6103229/rgb_cct_0xBBBB_1/
homeassistant/light/milight_hub_6103229/rgb_cct_0xBBBB_1/update

Hi,

Try the following settings for the light:

light:
  - platform: mqtt
    name: Ledstrip00
    schema: json
    command_topic: "milight/0xBBBB/rgb_cct/1"
    state_topic: "milight/0xBBBB/rgb_cct/1/state"
    brightness: true
    rgb: true
    color_temp: true
    effect: true
    effect_list:
      - 0
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - white_mode
      - night_mode
    optimistic: true
    qos: 0

and these settings for the gateway:

  • command topic:
    milight/:device_id/:device_type/:group_id
  • state topic
    milight/:device_id/:device_type/:group_id/state

Unless you want to try more advanced stuff concerning update topic, you’re fine to go for the moment.

I think this is part of the MQTT discovery but I don’t use it as I have all MQTT entities manually set.

1 Like

That’s the MQTT Discovery topic published by the device.

When the device publishes to a discovery topic, the payload contains information that Home Assistant uses to create an entity. You don’t define the entity manually when it already defines itself via MQTT Discovery.

1 Like

hey, when you say:

and these settings for the gateway:

  • command topic:
    milight/:device_id/:device_type/:group_id
  • state topic
    milight/:device_id/:device_type/:group_id/state

what do you mean with gateway? do you mean milight hub settings? and do i enter exactly that or fill it in with 0xBBBB etc?

Change Milight Hub settings in MQTT area to the values I wrote.

1 Like