Mi(Xiaomi) Smart home bindings?

Hello! I have a problem with connection xiaomi to openhab.
I add gateway and set the key, than I see all sub-items. I see them online and can see information from gateway light sensor, but if I try to send command I got the error
Did anybody face this problem?

21:57:05.152 [ERROR] [rnal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.mihome.handler.XiaomiAqaraActorSwitch2Handler@6a0d5e6a': null
java.lang.NullPointerException: null
        at org.openhab.binding.mihome.internal.EncryptionHelper.encrypt(EncryptionHelper.java:69) [202:org.openhab.binding.mihome:2.2.0]
        at org.openhab.binding.mihome.internal.EncryptionHelper.encrypt(EncryptionHelper.java:42) [202:org.openhab.binding.mihome:2.2.0]
        at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.getEncryptedKey(XiaomiBridgeHandler.java:291) [202:org.openhab.binding.mihome:2.2.0]
        at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.createDataJsonString(XiaomiBridgeHandler.java:277) [202:org.openhab.binding.mihome:2.2.0]
        at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.writeToDevice(XiaomiBridgeHandler.java:268) [202:org.openhab.binding.mihome:2.2.0]
        at org.openhab.binding.mihome.handler.XiaomiAqaraActorSwitch2Handler.execute(XiaomiAqaraActorSwitch2Handler.java:48) [202:org.openhab.binding.mihome:2.2.0]
        at org.openhab.binding.mihome.handler.XiaomiDeviceBaseHandler.handleCommand(XiaomiDeviceBaseHandler.java:104) [202:org.openhab.binding.mihome:2.2.0]
        at sun.reflect.GeneratedMethodAccessor29.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
        at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [109:org.eclipse.smarthome.core:0.10.0.b1]
        at org.eclipse.smarthome.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [109:org.eclipse.smarthome.core:0.10.0.b1]
        at com.sun.proxy.$Proxy138.handleCommand(Unknown Source) [202:org.openhab.binding.mihome:2.2.0]
        at org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:72) [116:org.eclipse.smarthome.core.thing:0.10.0.b1]
        at org.eclipse.smarthome.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:49) [116:org.eclipse.smarthome.core.thing:0.10.0.b1]
        at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
        at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [109:org.eclipse.smarthome.core:0.10.0.b1]
        at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [109:org.eclipse.smarthome.core:0.10.0.b1]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:?]
        at java.lang.Thread.run(Thread.java:745) [?:?]

Can you post your things, items & rules?

I configured it with Paper UI. How can I export it?

I found this
userdata\jsondb
org.eclipse.smarthome.core.items.Item.json

{
  "XiaomiMiSmartHomeGateway_Color": {
    "class": "org.eclipse.smarthome.core.items.ManagedItemProvider$PersistedItem",
    "value": {
      "groupNames": [],
      "itemType": "Color",
      "tags": [],
      "label": "Color",
      "category": "ColorLight"
    }
  },
  "XiaomiAqaraWallSwitch2Button_Button1s": {
    "class": "org.eclipse.smarthome.core.items.ManagedItemProvider$PersistedItem",
    "value": {
      "groupNames": [],
      "itemType": "Switch",
      "tags": [],
      "label": "Button 1s"
    }
  },
  "XiaomiMiSmartHomeGateway_Illumination": {
    "class": "org.eclipse.smarthome.core.items.ManagedItemProvider$PersistedItem",
    "value": {
      "groupNames": [],
      "itemType": "Number",
      "tags": [],
      "label": "Illumination"
    }
  },
  "XiaomiAqaraWallSwitch2Button_Button1": {
    "class": "org.eclipse.smarthome.core.items.ManagedItemProvider$PersistedItem",
    "value": {
      "groupNames": [],
      "itemType": "Switch",
      "tags": [],
      "label": "Button 1"
    }
  },
  "XiaomiMiSmartHomeGateway_Brightness": {
    "class": "org.eclipse.smarthome.core.items.ManagedItemProvider$PersistedItem",
    "value": {
      "groupNames": [],
      "itemType": "Dimmer",
      "tags": [],
      "label": "Brightness",
      "category": "DimmableLight"
    }
  }
}

