Mi(Xiaomi) Smart home bindings?

I don’t know if it is related directly, but I also had a case at the start of my project where openHab could see my smart plug, and see its status, but couldn’t control it.
If I remember correctly, it was a bug, that I fixed by manually adding an updated version of the Xiaomi binding. Can’t remember where I got it, I’m sure someone else here can assist. In the meantime I’ll see if I can find it.

I installed the latest binding available from paper UI on March 6, 2018, so I guess the bug is already gone when I install the binding, not sure about installing binding without paperUI, only tried to do that for not official binding, Broadlink binding.

I will ask a stupid question, just to make sure. You did remember to activate the developer mode on your Xiaomi app for the Gateways? Then copied the code to the bridge-gateway on PaperUI?
If I remember correctly, you can’t control the gateways if you don’t activate developer mode (among other things).

Yes, it is already activated, and I already able to turn it off and on, but only sometimes.

Did you notice, that you have two items for the same channel?
mihome_ctrl_neutral2_158d0001f4c141_ch1 is one item, Light_outdoor_8 is another.
They are both connected to the channel mihome:ctrl_neutral2:158d0001f4c141:ch1

Hello @dimalo, yes I noticed that I have two items. One from paperUI, and one from xiaomi.items for better management.
Can you please tell me what entries should I write to org.ops4j.pax.logging.cfg to get xiaomi binding logs?

I am a beginner here so probably asking a stupid question.

I got “Smart Home Gateway” (a round shaped thing with LEDs, speaker, and it provides zigbee gateway), however I cannot add it to OpenHAB as there is no way to specify the IP of the gateway. I was able to add “Smart Home Bridge” instead (typed in the IP and the key), got all my sensors.

However there is no “Smart Home Gateway” functionality on that bridge - no illumination, no speaker. If I add the gateway manually, it remains “offline” (understandable).

Is there any way to get illumination and speaker working from that Gateway device? Thanks

upd: although the gateway detects all the sensors, etc, most of them do not work - for example, “smart socket plug” does not respond to the “power” switch and all door/window sensors do not show battery level (but wireless switch does).

not sure you can enable debug logging there.
please dig a bit in the forum…
for example: https://community.openhab.org/t/logging-under-oh2-karaf

If you write you are able to write but only sometimes. perhaps the distance is too far, so that the connection is bad sometimes? or you have many devices? you can then just buy another gateway and distribute the devices on two gateways. the binding works great with multiple gateways…

hey @aik:
please make sure you have the latest firmware on the gateway via mihome app. Also make sure you have the gateway v3 - this one is reported to work the best.
the binding should give you the bridge and the gateway. OH internally, the bridge is for further devices connected to the gateway, the gateway thing itself is for controlling the gateway’s light and so on.

I understand if we can log from karaf, but somehow the combination of openhab:habopen when SSHing on port 8101 is rejected.
Also I do not know what is the bundle, is there any way to know what is the bundle of each addons?

hey @dimalo, it is v3 gateway, updated but the “smart home gateway” just does not take ip address in the config, only “smart home bridge” does but the bridge is way simpler that the gateway. Adding the gateway manually does not work - it remains offline.

My openhab2 is 2.2.0-1, does this have necessary xiaomi support?

upd: installed from testing - 2.3.0~20180310161859-1 - still no gateway support :-/

try openhab-cli console if you are on linux.

@aik
Then I’m guessing your network setup prevents the binding from being correctley configured. please check if you are able to receive multicast traffic.
for you it would also be interesting to enable enhanced logging for the binding trying to understand where the problem is.

@dimalo:
multicast is enabled everywhere I can see, the Mi gateway receives its IP over DHCP from the orangepi box which is running the opehnab2, the openhab2 server is in the same network as the xiaomi gateway.

I can enable logging but I wonder what I should be doing to get the setup working as expected so it would make sense to record the log to see what went wrong. Literally, I deleted all xiaomi devices, restarted the service, enable all DEBUG events, went to “inbox” and tried scanning Xiaomi binding - and it found nothing. The log is there: https://pastebin.com/YbshEnya
This does not give me a clue of what to expect really, what should have happened? Or I still have to add the bridge manually (as it is the only thing which takes an IP) and the gateway should pop up altogether with all the switches and sensors?

upd: in parallel I am also playing with domoticz, that thing does not autofind the gateway but I can add by IP+key (just like openhab does for “xiaomi bridge”) and then I can control all the sensors + sounds + lights, i.e. everything the gateway provides - these additional capabilities come as discovered switches. OpenHAB does something differently but what…

Try disabling firewall. Xiaomi MiHome Gateway not responding (Solved)

@kyomar tried that, no difference. Can you please give a hint how it is supposed to work?

Hi,

upon gearbest shopping i stumbled over the Xiaomi Thermostat Accuracy Temperature Humidity Monitor:

It seems to be basically the temperature sensor with a LCD display for displaying current temperature and humidity.

Does someone have some experience with it already? Is it supported by the binding?

Regards
Simon

You need this lamp as bluetooth gateway:

The mi home gateway is only zigbee, no bluetooth.

look here

Just follow the link I have provided, everything I know is explained there. Hint: first you have to completely turn off firewall, after the gateway has been detected you can setup the firewall as described.

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.