Xiaomi Smart Home Binding - Gateway light issue

Hi,
I’d like to report an issue with Xiaomi Smart Home Binding:

Dimmer Gateway_Brightness <dimmablelight> { channel="mihome:gateway:<GwID>:<ID>:brightness" }
Color Gateway_Color <rgb> { channel="mihome:gateway:<GwID>:<ID>:color" }

According to the document the above are items for gateway light. However the brightness in Color channel (Gateway_Color) doesn’t work, instead another channel Gateway_Brightness is needed.
Ideally I’d like only to use Color channel for control everything, it also creates problems if I want to expose it to HomeKit.

You’ll need to provide more detail. What happens when you issue a command to the Color Item? What happens when you issue a command to the Dimmer Item? What happens when you change the device outside of OH?

Do you have logs that show anything interesting (e.g. errors)?

Note, this isn’t filing an issue. How to file an Issue

Thanks will fire an issue properly. Below is what I see:

  1. The brightness in Color channel doesn’t do anything except that when it’s 0 it doesn’t allow me to change Hue and Saturation. It is not in sync with Brightness channel and when sending command to it no change to the light.
  2. The Dimmer controls the brightness so when sending command to it I can adjust brightness.
  3. When change state outside OH, the brightness in Color is not affected

@rlkoshak: looks like the mi smart home binding is not in the official OH repository, I find it here: openhab2-addons/README.md at master · fguiraldelli/openhab2-addons · GitHub
There is no way to report issue and looks like the binding is not updated for very long time, guess no chance to ask for a fix…

If it can’t be fixed, what you will need to do is as follows:

  1. Create a proxy Color Item to represent this device.
  2. Create a rule that when the Color Item linked to the channel changes to something different from the proxy Item’s hue and saturation, update the proxy Item. But only update the hue and saturation, never the dimmer.
  3. Create another rule when the Dimmer Item linked to the channel changes to something different from the proxy Item’s brightness, update the proxy Item’s brightness channel.
  4. Create a third rule when the proxy Item receives a command. If it’s ON/OFF, INCREASE/DECREASE, or just a single PercentType value send that command to the Dimmer Item. If the Color Item’s brightness value changed to something different from the Dimmer send that to the Dimmer Item as a command too. If the hue or saturation value changed and is different from the , send that as a command to the Color Item.
1 Like

Thank you for the hint, now I split brightness control from color control (in HomeKit I cannot do both at the same time anyways), it works better. However the code looks ugly. Any suggestion on how to make the code more readable? Appreciate your help!

rule "Sync brightness to proxy"
when
  Item Xiaomi_gateway_brightness changed 
then 
  var HSBType colour = Xiaomi_gateway_color.state as HSBType
  var HSBType old = Xiaomi_gateway_color_homekit.state as HSBType
  if(Xiaomi_gateway_brightness.state!= old.brightness){
    logInfo("Info", "Xiaomi: sync from xiaomi brightness(" + Xiaomi_gateway_brightness.state+ ") to homekit (" +old+ ")")
    var HSBType next = new HSBType(new DecimalType(colour.hue.intValue),new PercentType(colour.saturation.intValue),Xiaomi_gateway_brightness.state)
    Xiaomi_gateway_color_homekit.postUpdate(next)
  }
end

rule "Sync color to proxy"
when
  Item Xiaomi_gateway_color changed 
then 
  var HSBType colour = Xiaomi_gateway_color.state as HSBType
  var HSBType old = Xiaomi_gateway_color_homekit.state as HSBType
  if(colour.hue.intValue != old.hue.intValue || colour.saturation.intValue != old.saturation.intValue){
    logInfo("Info", "Xiaomi: sync lighting from xiaomi (" +colour+ ") and brightness " + Xiaomi_gateway_brightness.state+ " to homekit (" +old+ ")")
    var HSBType next = new HSBType(new DecimalType(colour.hue.intValue),new PercentType(colour.saturation.intValue),Xiaomi_gateway_brightness.state)
    Xiaomi_gateway_color_homekit.postUpdate(next)
  }
end

rule "Sync color or brightness from proxy"
when
  Item Xiaomi_gateway_color_homekit changed 
then 
  var HSBType colour = Xiaomi_gateway_color_homekit.state as HSBType
  var HSBType old = Xiaomi_gateway_color.state as HSBType
  if(colour.hue.intValue != old.hue.intValue || colour.saturation.intValue != old.saturation.intValue){
    logInfo("Info", "Xiaomi: sync color from homekit (" + colour + ") to xiaomi (" +old+ ")")
    var HSBType next = new HSBType(new DecimalType(colour.hue.intValue),new PercentType(colour.saturation.intValue), colour.brightness) 
    Xiaomi_gateway_color.sendCommand(next)
  }
  if(colour.brightness!= Xiaomi_gateway_brightness.state){
    logInfo("Info", "Xiaomi: sync brightness from homekit (" + colour.brightness + ") to xiaomi (" +Xiaomi_gateway_brightness.state+ ")")
    Xiaomi_gateway_brightness.sendCommand(colour.brightness)
  }
end

I see nothing ugly about the code. I think you need to sendCommand instead of postUpdate though, in some of these cases. When you postUpdate it only changes the Item’s state. It does not go to the binding and cause something to happen on the end device.

You could maybe apply Design Pattern: How to Structure a Rule which might make it a little simpler. But the overall approach is the same. You can move the lines of code around or combine them into fewer rules but it’s going to pretty much look the same no matter what you do.

Hi thanks for looking into it, I’m happy with the way how it works now, and I have sent an issue in OH Github in case somebody might want to pick up. Have a great day!