drndos / mikettle

Xiaomi Mi Kettle Bluetooth Library
MIT License
54 stars 23 forks source link

Domoticz integration #2

Open MynahPL opened 4 years ago

MynahPL commented 4 years ago

Awesome work! For my Xiaomi Mi Kettle from European distribution the ProductID is 275, it took me a while to figure this out - was failing while trying the 131 from aprosvetova's work. I run the demo.py, successfully paired and received response:

... Subscribing to data and receiving it once {'action': 'idle', 'mode': 'none', 'set temperature': 90, 'current temperature': 39, 'keep warm type': 'cool down', 'keep warm time': 0}

Are there any "next steps" after running the demo? I'd like to use this script to monitor the current temperature via Domoticz. Any clues how this can be achieved?

drndos commented 4 years ago

Hello, I published the module to pypi and added custom_component for HA. I don't plan on releasing domoticz component. Feel free to copy and modify my code, maybe take a look at https://github.com/drndos/mikettle-ha

Hypfer commented 4 years ago

I've also built a BLE to MQTT bride to use the Kettle and more ble things with Home Assistant. Autodiscovery works, but HA currently doesn't have a proper device class for it so it's just a sensor with attributes and mqtt services you can call to set stuff.

https://github.com/Hypfer/Cybele

https://github.com/Hypfer/Cybele/blob/master/docs/devices/MiSmartKettle.md

I'm currently evaluating measures to get it to work sorta-reliably since bluetooth adapters are a pain.

radokristof commented 4 years ago

@Hypfer can this bluetooth to mqtt bridge be used outside of HA? Also I can't seem to get this working. Do the Kettle needs to be paired to a device or in pairing mode? However I think this doesn't really matter in BLE right? The README says a Bluetooth dongle is needed. Can I use RPi integrated Bluetooth (on RPi4 it has Bluetooth 5 with LE)?

Hypfer commented 4 years ago

It's MQTT so you can use it whereever you like. Topics + Payloads are documented here: https://github.com/Hypfer/Cybele/blob/master/docs/devices/MiSmartKettle.md#mqtt

The kettle can't be paired. There are BLE-devices which can, but Viomi opted for their own proprietary handshake foo here.

The readme recommends a usb bluetooth adapter. You can use the RPi integrated bluetooth but it will fail eventually which then forces you to reboot since there is no other way to reset the HCI Adapter. Using USB HCI adapters is a hack to overcome this issue by (utilizing a uhubctl-compatible hub) giving us a way to forcefully reset the adapter without rebooting the whole host. Thats what's mentioned here: https://github.com/Hypfer/Cybele/blob/master/docs/index.md#hardware-recommendations

RPi 4 uses the same bluetooth chip as RPi 3. They just patched the version string to Bluetooth 5 for some reason. Recommended talk: https://media.ccc.de/v/2019-185-playing-with-bluetooth

As for connectivity issues I recommend moving the kettle closer, checking that the correct productId is used and also if you can see it advertising at all. Note that only one device can connect to it at a time. It will stop advertising itself while connected.

radokristof commented 4 years ago

Thanks! My problem might be that I just tried it with the RPi integrated BLE. I will buy an adapter and see with that. Does it matter what adapter is used? I found some inexpensive ones online which uses a Broadcom chip (only BLE 4.0). Thanks for the docs, I haven't found your project, this will suit my exceptations fully if I can get it working. Just a few questions I don't understand:

Hypfer commented 4 years ago

I have no idea. Some adapters seem to work okay-ish, others fail completely.

The kettle doesn't have a battery or any other energy source. Therefore it is only connectable while on its base. I don't understand the second question :(