org.eclipse.smarthome.core.thing.Thing.json

{
  "mihome:ctrl_neutral2:158d00016d934d": {
    "class": "org.eclipse.smarthome.core.thing.internal.ThingImpl",
    "value": {
      "label": "Xiaomi Aqara Wall Switch 2 Button",
      "bridgeUID": {
        "segments": [
          "mihome",
          "bridge",
          "34ce0088dc70"
        ]
      },
      "channels": [
        {
          "acceptedItemType": "Switch",
          "kind": "STATE",
          "uid": {
            "segments": [
              "mihome",
              "ctrl_neutral2",
              "158d00016d934d",
              "ch1"
            ]
          },
          "channelTypeUID": {
            "segments": [
              "mihome",
              "sw-btn"
            ]
          },
          "label": "Button 1",
          "description": "The first pushbutton on the switch.",
          "configuration": {
            "properties": {}
          },
          "properties": {},
          "defaultTags": []
        },
        {
          "acceptedItemType": "Switch",
          "kind": "STATE",
          "uid": {
            "segments": [
              "mihome",
              "ctrl_neutral2",
              "158d00016d934d",
              "ch2"
            ]
          },
          "channelTypeUID": {
            "segments": [
              "mihome",
              "sw-btn"
            ]
          },
          "label": "Button 2",
          "description": "The second pushbutton on the switch.",
          "configuration": {
            "properties": {}
          },
          "properties": {},
          "defaultTags": []
        }
      ],
      "configuration": {
        "properties": {
          "itemId": "158d00016d934d"
        }
      },
      "properties": {},
      "uid": {
        "segments": [
          "mihome",
          "ctrl_neutral2",
          "158d00016d934d"
        ]
      },
      "thingTypeUID": {
        "segments": [
          "mihome",
          "ctrl_neutral2"
        ]
      }
    }
  },
  "mihome:gateway:34ce0088dc70": {
    "class": "org.eclipse.smarthome.core.thing.internal.ThingImpl",
    "value": {
      "label": "Xiaomi Mi Smart Home Gateway",
      "bridgeUID": {
        "segments": [
          "mihome",
          "bridge",
          "34ce0088dc70"
        ]
      },
      "channels": [
        {
          "acceptedItemType": "Dimmer",
          "kind": "STATE",
          "uid": {
            "segments": [
              "mihome",
              "gateway",
              "34ce0088dc70",
              "brightness"
            ]
          },
          "channelTypeUID": {
            "segments": [
              "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": {
            "properties": {}
          },
          "properties": {},
          "defaultTags": [
            "Lighting"
          ]
        },
        {
          "acceptedItemType": "Number",
          "kind": "STATE",
          "uid": {
            "segments": [
              "mihome",
              "gateway",
              "34ce0088dc70",
              "illumination"
            ]
          },
          "channelTypeUID": {
            "segments": [
              "mihome",
              "illumination"
            ]
          },
          "label": "Illumination",
          "description": "This channel shows the brightness of the environment of the device.",
          "configuration": {
            "properties": {}
          },
          "properties": {},
          "defaultTags": []
        },
        {
          "acceptedItemType": "Color",
          "kind": "STATE",
          "uid": {
            "segments": [
              "mihome",
              "gateway",
              "34ce0088dc70",
              "color"
            ]
          },
          "channelTypeUID": {
            "segments": [
              "mihome",
              "color"
            ]
          },
          "label": "Color",
          "description": "Control the color of light.",
          "configuration": {
            "properties": {}
          },
          "properties": {},
          "defaultTags": [
            "Lighting"
          ]
        },
        {
          "acceptedItemType": "Dimmer",
          "kind": "STATE",
          "uid": {
            "segments": [
              "mihome",
              "gateway",
              "34ce0088dc70",
              "colorTemperature"
            ]
          },
          "channelTypeUID": {
            "segments": [
              "mihome",
              "colorTemperature"
            ]
          },
          "label": "Color Temperature",
          "description": "Allows to control the color temperature of light.",
          "configuration": {
            "properties": {}
          },
          "properties": {},
          "defaultTags": [
            "ColorTemperature"
          ]
        },
        {
          "acceptedItemType": "Switch",
          "kind": "STATE",
          "uid": {
            "segments": [
              "mihome",
              "gateway",
              "34ce0088dc70",
              "enableSound"
            ]
          },
          "channelTypeUID": {
            "segments": [
              "mihome",
              "enableSound"
            ]
          },
          "label": "Switch to turn sound off when playing",
          "configuration": {
            "properties": {}
          },
          "properties": {},
          "defaultTags": []
        },
        {
          "acceptedItemType": "Number",
          "kind": "STATE",
          "uid": {
            "segments": [
              "mihome",
              "gateway",
              "34ce0088dc70",
              "sound"
            ]
          },
          "channelTypeUID": {
            "segments": [
              "mihome",
              "sound"
            ]
          },
          "label": "Sound Selector",
          "configuration": {
            "properties": {}
          },
          "properties": {},
          "defaultTags": []
        },
        {
          "acceptedItemType": "Dimmer",
          "kind": "STATE",
          "uid": {
            "segments": [
              "mihome",
              "gateway",
              "34ce0088dc70",
              "volume"
            ]
          },
          "channelTypeUID": {
            "segments": [
              "mihome",
              "volume"
            ]
          },
          "label": "Sound Volume",
          "description": "This channel controls the volume of the gateway for playing sounds",
          "configuration": {
            "properties": {}
          },
          "properties": {},
          "defaultTags": []
        }
      ],
      "configuration": {
        "properties": {
          "itemId": "34ce0088dc70"
        }
      },
      "properties": {},
      "uid": {
        "segments": [
          "mihome",
          "gateway",
          "34ce0088dc70"
        ]
      },
      "thingTypeUID": {
        "segments": [
          "mihome",
          "gateway"
        ]
      }
    }
  },
  "mihome:bridge:34ce0088dc70": {
    "class": "org.eclipse.smarthome.core.thing.internal.BridgeImpl",
    "value": {
      "label": "Xiaomi Gateway",
      "channels": [],
      "configuration": {
        "properties": {
          "serialNumber": "34ce0088dc70",
          "port": 9898,
          "ipAddress": "192.168.1.165",
          "key": "3i42kimg50l4e5t1"
        }
      },
      "properties": {
        "vendor": "Xiaomi"
      },
      "uid": {
        "segments": [
          "mihome",
          "bridge",
          "34ce0088dc70"
        ]
      },
      "thingTypeUID": {
        "segments": [
          "mihome",
          "bridge"
        ]
      }
    }
  }
}

I debuged it a bit, and I found that error was caused by not existed gateway token. It’s null. As I see it should be recieved from heartbeat, but, as I heard, now gateway doesn’t send his token into heartbeat. Anybody know something about this problem?

firmware updated: 1.4.1_153.0143

@dimalo finalized the binding

Now this switch works for you?
I have such errors:

2018-03-18 09:03:10.017 [ERROR] [ndler.XiaomiAqaraActorSwitch1Handler] - Can't handle command ON on channel mihome:ctrl_ln1:id:ch1
2018-03-18 09:03:12.751 [ERROR] [ndler.XiaomiAqaraActorSwitch1Handler] - Can't handle command OFF on channel mihome:ctrl_ln1:id:ch1

If developer mode is activated using the Mi App, it should get its own token provided that the developer key was filled in for the Gateway. I haven’t needed to fill in the token manually for the Gateways before.

Is it possible to add the functionality that would allow the Xiaomi Gateway to be defined/used as system speaker in openhab2? From my understanding, currently the device is only able to play one of the 30 predefined sounds.

Someone else can maybe correct me, but I have yet to find a way to use it as a general speaker.
The best I could do was to add a custom sound to the Gateway, and play the sound when applicable via OH.

What the version of OH you use?
I downloaded 2.2 and it doesn’t work with mi home for me.
If I just download addon and try to send command to xiomi item - I get NPE because there is no gateway token in heartbeat anymore. But it still present into get_id_list_ack, but looks like the encryption alghoritm was changed too, because in this case I get invalid key message.
By the way, anybody know who’s author of mi home addon?

I’ve been using the newest version of OH without any trouble thus far.
Are you using “Xiaomi Mi Smart Home Binding” or “Xiaomi Mi IO Binding”?

I use
Xiaomi Mi Smart Home Binding

I have the same error:

2018-03-22 22:12:26.265 [WARN ] [me.handler.XiaomiActorGatewayHandler] - Can't handle command OFF on channel mihome:gateway:7811dcb38279:7811dcb38279:colorTemperature

Any solution?

I set the log level for org.openhab.binding.xiaomigateway to DEBUG and I don’t have anything logged.
EDIT: I wrote wrong instance. I changed to org.openhab.binding.mihome and it is logging.

I also have this log entry on events

17:45:00.126 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Light_outdoor_1' received command ON
17:45:00.137 [ERROR] [andler.XiaomiAqaraActorSwitch1Handler] - Can't handle command ON on channel mihome:ctrl_neutral1:158d0001f503dc:ch1
17:45:00.154 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Light_outdoor_3' received command ON

I checked on mihome app and everything runs normally, no devices is in offline status. But for the past week, it is not working again like my previous post here
I’m quite sure that wifi signal is not the problem, it is receiving from outdoor beamer TP-Link CPE210 and set signal for receiver <1km and only separated by 2 glass walls with about 15m distance.

Controlling via mihome app also does not update button status on openhab.

@kohlsalem, have you found an answer to your question? I’m thinking about buying that lamp, but not sure whether I will be able to integrate it with my Openhab.

no solution yet.
For me, some items works and some not.
For exapmple, temperature sensors work, battery level too.
But the led color of the gateway no.

@sunseaandpalms i did not find any solution yet. But the Lamp is a great piece of hardware even without connectivety…

The Philips Eyecare 2 now works with the MIIO addon.
https://openhab.jfrog.io/openhab/libs-pullrequest-local/org/openhab/binding/org.openhab.binding.miio/2.3.0-SNAPSHOT/

1 Like

Me too experiencing the issue with action handling. I’m on the latest snapshot

2018-03-25 19:50:07.616 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.mihome.handler.XiaomiActorPlugHandler@56b4aa61': null
java.lang.NullPointerException: null
	at org.openhab.binding.mihome.internal.EncryptionHelper.encrypt(EncryptionHelper.java:69) [207:org.openhab.binding.mihome:2.3.0.201803101457]
	at org.openhab.binding.mihome.internal.EncryptionHelper.encrypt(EncryptionHelper.java:42) [207:org.openhab.binding.mihome:2.3.0.201803101457]
	at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.getEncryptedKey(XiaomiBridgeHandler.java:290) [207:org.openhab.binding.mihome:2.3.0.201803101457]
	at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.createDataJsonString(XiaomiBridgeHandler.java:276) [207:org.openhab.binding.mihome:2.3.0.201803101457]
	at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.writeToDevice(XiaomiBridgeHandler.java:267) [207:org.openhab.binding.mihome:2.3.0.201803101457]
	at org.openhab.binding.mihome.handler.XiaomiActorPlugHandler.execute(XiaomiActorPlugHandler.java:47) [207:org.openhab.binding.mihome:2.3.0.201803101457]
	at org.openhab.binding.mihome.handler.XiaomiDeviceBaseHandler.handleCommand(XiaomiDeviceBaseHandler.java:104) [207:org.openhab.binding.mihome:2.3.0.201803101457]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [97:org.eclipse.smarthome.core:0.10.0.201803241900]
	at org.eclipse.smarthome.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [97:org.eclipse.smarthome.core:0.10.0.201803241900]
	at com.sun.proxy.$Proxy145.handleCommand(Unknown Source) [207:org.openhab.binding.mihome:2.3.0.201803101457]
	at org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:75) [104:org.eclipse.smarthome.core.thing:0.10.0.201803241900]
	at org.eclipse.smarthome.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:49) [104:org.eclipse.smarthome.core.thing:0.10.0.201803241900]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [97:org.eclipse.smarthome.core:0.10.0.201803241900]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [97:org.eclipse.smarthome.core:0.10.0.201803241900]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]

Yep this error is absolutely like mine. And It’s very strange that nobody else faced it. Maybe some special gateway or gateway firmware version?