ESP8266 Milight Hub and MQTT to control Milight RGB-CCT

Hi,

I been running ESP8266 Milight Hub with HASS to control my bulb Milight RGB-CCT and it work perfectly. I can control state, color, brightness, color temperature, and the effects. Only Saturation doesn’t work since HA expect to have “white_value” instead of “saturation” which is another problem I’ll fix later.

So the issue I’m having is with the status in the frontend panel (Standard and Lovelace), it only update when it is ON or OFF event. If I dim/bright or change the color of the light from the milight remote, iOS device or another browser, it doesn’t update on the frontend panel.

I’m running HASSIO v80.3 on RP3 with Mosquitto MQTT.

# Milight Type: MQTT_JSON      
      - name: "Bureau_lamp-States"
        platform: mqtt_json  
        command_topic: "milight/commands/0x72C6/rgb_cct/1"
        state_topic: "milight/states/0x72C6/rgb_cct/1"
        brightness: true
        rgb: true
        color_temp: true
        white_value: true
        qos: 0
        optimistic: false
        effect: true
        effect_list: [0, 1, 2, 3, 4 ,5, 6, 7, 8]

Result from MQTT client:
Topic: milight/states/0x72C6/rgb_cct/1
{“state”:“ON”,“brightness”:255,“color_temp”:153}

Topic: milight/updates/0x72C6/rgb_cct/1
{“brightness”:255}

I know my state_topic work since I’m receiving the state status ON or OFF, but any reason why other status doesn’t update on the front panel?

Thanks

1 Like

Messages like this will be ignored, as the topic does not match the state_topic parameter.

Finally got it working with HA Frontend Web and Milight remote but it is unknown if a reboot HASS just had make things work. Anyway, I did add some tweak:

HASSIO

  • Add the MQTT “qos:1” for feedback confirmation.
  • Remove White_Value: true

Milight hub

  • Upgrade to Milight hub to latest version 1.85
  • In Radio Tab, Disable Automatic Mode Switching (White vs RGB)
  • In MQTT, Only set the follow state:
    – state, brightness, color, color_temp, effect

Configuration.yaml

  light:
  # Milight Type: MQTT_JSON      
  - name: "Bureau_lamp"
    platform: mqtt_json  
    # The command topic is derived by substituting real values for the
    # tokens in the setting mqtt_topic_pattern (e.g., "rgb_cct" for
    # ":device_type"):
    #                                    ______________ Device ID
    #                                    |      ________ Device Type
    #                                    |     |     ___ Group ID
    #                                    |     |    |
    #                                    v     v    v
    command_topic: "milight/commands/0x72C6/rgb_cct/1"
    state_topic: "milight/states/0x72C6/rgb_cct/1"
    qos: 1
    optimistic: false
    retain: true
    
    #-- Bulb configuration
    brightness: true
    rgb: true
    color_temp: true
    # HA missing scale temp feature. On todo list...
    #color_temp_min: 0 
    #color_temp_max: 100
    
    # Milight hub command is "saturation", so white_value doesn't take effect. On todo list...
    #white_value: true 
    
    effect: true
    #Effect list 0=Full, 1=White, 2=RGB, 3=Full hard, 4=Disco, 5=Red Flash, 6=Green Flash, 7=Blue Flash, 8=White Flash]
    effect_list: [0, 1, 2, 3, 4 ,5, 6, 7, 8]  
    #effect_speed: true # Milight hub support it. HA missing feature. 
    
    #-- Milight bulb doesn't support it :(. Need workaround to be done via software on HA or Milight hub
    #transition: true
4 Likes

@gpbenton Not sure I understand your though as this is a topic not parameters. Also I’m using the platform MQTT JSON Light not MQTT Light

Hi Starwolf,

Can you elaborate on what you mean by “Milight hub command is “saturation”, so white_value doesn’t take effect.”? I am trying to get full control over my rgb-cct milight lights as well. Thank you for the work so far!

Ha_enthusiast

Thanks for the example. I got everything setup! Now My lights stay synced with the remote. Exept for the 0/All device.

How can i setup the lights if i turn off my light with the remote:
milight/state/0x1F4D/rgb_cct/0
all my lights go out in HA

Right now i have this in Node-Red

