Mi(Xiaomi) Smart home bindings?

I agree, it’s completely different than interacting with the gateway by documented API and I can reuse only some helper methods manipulating with strings and arrays. But binding using Miio protocol is the real MiHome binding (it can communicate with the gateway as well|). We can develope it separately as xiaomimiio or miio binding and make the vacuum binding more general with discovery of any miio device.

hey guys,
great to hear your plans!
I agree that marcels implementation is the way to gain general access to the protocol.
It has already the basic implementation for it.
The MiHome binding as it exists is to specialized for that. But on the other hand it went through several refactorings and improvements - making it easy to integrate new ZigBee devices controlled by the gateway and stable enough, so that basically only the discovery and message handling have to be touched in order to gain the neccessary next abstraction level. As long as the bridge thing in the MiHome binding receives the same formatted messages, it will work on with grace.
While Xiaomi is actively releasing new devices in that sub-ecosystem I would say this is the base to take for communicating with the gateway - not to forget @Ondrej_Pecta and his OH1.x binding, he is the real pioneer here :wink:

My best suggestion is to take the MiHome binding as it already exists in the official repo and build a new base for it.
So make a root binding for all miio devices, with a good support for the ZigBee sub-tree and the wifi sub-tree. If this root is stable and extensible enough it will be an ease to support whatever they bring tomorrow, developer mode or not. As long as they keep the encryption :no_mouth:
I really wouldn’t like to see different MiHome, Yeelight, Vacuum, etc. bindings.

As an alternative we can keep things seperate, see the general miio codebase rise and merge then. But definitely there should be only one to rule them all :smile: - thinking of the yeelight binding zombie eating brains in the PR list…

cheers!

2 Likes

thank you Brian, I´m afraid I dont know how to program by myself, do you some some guidance on where I could look at to learn ?

You can start here with some examples:

http://docs.openhab.org/tutorials/beginner/rules.html

Good luck :slight_smile:

For expermenting I added a thingtype to the vacuum binding that allows you to send commands to miio devices.
I also found out how to identify which miio device it is.
If someone I’d willing to give it a try e.g with a humidifier, fan or something I am curious for the outcome. (To try it, install the Xiaomi vacuum binding from the marketplace, add manually a miio thing)

1 Like

192.168.1.164 - This is my Mi Air Purifier 2, this binding is found it, and it is found my 3 yeelight bulbs , and the gateway too.

2017-07-28 12:43:18.626 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Vacuum time stamp: 1970-01-02T19:15:45, OH time 2017-07-28T12:43:18.626, delta 47
2017-07-28 12:43:18.627 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Discovered Xiaomi Robot Vacuum 02E00AFF at 192.168.1.121
2017-07-28 12:43:18.629 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Discovered token for device 02E00AFF: 00000000000000000000000000000000 ('')
2017-07-28 12:43:18.634 [DEBUG] [g.discovery.internal.PersistentInbox] - Updated discovery result for 'xiaomivacuum:vacuum:02E00AFF'.
2017-07-28 12:43:18.636 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Vacuum time stamp: 1970-01-06T14:29:37, OH time 2017-07-28T12:43:18.636, delta 47
2017-07-28 12:43:18.637 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Discovered Xiaomi Robot Vacuum 00D04B95 at 192.168.1.75
2017-07-28 12:43:18.638 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Discovered token for device 00D04B95: 00000000000000000000000000000000 ('')
2017-07-28 12:43:18.648 [DEBUG] [g.discovery.internal.PersistentInbox] - Updated discovery result for 'xiaomivacuum:vacuum:00D04B95'.
2017-07-28 12:43:18.650 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Vacuum time stamp: 1970-01-06T10:53:13, OH time 2017-07-28T12:43:18.650, delta 47
2017-07-28 12:43:18.652 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Discovered Xiaomi Robot Vacuum 02AA0975 at 192.168.1.250
2017-07-28 12:43:18.653 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Discovered token for device 02AA0975: 00000000000000000000000000000000 ('')
2017-07-28 12:43:18.663 [DEBUG] [g.discovery.internal.PersistentInbox] - Updated discovery result for 'xiaomivacuum:vacuum:02AA0975'.
2017-07-28 12:43:18.665 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Vacuum time stamp: 1970-01-01T10:59:27, OH time 2017-07-28T12:43:18.665, delta 47
2017-07-28 12:43:18.667 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Discovered Xiaomi Robot Vacuum 00D05E12 at 192.168.1.47
2017-07-28 12:43:18.668 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Discovered token for device 00D05E12: 00000000000000000000000000000000 ('')
2017-07-28 12:43:18.678 [DEBUG] [g.discovery.internal.PersistentInbox] - Updated discovery result for 'xiaomivacuum:vacuum:00D05E12'.
2017-07-28 12:43:18.680 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Vacuum time stamp: 1970-03-13T21:00:37, OH time 2017-07-28T12:43:18.680, delta 47
2017-07-28 12:43:18.681 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Discovered Xiaomi Robot Vacuum 02D07548 at 192.168.1.164
2017-07-28 12:43:18.682 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Discovered token for device 02D07548: 82FA712A5701833C0E1CFC50D82E9BCC ('��q*W�<�P�.��')
2017-07-28 12:43:18.692 [DEBUG] [g.discovery.internal.PersistentInbox] - Updated discovery result for 'xiaomivacuum:vacuum:02D07548'.
2017-07-28 12:43:18.694 [DEBUG] [aomivacuum.discovery.VacuumDiscovery] - Xiaomi Robot Vacuum discovery done
2017-07-28 12:43:18.695 [DEBUG] [est.core.discovery.DiscoveryResource] - Scan for binding 'xiaomivacuum' successfully finished.

