How to configure HomeKit light with colour?

done. Pull request is here

re-sync should not destroy any configuration and automation in home app as long as the accessories ID (aid) remain the same

Thanks for the quick solution! Not sure I understand the release cycle of bindings, will the change be released with OH 3.3.0? I’m on 3.2.0 at the moment. Would also like to get your other change (group support). Many thanks!

the process is like this

  • my changes needs to be approved
  • once approved they will be part of the next SNAPSHOT build (every night)
  • they will be part of next milestone build (once a month) 3.3.0M6
  • and part of the next release 3.3. i cannot tell you when it will be released.

regarding the group, to put right expectations, currently only mixed groups are supported, i.e. different accessory types in one group, e.g. light and fan.
i will try to implement same type groups, e.g. multiple lights, in the next weeks and before OH3.3

Any possibility to get a snapshot version to run with OH 3.2.0? Can’t wait for testing it :slight_smile:

this would actually great if you could test the snapshot
you can upgrade to snapshot via karaf console with this command (277 has to be replace with your homekit binding id)

update 277 https://openhab.jfrog.io/artifactory/libs-pullrequest-local/org/openhab/addons/bundles/org.openhab.io.homekit/3.3.0-SNAPSHOT/org.openhab.io.homekit-3.3.0-SNAPSHOT.jar

it looks like this

Hi @yfre,

Thanks! With the new version looks like the channels are mapped correctly however I cannot change colour. In log I see the error:

