MiLight bulbs not switching reliably

Just set up OpenHAB2 and connected my Milight Bulbs.
As first sitemap I created a sitemap with one general switch for all bulbs and one dedicated switch per bulb.

Because there is no on / off in the openhab2 binding, I created rules according to this post.

In order to maintain the state of the dedicated buttons I decided to create an additional rule for the general switch that doesn’t address the “all” channel. Instead it switches the dedicated switches one by one.
Unfortunately this doesn’t work reliably. The bulbs react kind of randomly - sometimes all bulbs react, sometimes only one or several.

This is my sitemap:

sitemap philli label="My Hood"
{
    Frame label="Licht gesamt" {        
        Switch item=LIGHT_ALL mappings=[ON="An", OFF="Aus"]        
    }
    Frame label="Licht einzeln" {
        Switch item=LIGHT_TV mappings=[ON="An", OFF="Aus"]
        Switch item=LIGHT_COUCH mappings=[ON="An", OFF="Aus"]
        Switch item=LIGHT_FLUR mappings=[ON="An", OFF="Aus"]
        Switch item=LIGHT_WINTERGARTEN mappings=[ON="An", OFF="Aus"]
    }
}

These are the items:

Switch LIGHT_ALL        "Alle Lampen"
Color LIGHT_ALL_COLOR "Label" {channel="milight:rgbLed:ACCF23468948:6:ledcolor"} 

Switch LIGHT_WINTERGARTEN    "Wintergarten"
Color LIGHT_WINTERGARTEN_COLOR "Label" {channel="milight:rgbLed:ACCF23468948:10:ledcolor"} 

Switch LIGHT_TV    "TV"
Color LIGHT_TV_COLOR "Label" {channel="milight:rgbLed:ACCF23468948:7:ledcolor"}

Switch LIGHT_COUCH    "Couch"
Color LIGHT_COUCH_COLOR "Label" {channel="milight:rgbLed:ACCF23468948:8:ledcolor"}

Switch LIGHT_FLUR    "Flur"
Color LIGHT_FLUR_COLOR "Label" {channel="milight:rgbLed:ACCF23468948:9:ledcolor"}

And here are the rules:

rule "all lights on"
    when
        Item LIGHT_ALL received command ON
    then
        //sendCommand(LIGHT_ALL_COLOR, new HSBType (new DecimalType(0),new PercentType(0),new PercentType(100)))
        sendCommand(LIGHT_WINTERGARTEN, "ON")
        sendCommand(LIGHT_TV, "ON")
        sendCommand(LIGHT_COUCH, "ON")
        sendCommand(LIGHT_FLUR, "ON")
        
        //sendCommand(LIGHT_ALL_COLOR, new HSBType (new DecimalType(0),new PercentType(0),new PercentType(100)))
    end
    
rule "all lights off"
    when
        Item LIGHT_ALL received command OFF
    then
        sendCommand(LIGHT_WINTERGARTEN, "OFF")
        sendCommand(LIGHT_TV, "OFF")
        sendCommand(LIGHT_COUCH, "OFF")
        sendCommand(LIGHT_FLUR, "OFF")
        
        //sendCommand(LIGHT_ALL_COLOR, new HSBType (new DecimalType(0),new PercentType(0),new PercentType(0)))
    end

    
rule "wintergarten ON"
    when
        Item LIGHT_WINTERGARTEN received command ON
    then
        logInfo("LIGHT", "Turn Wintergarten ON")
        sendCommand(LIGHT_WINTERGARTEN_COLOR, new HSBType (new DecimalType(0),new PercentType(0),new PercentType(100)))
    end
    
rule "wintergarten OFF"
    when
        Item LIGHT_WINTERGARTEN received command OFF
    then
        logInfo("LIGHT", "Turn Wintergarten OFF")
        sendCommand(LIGHT_WINTERGARTEN_COLOR, new HSBType (new DecimalType(0),new PercentType(0),new PercentType(0)))
    end
    
    
rule "light tv on"
    when
        Item LIGHT_TV received command ON
    then
        logInfo("LIGHT", "Turn TV ON")
        sendCommand(LIGHT_TV_COLOR, new HSBType (new DecimalType(0),new PercentType(0),new PercentType(100)))
    end
    
rule "light tv off"
    when
        Item LIGHT_TV received command OFF
    then
        logInfo("LIGHT", "Turn TV OFF")
        sendCommand(LIGHT_TV_COLOR, new HSBType (new DecimalType(0),new PercentType(0),new PercentType(0)))
    end
    
    
rule "LIGHT_COUCH_ON"
    when
        Item LIGHT_COUCH received command ON
    then
        logInfo("LIGHT", "Turn Couch ON")
        sendCommand(LIGHT_COUCH_COLOR, new HSBType (new DecimalType(0),new PercentType(0),new PercentType(100)))
    end
    
rule "LIGHT_COUCH_OFF"
    when
        Item LIGHT_COUCH received command OFF
    then
        logInfo("LIGHT", "Turn Couch OFF")
        sendCommand(LIGHT_COUCH_COLOR, new HSBType (new DecimalType(0),new PercentType(0),new PercentType(0)))
    end
    
    
rule "LIGHT_FLUR_ON"
    when
        Item LIGHT_FLUR received command ON
    then
        logInfo("LIGHT", "Turn Flur ON")
        sendCommand(LIGHT_FLUR_COLOR, new HSBType (new DecimalType(0),new PercentType(0),new PercentType(100)))
    end
    
rule "LIGHT_FLUR_OFF"
    when
        Item LIGHT_FLUR received command OFF
    then
        logInfo("LIGHT", "Turn Flur OFF")
        sendCommand(LIGHT_FLUR_COLOR, new HSBType (new DecimalType(0),new PercentType(0),new PercentType(0)))
    end

Any idea why the bulbs react so unreliably?

Try to sleep for 200ms between the commands when sending multiple commands. The bridge is not capable of sending commands to the bulbs if they are too close together. This solved the problem for me.

Tried this already - even with 2000ms, without success. Did you do this with openhab 1 or 2? I have the feeling that the milight binding for openhab2 is still a bit buggy since I don’t get discomode working, too.

Hey all,

there is a new version of the milight binding in progress, please have a look at this thread:

Especially delays between commands and repeating of commands is implemented more reliable now and is configurable, too.

@peez: It is not necessary to make rules for On/Off. You can just use a switch for the color channel, the binding will figure out what your intention is.

Cheers,
David