Xiaomi Gateway v2 - -can't controll light, vulume, color etc. in OH4

I have two Openhab systems ver. 2. and ver. 4 working paralelly. The problem is I can’t controll light, sound volume, color in Xiaomi Gateway using Xiaomi Mi Smart Home Binding in OH4, but it can be done in OH2.
For example I can turn on Gateway Light in OH2 (in OH4 it is shown as ON). I can’t turn it off in OH4, I can’ t turn it on OH4. The only way to to controll is possible in OH2.
Other Zigbee Xiaomi sensors (added via Xiaomi Home app) work properly, I can see their states.
Every Thing conected by binding (e.g. Xiaomi Mi Smart Home Bridge and Xiaomi Mi Smart Home Gateway) is online All channels are in Items
Any ideas? Is a bug in the binding?
When I try to swith on or off the light in Gateway,log give an error:

2024-03-06 21:58:19.598 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method ‘ThingHandler.handleCommand()’ on ‘org.openhab.binding.mihome.internal.handler.XiaomiActorGatewayHandler@778b433f’: Cannot invoke “Object.toString()” because “o” is null
java.lang.NullPointerException: Cannot invoke “Object.toString()” because “o” is null
at org.openhab.binding.mihome.internal.handler.XiaomiBridgeHandler.toJsonValue(XiaomiBridgeHandler.java:368) ~[?:?]
at org.openhab.binding.mihome.internal.handler.XiaomiBridgeHandler.sendCommandToBridge(XiaomiBridgeHandler.java:297) ~[?:?]
at org.openhab.binding.mihome.internal.handler.XiaomiBridgeHandler.sendCommandToBridge(XiaomiBridgeHandler.java:279) ~[?:?]
at org.openhab.binding.mihome.internal.handler.XiaomiBridgeHandler.writeToBridge(XiaomiBridgeHandler.java:316) ~[?:?]
at org.openhab.binding.mihome.internal.handler.XiaomiActorGatewayHandler.writeBridgeLightColor(XiaomiActorGatewayHandler.java:168) ~[?:?]
at org.openhab.binding.mihome.internal.handler.XiaomiActorGatewayHandler.writeBridgeLightColor(XiaomiActorGatewayHandler.java:164) ~[?:?]
at org.openhab.binding.mihome.internal.handler.XiaomiActorGatewayHandler.execute(XiaomiActorGatewayHandler.java:76) ~[?:?]
at org.openhab.binding.mihome.internal.handler.XiaomiDeviceBaseHandler.handleCommand(XiaomiDeviceBaseHandler.java:138) ~[?:?]
at jdk.internal.reflect.GeneratedMethodAccessor231.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:147) [bundleFile:?]
at org.openhab.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [bundleFile:?]
at jdk.proxy5348.$Proxy5475.handleCommand(Unknown Source) [?:?]
at org.openhab.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:95) [bundleFile:?]
at org.openhab.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:49) [bundleFile:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:147) [bundleFile:?]
at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
at java.lang.Thread.run(Thread.java:840) [?:?]

No: I have the Gateway light working with openHAB 4.1.1 and before with openHAB 2.x and 3.x and never had to change the configuration.

Maybe that is the problem? Switch off openHAB 2.x and try again.
Also make sure you have cleaned cache and tmp folders in openHAB 4 and restart at least twice.

Nothing helped. My Openhab is also 4.1.1.
Still I have an error: [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method ‘ThingHandler.handleCommand()’ on ‘org.openhab.binding.mihome.internal.handler.XiaomiActorGatewayHandler@268aeef3’: Cannot invoke “Object.toString()” because “o” is null
java.lang.NullPointerException: Cannot invoke “Object.toString()” because “o” is null

I have 3 Gateways now for tests working paralelly and none of them don’t work.
OH2 is closed. Temps and cache folders are cleaned.OH4 restarted twice.

I wonder what does it mean: Cannot invoke “Object.toString()” because “o” is null.
What “o”?

I am not sure but it looks like there is a problem with the Thing configuration: make sure you have the correct Developer Key for the bridge Thing and the correct Device ID for the Gateway Thing.

For comparison, here are my working Things:

Bridge:

UID: mihome:bridge:12ab345c6d78
label: "Xiaomi Mi Gateway V2 Bridge "
thingTypeUID: mihome:bridge
configuration:
  ipAddress: 192.168.2.22
  serialNumber: 12ab345c6d78
  port: 9898
  key: abc1d2ef34g5hij6

Gateway:

UID: mihome:gateway:12ab345c6d78:12ab345c6d78
label: Xiaomi Mi Smart Home Gateway
thingTypeUID: mihome:gateway
configuration:
  itemId: 12ab345c6d78
bridgeUID: mihome:bridge:12ab345c6d78
channels:
  - id: brightness
    channelTypeUID: mihome:brightness
    label: Brightness
    description: The brightness channel allows to control the brightness of a light.
      It is also possible to switch the light on and off.
    configuration: {}
  - id: illumination
    channelTypeUID: mihome:illumination
    label: Illumination
    description: This channel shows the brightness of the environment of the device.
    configuration: {}
  - id: color
    channelTypeUID: mihome:color
    label: Color
    description: Control the color of light.
    configuration: {}
  - id: colorTemperature
    channelTypeUID: mihome:colorTemperature
    label: Color Temperature
    description: Allows to control the color temperature of light.
    configuration: {}
  - id: enableSound
    channelTypeUID: mihome:enableSound
    label: Switch to Turn Sound Off When Playing
    description: null
    configuration: {}
  - id: sound
    channelTypeUID: mihome:sound
    label: Sound Selector
    description: null
    configuration: {}
  - id: volume
    channelTypeUID: mihome:volume
    label: Sound Volume
    description: This channel controls the volume of the gateway for playing sounds
    configuration: {}

Thanks for your reply.
I don’t think that the problem is in uncorrect Developer Key for the bridge Thing and the uncorrect Device ID for the Gateway Thing. As I wrote before when I turn on the Gateway light in OH2, I can see it in OH4, but can’t contoll it.
The Bridge and Gateway is online - so all settings are correct.
Maybe current version of Xiaomi Bindigg has an error.
My version of Xiaomi Mi Smart Home Binding is 4.4.1.
What’s yours?

Ruben_Perez in topic " Binding Xiaomi Mi home getway" wrote “BUT, I can actually read sensors connected to Xiaomi Gateway, but I can’t actuate to the Gateway, if I try to switch on the light for example, nothing happens… I don’t know why… More investigation time needed!” and I ask him about it. We will see

I am pretty sure the binding works fine as I can control the gateway on all available channels.

4.1.1, this is the latest stable binding version.

It looks, you were right. I noticed that Bridge ii online, no matter what Developer key is written.
Here is the post from the log:
2024-03-08 20:56:07.685 [WARN ] [internal.handler.XiaomiBridgeHandler] - No token received from the gateway yet. Unable to encrypt the access key.

Finally I used Developer key, which was used in Xiaomi binding in OH2 (although Developer key retrieved from Xiaomi app is different - here I use the password for LAN comunication protocol, also can be retieved from Xiaomi app - old version), but the most important thing was that there wasn’t a serial number in Xaomi Bridge settings. It didn’t say it is required, but when I set it (the same as a Gateway MiHome Device ID - it started to work.
So thanks for yuor advices

1 Like

As I say to @sp4mpa ; i have actually working, and can actuate over Gateway, change light color, etc… without problem on OH 4.1.1.
The curiosity is that if I go to Bindings on OH UI, it says that I don’t have any Xiaomi binding currently installed (but I was sure that it was, and updated from old OH versions). Very strange.

Ruben