2022-06-02 21:17:50.221 [WARN ] [rver.impl.http.impl.AccessoryHandler] - Exception caught in web handler
java.lang.NoSuchMethodError: 'void org.openhab.core.library.types.DecimalType.<init>(java.lang.Number)'
	at org.openhab.io.homekit.internal.accessories.HomekitCharacteristicFactory.lambda$19(HomekitCharacteristicFactory.java:555) ~[?:?]
	at io.github.hapjava.characteristics.impl.base.FloatCharacteristic.setValue(FloatCharacteristic.java:133) ~[?:?]
	at io.github.hapjava.characteristics.impl.base.FloatCharacteristic.setValue(FloatCharacteristic.java:20) ~[?:?]
	at io.github.hapjava.characteristics.impl.base.BaseCharacteristic.setValue(BaseCharacteristic.java:126) ~[?:?]
	at io.github.hapjava.server.impl.json.CharacteristicsController.put(CharacteristicsController.java:83) ~[?:?]
	at io.github.hapjava.server.impl.connections.HttpSession.handleAuthenticatedRequest(HttpSession.java:79) ~[?:?]
	at io.github.hapjava.server.impl.connections.ConnectionImpl.doHandleRequest(ConnectionImpl.java:55) ~[?:?]
	at io.github.hapjava.server.impl.connections.ConnectionImpl.handleRequest(ConnectionImpl.java:49) ~[?:?]
	at io.github.hapjava.server.impl.http.impl.AccessoryHandler.channelRead0(AccessoryHandler.java:52) ~[?:?]
	at io.github.hapjava.server.impl.http.impl.AccessoryHandler.channelRead0(AccessoryHandler.java:17) ~[?:?]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[bundleFile:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [bundleFile:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:61) [bundleFile:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:370) [bundleFile:4.1.68.Final]
	at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:66) [bundleFile:4.1.68.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986) [bundleFile:4.1.68.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [bundleFile:4.1.68.Final]
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [bundleFile:4.1.68.Final]
	at java.lang.Thread.run(Thread.java:829) [?:?]

Edit: too quick to conclude - also experience when channel switches iPhone doesn’t re-sync once. So I’m not sure if the problem is completely solved, but this could also be related to color change problem.

hm. the exception does not make much sense for me.
it happens indeed in HUE method but i have not change anything there since a longer time and it complains that something does not exist which is actually there.
if not done yet, please restart and try again.
maybe rename the openHAB item and add new one, just to make sure it not due some old caching things or so.

@somy i could reproduce the exception on my side. the snapshot version of binding is not working with oh3.2 correctly. it expects version 3.3 snapshot of openhab as well
with openHAB3.3 snapshot i dont get this exception and HUE looks correct (but it was also working before on my machine)

so, if you like please tests with openHAB3.3. snapshot (can be downloaded from the homepage) or wait for official oh3.3 release

Hi @yfre : thanks a lot for looking into it!
I think best for me to downgrade for now will test again when OH3.3 released. How can I safely downgrade homekit binding without losing any existing configuration/items?

it should be “ok” to remove binding via main UI and add it again.
it should not remove any configuration
to be on the save side i would maybe copy the file called “homekit.json” - it has the pairing information, i.e. device connected to openHAB
in my setup i have this file in
/var/lib/openhab/jsondb/homekit.json

Thank you! Now I’m very much looking forward to OH v3.3 :slight_smile:

Hi @yfre :

Sorry but I need to bother you again on a related HomeKit issue - I’m afraid this time is no less tricky :joy:
One issue with the Xiaomi binding is that Brightness channel is not mapped correctly, so I have to use Color to control Hue/Saturation, and a separate Dimmer item for brightness. Today I tried something else and I managed to re-configure the gateway light by using another binding (Miio). With Miio binding the color channel works better and as expected - i.e. brightness can actually control the brightness while hue/saturation also work fine. I than configure HomeKit for the color item as follows:

Color Mi_hub_color “Mi Hub Light” (gXiaomiGateway) {channel=“miio:generic:031D14D8:rgb”, homekit=“Lighting,Lighting.Hue,Lighting.Saturation,Lighting.Brightness”}

Ok, here comes the problem. Even though I can control the light perfectly fine in OpenHab web interface, I can’t seem to change brightness from HomeKit. I cannot turn ON/OFF the light, and when the light is ON I cannot adjust brightness at all. Whenever I change brightness I can see in OH UI that the brightness slide is changes correctly, however no change to the hardware, and after a few seconds it reverts to old value. I’m able to change Hue/Saturation without problem though.

Initially I thought it was because it sends both brightness and On command, so I added:
[dimmerMode=“filterOn”], and I can see in the log that it only send brightness command to the Color item. However it doesn’t solve the issue.

For some reason when brightness is updated from HomeKit it doesn’t trigger OH to actually send the command to the device. Is it some configuration I missed somewhere?

Many thanks in advance!

to confirm my understanding

  • you can change brightness via openhab UI and change it on device
  • if you change brightness via homekit you do see changes in openhab UI but it has no impact on device

can you check the openhab event log ? (in my case it is in /var/log/openhab/events.log) sometimes openHAB “predicts” the value wrongly - you would see it in events log

Hi @yfre : yeah I also checked the event log, nothing suspicious.
When I turn on the device, you can see it sent 0,0,100 and the state also changed to 0,0,100, but after 3 seconds it flipped back to 0,0,0:

2022-06-07 21:46:07.642 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 0,0,0 to 348,5,38
2022-06-07 21:46:37.731 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 348,5,38 to 0,0,0
2022-06-08 21:29:58.618 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_color' received command ON
2022-06-08 21:29:58.624 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_color' received command 100
2022-06-08 21:29:58.625 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_color' predicted to become ON
2022-06-08 21:29:58.632 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_color' predicted to become 100
2022-06-08 21:29:58.633 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 0,0,0 to 0,0,100
2022-06-08 21:30:01.694 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 0,0,100 to 0,0,0

If I just change brightness (when the light is on), it sent ON and new brightness, the state first changed and then flipped back to old values (device is not affected at all):

2022-06-08 21:37:09.311 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_color' received command ON
2022-06-08 21:37:09.313 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_color' received command 92
2022-06-08 21:37:09.314 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_color' predicted to become ON
2022-06-08 21:37:09.315 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_color' predicted to become 92
2022-06-08 21:37:09.318 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 260,72,58 to 260,72,100
2022-06-08 21:37:09.319 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 260,72,100 to 260,72,92
2022-06-08 21:37:12.419 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 260,72,92 to 260,72,58

Below is when I change color, which works:

2022-06-08 21:35:54.065 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_color' received command 260.0,72,58
2022-06-08 21:35:54.066 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_color' predicted to become 260.0,72,58
2022-06-08 21:35:54.067 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 0,100,58 to 260.0,72,58

Also tried dimmerMode=“filterON”, below is when I turn the light:

2022-06-08 21:38:58.636 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_color' received command 100
2022-06-08 21:38:58.637 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_color' predicted to become 100
2022-06-08 21:38:58.638 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 0,0,0 to 0,0,100
2022-06-08 21:39:01.723 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 0,0,100 to 0,0,0

When I change from 100% brightness to 45% in HomeKit:

2022-06-08 21:41:21.437 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_color' received command 55
2022-06-08 21:41:21.444 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_color' predicted to become 55
2022-06-08 21:41:21.449 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 0,0,100 to 0,0,55
2022-06-08 21:41:21.662 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_color' received command 45
2022-06-08 21:41:21.666 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_color' predicted to become 45
2022-06-08 21:41:21.673 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 0,0,55 to 0,0,45
2022-06-08 21:41:24.547 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 0,0,45 to 0,0,100

Now if I change directly via OH GUI:

2022-06-08 21:42:11.526 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_color' received command 0,0,99
2022-06-08 21:42:11.527 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_color' predicted to become 0,0,99
2022-06-08 21:42:11.528 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 0,0,100 to 0,0,99
2022-06-08 21:42:11.726 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_color' received command 0,0,54
2022-06-08 21:42:11.731 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_color' predicted to become 0,0,54
2022-06-08 21:42:11.732 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_color' changed from 0,0,99 to 0,0,54

Edit: I can think of one thing that could be the cause. When I adjust brightness in OH GUI, it looks like it always send 3 values: Item ‘Mi_hub_color’ received command 0,0,54
When I change brightness from HomeKit, it only sends one value: Item ‘Mi_hub_color’ received command 45
Maybe the device doesn’t cache hue and saturation and always require all three values when brightness changes?

Hi @yfre : just want to report back that I did some more experiment with autoupdate in item configuration and it doesn’t solve the problem, so somehow there is a difference between the way how HomeKit binding and Web UI send command to the miio binding. Based on the event log I suspect jus send dimmer (brightness) command to color is not good enough for Xiaomi devices. I observed the following from HomeKit (which makes me think that the device need both dimmer and color to change):

  1. I change brightness for example from 0% to 50%, nothing happens to the light, in Web UI I can see brightness is changed to 50%
  2. Before the state flip back to 0% I send a color command from HomeKit
  3. This time it works the device changes color and brightness (50%)

Please let me know anything else I should test, I’m running out of ideas…

i was also thinking about “autoupdate” as the last idea. but you have tested it.
let me make a fix so that homekit always send 3 values if the item type is color

@somy thank you for the good investigation. it makes indeed to send always 3 values and not just brightness.

fix is submitted

the OH3.3 release is expected end of the month, so, soon you can test these fixes

HI @yfre : thanks a lot and hope it will be approved and released with OH 3.3.
Good that you agree that UI and HomeKit binding should behave consistently.

Hi @yfre : I just came back from vacation and would very much like to try the new 3.3.0 version. However I encountered some problem which I created another post:

Looks like something to do with the upgrade, and I have very little knowledge in this area, so I’d like to ask if you have any suggestion? Many thanks in advance!

Hi @yfre

Sorry to spam you but I have done some more tests with OH 3.3.0, and it does work better so really appreciate your effort. Now I can turn on the light, adjust color and brightness with no problem. The only issue is I cannot turn off the light, however I can adjust brightness to 0 which then turns off the light. Events logs below:
Turn on the light (work great):

2022-07-12 12:11:56.787 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_light' predicted to become ON
2022-07-12 12:11:56.789 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_light' predicted to become 0,0,100
2022-07-12 12:11:56.792 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_light' changed from 0,0,0 to 0,0,100

Adjust brightness (works great):

2022-07-12 12:12:11.683 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_light' received command ON
2022-07-12 12:12:11.685 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_light' received command 0,0,47
2022-07-12 12:12:11.694 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_light' predicted to become ON
2022-07-12 12:12:11.696 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_light' predicted to become 0,0,47
2022-07-12 12:12:11.699 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_light' changed from 0,0,100 to 0,0,47
2022-07-12 12:12:11.833 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_light' received command ON
2022-07-12 12:12:11.834 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_light' received command 0,0,46
2022-07-12 12:12:11.835 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_light' predicted to become ON
2022-07-12 12:12:11.836 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_light' predicted to become 0,0,46
2022-07-12 12:12:11.837 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_light' changed from 0,0,47 to 0,0,100
2022-07-12 12:12:11.837 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_light' changed from 0,0,100 to 0,0,46

Turn off (doesn’t work):

2022-07-12 12:12:28.207 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_light' received command OFF
2022-07-12 12:12:28.207 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_light' predicted to become OFF
2022-07-12 12:12:28.210 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_light' changed from 0,0,46 to 0,0,0
2022-07-12 12:12:31.273 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_light' changed from 0,0,0 to 0,0,46

Adjust brightness to 0 (strangely it works):

2022-07-12 12:13:02.041 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_light' received command OFF
2022-07-12 12:13:02.044 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_light' predicted to become OFF
2022-07-12 12:13:02.047 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Mi_hub_light' received command 0,0,0
2022-07-12 12:13:02.050 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Mi_hub_light' changed from 0,0,46 to 0,0,0
2022-07-12 12:13:02.052 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Mi_hub_light' predicted to become 0,0,0

So basically looks like the light need an explicit command (0, 0, 0) to be sent when it’s turned off.

Edit: as a workaround I have added the following rule and it seems to work (for now). Will report if more issues:

rule "Turn off Mi Hub light"
when
  Item Mi_hub_light received command OFF 
then 
  var HSBType next = new HSBType(new DecimalType(0),new PercentType(0),new PercentType(0))
  Mi_hub_light.sendCommand(next)
end```
1 Like