Git Product home page Git Product logo

mikettle's Introduction

mikettle - Library for Xiaomi Mi Kettle with Bleutooth LE

This library properly authenticates with Xiaomi Mi Kettle and allows to read status and control the kettle via Bluetooth.

Based on https://github.com/ratcashdev/mitemp that is based on https://github.com/open-homeautomation/miflora .

This library uses authentication that was reverse engineered by aprosvetova (https://github.com/aprosvetova/xiaomi-kettle) and then customized and verified by me

I am still not sure about ProductId and how many different ProductIds there are. This needs to be investigated further.

Demo

European ProductId (mine) is 275

Place your kettle near your Bluetooth device (for example RaspberryPi)

Run:

hcitool lescan

You can see the Mac address near MiKettle

Run demo by providing MAC address of your kettle and your ProductID (275 for EU).

pip3 install bluepy
python3 setup.py install
python3 demo.py connect AB:CD:EF:12:34:56 275

Functionality

Supports reading of these values:

  • Current action
  • Current Mode
  • Keep warm set temperature
  • Current temperature
  • Keep warm type
  • Keep warm time

Supports controlling of these values:

  • TBD

To use this library you will need a Bluetooth Low Energy dongle attached to your computer or Raspberry PI. You will also need a Xiaomi Mi Kettle.

To use with home-assistant please refer to documentation over at home assitant custom component https://github.com/drndos/mikettle-ha

Backend

Backend is using bluepy library. Please refer to installation instructions - https://github.com/IanHarvey/bluepy

Conttributing

please have a look at CONTRIBUTING.md


Projects Depending on mikettle

(TBD) https://github.com/home-assistant/home-assistant

mikettle's People

Contributors

aqualx avatar drndos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mikettle's Issues

strange value (non-hex) in DEBUG parse data

Output from demo.py

...
DEBUG:mikettle.mikettle:Parse data: b'\x00\xff\x00\x00PJ\x01\x00\x00\x01\x18\x00'
DEBUG:mikettle.mikettle:data parsed {'action': 'idle', 'mode': 'none', 'set temperature': 80, 'current temperature': 74, 'keep warm type': 'cool down', 'keep warm time': 0}
...

In the fourth byte-data there are non-hex characters.
Must be the data for the temperature, is it?

    def _parse_data(self, data):
        """Parses the byte array returned by the sensor."""
        res = dict()
        res[MI_ACTION] = MI_ACTION_MAP[int(data[0])]
        res[MI_MODE] = MI_MODE_MAP[int(data[1])]
        res[MI_SET_TEMPERATURE] = int(data[4])
        res[MI_CURRENT_TEMPERATURE] = int(data[5])
        res[MI_KW_TYPE] = MI_KW_TYPE_MAP[int(data[6])]
        res[MI_KW_TIME] = MiKettle.bytes_to_int(data[7:8])
        return res

Hello.

I need to using with homeassisant.

Is it yet?

Thanks.

Mi Smart Kettle Pro

Any change to get it working with
NAME: Mi Smart Kettle Pro
MODEL: yunmi.kettle.v12

Sensor won't update only one time after restart Home asistant

Hi,

Only when i restart home assistant, the data is updating. any way this issue can be fixed?
i try adding the force update without success.
this is my config below:

  • platform: mikettle
    mac: 'B8:7C:6F:23:1A:1S'
    product_id: 275
    force_update: true
    monitored_conditions:
    • action
    • mode
    • set temperature
    • current temperature
    • keep warm type
    • keep warm time

Is there a way to overcome this issue? maybe i'm doing something wrong?
how often the sensor is been updating ?

tf is a productID

I was trying to run your script but i ran into a problem with product id
i tried the common id's like 275 131 and 1116 but none of the worked.

connection loss when getting data

Tried to hack my new MiKettle with your python script, thank you for fiddling this out!

It seems to connect for a short period of time. The little bell sound from the kettle appears, the connection is lost.

Debug information:

pi@raspberry:~/mikettle $ python3 demo.py connect XX:XX:XX:XX:XX:XX 275
DEBUG:mikettle.mikettle:Init Mikettle with mac XX:XX:XX:XX:XX:XX and pid 275
Authenticating
Getting data from mi Kettle
FW: 7.5.10
Traceback (most recent call last):
  File "demo.py", line 78, in <module>
    main()
  File "demo.py", line 74, in main
    args.func(args)
  File "demo.py", line 47, in connect
    print("Name: {}".format(kettle.name()))
  File "/home/pi/mikettle/mikettle/mikettle.py", line 87, in name
    self.connect()
  File "/home/pi/mikettle/mikettle/mikettle.py", line 82, in connect
    self._p = Peripheral(deviceAddr=self._mac, iface=self._iface)
  File "/home/pi/.local/lib/python3.7/site-packages/bluepy/btle.py", line 391, in __init__
    self._connect(deviceAddr, addrType, iface)
  File "/home/pi/.local/lib/python3.7/site-packages/bluepy/btle.py", line 439, in _connect
    raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral XX:XX:XX:XX:XX:XX, addr type: public

Can you give me a hint, how to get in this further?

Domoticz integration

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?

Failed to connect to peripheral

I'm Executin the following:

`pi@pi:~/kettle $ python3 demo.py connect B8:7C:6F:A9:08:61 1116

DEBUG:mikettle.mikettle:Init Mikettle with mac B8:7C:6F:A9:08:61 and pid 1116
Authenticating
Getting data from mi Kettle
FW: 7.5.10
Traceback (most recent call last):
File "/home/pi/kettle/demo.py", line 77, in
main()
File "/home/pi/kettle/demo.py", line 73, in main
args.func(args)
File "/home/pi/kettle/demo.py", line 47, in connect
print("Name: {}".format(kettle.name()))
File "/home/pi/kettle/mikettle/mikettle.py", line 87, in name
self.connect()
File "/home/pi/kettle/mikettle/mikettle.py", line 82, in connect
self._p = Peripheral(deviceAddr=self._mac, iface=self._iface)
File "/usr/local/lib/python3.9/dist-packages/bluepy/btle.py", line 391, in init
self._connect(deviceAddr, addrType, iface)
File "/usr/local/lib/python3.9/dist-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral B8:7C:6F:A9:08:61, addr type: public`

The kettle gives a peep sound (With other product id it does not, so I think that part is right) but it's not able to fully connect to the Mi Kettle. Any ideas?

Wrong Handle numbers for my Kettle (Mijia Kettle Pro)

Hi drndos.

I'm trying to use your code with HA, but all handles are different for my kettle, so instead of using the handle directly, i'm using the UUID to get the characteristic and then write the data.

The problem is that the UUID 0001 that is used for auth is not visible/unavailable. When I list all characteristics from my Kettle, this is what it returns:
Hi, trying to auth my kettle (mijia kettle pro), but the uuid 0001 is missing from the characteristics.

All uuids returned:

00002a00-0000-1000-8000-00805f9b34fb
00002a01-0000-1000-8000-00805f9b34fb
00002a04-0000-1000-8000-00805f9b34fb
00002a05-0000-1000-8000-00805f9b34fb
00002a50-0000-1000-8000-00805f9b34fb
00002a28-0000-1000-8000-00805f9b34fb
00010203-0405-0607-0809-0a0b0c0d2b10
00010203-0405-0607-0809-0a0b0c0d2b11
00010203-0405-0607-0809-0a0b0c0d2b12
00010203-0405-0607-0809-0a0b0c0d2b21
00000004-0000-1000-8000-00805f9b34fb
00000010-0000-1000-8000-00805f9b34fb
00000017-0000-1000-8000-00805f9b34fb
00000018-0000-1000-8000-00805f9b34fb
00000019-0000-1000-8000-00805f9b34fb
00000101-0065-6c62-2e74-6f696d2e696d
00000102-0065-6c62-2e74-6f696d2e696d
0000aa01-0000-1000-8000-00805f9b34fb
0000aa02-0000-1000-8000-00805f9b34fb
0000aa03-0000-1000-8000-00805f9b34fb
0000aa04-0000-1000-8000-00805f9b34fb
0000aa05-0000-1000-8000-00805f9b34fb

Have you had any kind of problems like this?
Any ideas?

I tried to decompile the APK but it even after removing obfuscation, continues bad for reading...

Thanks!

Bluetooth command failed (code: 3, error: Attribute can't be written)

I'm getting similar error to drndos/mikettle-ha#3 (comment) in my HA. So I went further and I'm trying to troubleshoot the root cause.

I'm trying to run demo.py but I'm getting the following error:

$ python demo.py connect AB:CD:EF:12:34:56 275
DEBUG:mikettle.mikettle:Init Mikettle with mac AB:CD:EF:12:34:56 and pid 275
Authenticating
Getting data from mi Kettle
Traceback (most recent call last):
  File "/tmp/mikettle/mikettle/demo.py", line 78, in <module>
    main()
  File "/tmp/mikettle/mikettle/demo.py", line 74, in main
    args.func(args)
  File "/tmp/mikettle/mikettle/demo.py", line 46, in connect
    print("FW: {}".format(kettle.firmware_version()))
  File "/tmp/mikettle/mikettle/mikettle/mikettle.py", line 99, in firmware_version
    self.auth()
  File "/tmp/mikettle/mikettle/mikettle/mikettle.py", line 181, in auth
    self._p.writeCharacteristic(_HANDLE_AUTH_INIT, _KEY1, "true")
  File "/tmp/mikettle/venv/lib/python3.9/site-packages/bluepy/btle.py", line 543, in writeCharacteristic
    return self._getResp('wr')
  File "/tmp/mikettle/venv/lib/python3.9/site-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/tmp/mikettle/venv/lib/python3.9/site-packages/bluepy/btle.py", line 368, in _waitResp
    raise BTLEGattError("Bluetooth command failed", resp)
bluepy.btle.BTLEGattError: Bluetooth command failed (code: 3, error: Attribute can't be written)

@djmalin, how did you fix your your issue?
Any ideas what might be wrong?

How does one figure out a product ID?

Hi!

I've a Viomi Smart Kettle SK-152A that integrates with the Xiaomi Mi Home app. It shows up on htmgmt find as "MiKettle" (MAC B8:7C:6F:xx:xx:xx). Attempts to talk to it using the known Xiaomi MiKettle product IDs (275 or 131) fail with Exception: Authentication failed when I run python demo.py connect $MAC $PID.

Now I'm not 100% sure it uses the same protocol (although the "MiKettle" name is very telling), but if it is, how would I go about figuring out the right product ID to use? Random guessing doesn't seem very productive.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.