I added manual Mi Air Purifier 2 as Xiaomi MiIO device

2017-07-28 12:50:33.401 [DEBUG] [aomivacuum.handler.XiaomiMiioHandler] - Update connection 'xiaomivacuum:unknown:02D07548'
2017-07-28 12:50:33.402 [DEBUG] [.smarthome.config.core.Configuration] - Setting value (String) 192.168.1.164 to field 'host' in configuration class org.openhab.binding.xiaomivacuum.XiaomiVacuumBindingConfiguration
2017-07-28 12:50:33.403 [DEBUG] [.smarthome.config.core.Configuration] - Setting value (String) 82FA712A5701833C0E1CFC50D82E9BCC to field 'token' in configuration class org.openhab.binding.xiaomivacuum.XiaomiVacuumBindingConfiguration
2017-07-28 12:50:33.404 [DEBUG] [.smarthome.config.core.Configuration] - Setting value (String) 02D07548 to field 'deviceId' in configuration class org.openhab.binding.xiaomivacuum.XiaomiVacuumBindingConfiguration
2017-07-28 12:50:33.404 [DEBUG] [.smarthome.config.core.Configuration] - Setting value (int) 30 to field 'refreshInterval' in configuration class org.openhab.binding.xiaomivacuum.XiaomiVacuumBindingConfiguration
2017-07-28 12:50:33.405 [DEBUG] [aomivacuum.handler.XiaomiMiioHandler] - Using vacuum device ID 02D07548
2017-07-28 12:50:33.438 [DEBUG] [omivacuum.internal.RoboCommunication] - Send command: {'method': 'miIO.info', 'id': 14} -> 192.168.1.164 (Device: 02D07548 token: 82FA712A5701833C0E1CFC50D82E9BCC)

2017-07-28 12:50:43.452 [DEBUG] [omivacuum.internal.RoboCommunication] - Communication error for vacuum at 192.168.1.164: Receive timed out
2017-07-28 12:50:43.453 [DEBUG] [omivacuum.internal.RoboCommunication] - len 0
2017-07-28 12:50:43.455 [DEBUG] [omivacuum.internal.RoboCommunication] - No response from vacuum for command {'method': 'miIO.info', 'id': 14}.
Message:
Header  : 21 31 00 50 00 00 00 00 02 D0 75 48 59 7B 16 F9
checksum: 6E 03 D4 F4 FC C3 B2 78 98 4B BD 61 E8 0D 8F C1
content : D7 0A 31 3C 99 87 E5 92 0E BE FB 00 2E D0 CD B4 21 3F 91 4C 4A 44 FF A7 07 6D CD 72 8A 11 AC 87 42 41 60 26 6E 51 35 4C C2 8B 0A 07 EE FF 3A FF
Header Details: Magic:21 31
Length:   80
Serial:   02 D0 75 48
TS:2017-07-28 12:50:33 CEST
2017-07-28 12:50:43.456 [DEBUG] [aomivacuum.handler.XiaomiMiioHandler] - Empty response received.

So it is good start :slight_smile:

Great! This is one of the key issues we need to solve since right now we know there’s a miio device but we cannot create thing until it is identified. Most of the devices do not expose their token and we must enter it somewhere manually…

Interesting indeed.

I see the 4 four devices respond differently wrt to the token than the vacuum. (with all 00’s )
I’ll make quick update that will avoid that it is considered a valid token.

I guess you did not enter tolkens for these items right? If you did, was the reply the same as quoted here (no rrsponse).

Yes, it will be a bit tricky, I think it can be done.
Will do bit of experimenting see if my idea for it works out

Only Mi Air Purifier 2 added as thing, filled the token, and device id, and the ip address. I did not add the other 4 where the token 000 mi item (3 yeelight bulb and a gateway)

Hi,
I’m trying to follow you guys guidelines for wifi smart socket but can’t get my hand on token.
How do you get it?

mmm, this looks like the token is no longer accepted,
Motly that means that it was able to send the message[quote=“Variamus, post:374, topic:4711”]
I’m trying to follow you guys guidelines for wifi smart socket but can’t get my hand on token.

How do you get it?
[/quote]

Assuming it is similar, you can read the tolken info in the first post

Thanks, I could find the token with your help.
No way to implement wifi socket yet as I understand your reply?
Also, I don’t have device id…

I’ve created rules for existing xiaomi gateway channels, but could not find information a command I should send to arm it’s embedded alarm

I can confirm that the Smoke Sensor does not work with 2.2.0 binding,

same here… smoke sensor doesnt work.
(oh 2.1 and binding 2.1)

what do would you like to do?
if you want to have an alarm go off when you have movement then take a look at the documentation, it has very good examples, see :

http://docs.openhab.org/addons/bindings/mihome/readme.html

I found this on the HASS forum:

Did anybody try this and made it work with openhab?
I like to use it as confimation for my away, home setting ect.
I’m going to try later this evening.

It’s worth to check official documentation sometimes :wink:

rule "Play quiet knock-knock ringtone with the Xiaomi Gateway"
when
    // Item ExampleSwitch changed to ON
then
    sendCommand(Gateway_SoundVolume, 2)
    sendCommand(Gateway_Sound, 11)
    Thread::sleep(2000) /* wait for 2 seconds */
    sendCommand(Gateway_Sound, 10000)
    sendCommand(Gateway_SoundVolume, 0)
end

Hello,
it will possible add local radio station (m3u8) or other file. To play with gateway ?

thanks