[{"id":"57216e89.dd502","type":"mqtt out","z":"620d0bfb.65bb64","name":"","topic":"milight/state/0x1F4D/rgb_cct/1","qos":"","retain":"","broker":"da157e47.78991","x":890,"y":580,"wires":[]},{"id":"96fdfa11.081c48","type":"mqtt in","z":"620d0bfb.65bb64","name":"","topic":"milight/update/0x1F4D/rgb_cct/0","qos":"2","broker":"da157e47.78991","x":570,"y":640,"wires":[["57216e89.dd502","79fc725b.c7137c","959d43ca.fcbc3","96bad0ea.790a"]]},{"id":"79fc725b.c7137c","type":"mqtt out","z":"620d0bfb.65bb64","name":"","topic":"milight/state/0x1F4D/rgb_cct/2","qos":"","retain":"","broker":"da157e47.78991","x":890,"y":620,"wires":[]},{"id":"959d43ca.fcbc3","type":"mqtt out","z":"620d0bfb.65bb64","name":"","topic":"milight/state/0x1F4D/rgb_cct/3","qos":"","retain":"","broker":"da157e47.78991","x":890,"y":660,"wires":[]},{"id":"96bad0ea.790a","type":"mqtt out","z":"620d0bfb.65bb64","name":"","topic":"milight/state/0x1F4D/rgb_cct/4","qos":"","retain":"","broker":"da157e47.78991","x":890,"y":700,"wires":[]},{"id":"da157e47.78991","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

In order to be able to capture group 0 commands from the physical remotes you need to use a previous firmware (before 1.8.x).

In firmware after 1.8.1 group 0 is not captured anymore (although sending it from the emulator still works).

Alternatively, you can use two gateways: one with an older firmware (pre 1.8.x) and another updated to the latest version. Then keep the state topic only for the older one so that you’re not flooding MQTT.

Does ESP8266 Milight Hub work with milight android app? I have one ibox2 but 4 channels/zone is too limiting so I am considering getting another ibox2 or making an esp8266 hub.

Definitely go with ESP8266 hub (ESPMH) as you need only one hub for the entire house and can control a virtually unlimited number of lights (can also setup a second hub to increase coverage or add redundancy case the main hub is offline). Look for the MiLight/Limitless topics also for the MQTT setup.

The Android app works with ESPMH; however, I don’t know if you’ll ever find any use for it as:

  1. HA controls are superior;
  2. The app on the phone is probably using home calling of Chinese servers quite often.

Anyway, I’m usually using the original apps that come with most of the devices only for the initial setup/pairing/firmware upgrade (after that I only use HA).

1 Like

I got the components, built the ESPMH and paired my led strips, set up mqtt and finally I can control each strip individually. HA automatically discovered the strips and I control them through entity cards and a few scripts (combination of strips, different brightness). I have two issues, though:

  • I can’t put the strips into night mode in HA. I can do that through ESPMH web interface
  • when I turn the strips on, entity card often shows their brightness as 100% which is incorrect.

First issue is fixed, was a bug in [1.10.0-dev.8]

I don’t use MQTT Discovery and have no issues whatsoever (although I’m using multiple remote IDs for each bulb they’re in sync) so it might be related.

Could you try monitoring MQTT payloads when sending commands from HA to the led strip? If using defaults, I think topics would be
homeassistant/light/alias_of_the_light_in_espmh/set for the commands and homeassistant/light/alias_of_the_light_in_espmh/state respectively

You can also send manual commands with mosquitto_pub to test if the brightness is accurate.

Alternatively, there might be issues with the NRF24L01 board causing the ESP to mishandle packets (there are some tips and tricks in the wiki).

I should mention that MiLight bulbs are turning on with the last known value regardless of the brightness value used in the command (then it will adjust brightness up or down to match it). In order to prevent temporary blindness and issues case power outages during the night I set brightness to 1 before turning the bulb off. When turned on again, brightness is at 1 and this will also prevent flickering if the current settings for colors are too much different than the previous ones.

1 Like

Im trying to get this working but am new to mqtt, i feel like im missing something. Could you please show screenshots of your mqtt setup on the milight hub

Try the followings:

milight/commands/:device_id/:device_type/:group_id
mililight/updates/:device_id/:device_type/:group_id
milight/states/:device_id/:device_type/:group_id
milight/status/:device_id/:device_type/:group_id

What is your setup in HA the lights?

1 Like

thanks for the help, i’m not sure what was the final piece of the puzzle but its working, ill update with my settings later. thank you :slight_smile:

You’re welcome.

I think the topic fields are expected to be wildcard based, not static IDs (as you won’t be able to control other lights).

Yeah, so i was just looking at what else i changed before it started working and i did at a new user for Mosquitto and a password then a couple restarts and everything is working as it should

Hi there

Can someone provide the settings of how they got this working… I lost now countless hours and don’t seem to be able to get the mqtt connection working properly.

I managed to get the hub itself working and i can control the light from the web interface.

This is my current config

light:
 - name: "Wohnzimmer"
   command_topic: "milight/commands/0x1111/rgbw/1"
   state_topic: "milight/states/0x1111/rgbw/1"
   <<: &MILIGHT_PARAMS
     platform: mqtt
     schema: json
     rgb: true
     brightness: true
     availability_topic: milight/client_status
     payload_available: 'connected'
     payload_not_available: 'disconnected'


The device also shows up no no enteties…

Hi,

It is not visible from the printscreen, but can you confirm that you have
milight/commands/:device_id/:device_type/:group_id for MQTT topic pattern in the ESPMH? (I don’t see the group_id field in the picture)

Actually you don’t need the availability section (it will cause more issues than solve).

Anyway, you might look for the light entities in Developer tools-> States