Yeelight Night Light Dimmable Bed Lamp BT

i haven’t find the integrations for this model: http://www.gearbest.com/smart-home/pp_197251.html?wid=21
and i have find this code: https://github.com/leopck/Yee-Light-Blue , but my know is not enough to create the plugin.

thanks to all.

Yeelight blue is a different product (http://www.gearbest.com/smart-home/pp_159352.html) than this bed side lamp, I’m not sure if they even communicate with the same protocol. Anyways, I’m receiving my bedside lamp soon I hope, and my plans are integrate it someway or another to homeassistant.

Hi find this reverse engineering hope that useful

https://github.com/Marcocanc/node-mi-lamp/blob/master/notes.md

thanks

Thanks for the link, it was indeed helpful! There’s now a project here for this lamp: https://github.com/rytilahti/python-yeelightbt – any help (patches, implementing more features) is very welcome :slight_smile: it has not yet been battle-tested for very long time, so it may not yet be suitable for regular use.

In anycase, patches & bug reports are welcome!

1 Like

Hello, do I need to install the whole python-yeelightbt repo?
I’m getting an error of no such file and directory. The README says I need to go to the bluepy directory but the installation immediately deletes it after failure.
I wanted to install this so I could check my bedside’s bluetooth mac address. IT doesn’t show up on the yeelight app nor phone’s bluetooth scan.

Here’s the error:
b"make: Entering directory '/tmp/pip-build-4tl7uko9/bluepy/bluepy'\ntar xzf bluez-src.tgz\ntouch ./bluez-5.29/lib/bluetooth.c ./bluez-5.29/lib/hci.c ./bluez-5.29/lib/sdp.c ./bluez-5.29/lib/uuid.c ./bluez-5.29/attrib/att.c ./bluez-5.29/attrib/gatt.c ./bluez-5.29/attrib/gattrib.c ./bluez-5.29/attrib/utils.c ./bluez-5.29/btio/btio.c ./bluez-5.29/src/log.c ./bluez-5.29/src/shared/mgmt.c ./bluez-5.29/src/shared/crypto.c ./bluez-5.29/src/shared/att.c ./bluez-5.29/src/shared/queue.c ./bluez-5.29/src/shared/util.c ./bluez-5.29/src/shared/io-glib.c ./bluez-5.29/src/shared/timeout-glib.c\nPackage glib-2.0 was not found in the pkg-config search path.\nPerhaps you should add the directory containingglib-2.0.pc’\nto the PKG_CONFIG_PATH environment variable\nNo package ‘glib-2.0’ found\nPackage glib-2.0 was not found in the pkg-config search path.\nPerhaps you should add the directory containing `glib-2.0.pc’\nto the PKG_CONFIG_PATH environment variable\nNo package ‘glib-2.0’ found\ngcc -L. -Os -g -Wall -Werror -DHAVE_CONFIG_H -I./bluez-5.29/attrib -I./bluez-5.29 -I./bluez-5.29/lib -I./bluez-5.29/src -I./bluez-5.29/gdbus -I./bluez-5.29/btio -o bluepy-helper bluepy-helper.c ./bluez-5.29/lib/bluetooth.c ./bluez-5.29/lib/hci.c ./bluez-5.29/lib/sdp.c ./bluez-5.29/lib/uuid.c ./bluez-5.29/attrib/att.c ./bluez-5.29/attrib/gatt.c ./bluez-5.29/attrib/gattrib.c ./bluez-5.29/attrib/utils.c ./bluez-5.29/btio/btio.c ./bluez-5.29/src/log.c ./bluez-5.29/src/shared/mgmt.c ./bluez-5.29/src/shared/crypto.c ./bluez-5.29/src/shared/att.c ./bluez-5.29/src/shared/queue.c ./bluez-5.29/src/shared/util.c ./bluez-5.29/src/shared/io-glib.c ./bluez-5.29/src/shared/timeout-glib.c \nbluepy-helper.c:33:18: fatal error: glib.h: No such file or directory\n #include <glib.h>\n ^\ncompilation terminated.\n./bluez-5.29/attrib/att.c:33:18: fatal error: glib.h: No such file or directory\n #include <glib.h>\n ^\ncompilation terminated.\n./bluez-5.29/attrib/gatt.c:32:18: fatal error: glib.h: No such file or directory\n #include <glib.h>\n ^\ncompilation terminated.\n./bluez-5.29/attrib/gattrib.c:34:18: fatal error: glib.h: No such file or directory\n #include <glib.h>\n ^\ncompilation terminated.\n./bluez-5.29/attrib/utils.c:30:18: fatal error: glib.h: No such file or directory\n #include <glib.h>\n ^\ncompilation terminated.\n./bluez-5.29/btio/btio.c:37:18: fatal error: glib.h: No such file or directory\n #include <glib.h>\n ^\ncompilation terminated.\n./bluez-5.29/src/log.c:32:18: fatal error: glib.h: No such file or directory\n #include <glib.h>\n ^\ncompilation terminated.\n./bluez-5.29/src/shared/io-glib.c:30:18: fatal error: glib.h: No such file or directory\n #include <glib.h>\n ^\ncompilation terminated.\n./bluez-5.29/src/shared/timeout-glib.c:22:18: fatal error: glib.h: No such file or directory\n #include <glib.h>\n ^\ncompilation terminated.\nMakefile:28: recipe for target ‘bluepy-helper’ failed\nmake: *** [bluepy-helper] Error 1\nmake: Leaving directory ‘/tmp/pip-build-4tl7uko9/bluepy/bluepy’\n"

`

If you look at the error, it says that you are missing glib.h -> you need to install glib’s development package to get those header files for compilation. But if it isn’t detected by the app, it probably won’t be detected by this component either.

thanks!, that did the trick. However, I couldn’t do any scan since it requires the MAC address. the debug option doesn’t produce any verbose logs.

root@mxs-rpi01:~# yeelightbt scan
Usage: yeelightbt [OPTIONS] COMMAND [ARGS]...
Error: Missing option "--mac".

You can try to put --mac ‘’ for now to make it work, I suppose. I’ll fix that later.

Thanks. Tried that and it goes to scan mode but crashes:

Scanning for 5 seconds
Traceback (most recent call last):
File "/usr/local/bin/yeelightbt", line 9, in <module>
load_entry_point('python-yeelightbt==0.0.2', 'console_scripts', 'yeelightbt')()
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/yeelightbt/cli.py", line 58, in scan
devs = scan.scan(sec)
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 631, in scan
self.start()
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 569, in start
self._mgmtCmd("le on")
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 240, in _mgmtCmd
"Failed to execute mgmt cmd '%s'" % (cmd))
bluepy.btle.BTLEException: Failed to execute mgmt cmd 'le on'

For some reason it isn’t able to activate scanning. Did you give those extra permissions as shown in the README to bluepy-helper (which is located in /usr/local/lib/python3.4/dist-packages/bluepy/ in your setup I think)? You may try yeelightbt --mac ‘’ -dd scan to get more debug output to locate the problem.

I really wanted to get this lamp but I’m not dealing with bluetooth… why didn’t they make it WIFI too!!!

This was one of their first products I think, their new ceiling lamp has both bluetooth and wifi. So far I’m not having big problems with bluetooth although wifi would be easier to handle indeed.

Hi @teprrr,
Just tried your scripts in hass.io (ha v0.55) and do get following error:

2017-10-17 12:53:48 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.6/asyncio/tasks.py”, line 181, in _step
result = coro.throw(exc)
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py”, line 381, in async_process_entity
new_entity, self, update_before_add=update_before_add
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py”, line 212, in async_add_entity
yield from self.hass.async_add_job(entity.update)
File “/usr/lib/python3.6/asyncio/futures.py”, line 331, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.6/asyncio/tasks.py”, line 244, in _wakeup
future.result()
File “/usr/lib/python3.6/asyncio/futures.py”, line 244, in result
raise self._exception
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/light/yeelight_bt.py”, line 163, in update
with self._dev:
File “/config/custom_components/light/yeelight_bt.py”, line 131, in _dev
from yeelightbt import Lamp
ModuleNotFoundError: No module named ‘yeelightbt’

Do you have any tips what might the issue be or in which direction to dig?
Thank you, Alex

You are missing yeelightbt package, which is not currently available from pip. Here’s how to install it: https://github.com/rytilahti/python-yeelightbt#installation

So with some hit and trial I managed to load all scripts in hassio. Also found the mac using a scanner. After first configuration it did not want to connect saying about some weird response from bluetooth device. But on second reboot of HA it worked. Thanks for help. Next IR is on the list…

@teprrr btw, they still produce new devices based on bluetooth. https://www.kickstarter.com/projects/1726969603/yeelight-candela-the-smart-mood-candlelight Ordered 2 of those, so will see how they work with HA once delivered.

Yeah, I’m waiting for my Candelas to arrive, too! According to their developers the API will be similar, so adding a support (if not working directly) should be quite easy. At that point I will upload a more complete implementation and try to get this merged to homeassistant directly.

1 Like

Even though that the lamp is working now the log is still full of following exception:

2017-10-20 20:53:53 ERROR (MainThread) [homeassistant.helpers.entity] Update for light.bedside fails
Traceback (most recent call last):
  File "/config/yeelightbt/lamp.py", line 34, in _wrap
    timeout=wait)
  File "/config/yeelightbt/connection.py", line 100, in make_request
    res = self._conn.writeCharacteristic(handle, value, withResponse=with_response)
  File "/usr/lib/python3.6/site-packages/bluepy/btle.py", line 502, in writeCharacteristic
    return self._getResp('wr')
  File "/usr/lib/python3.6/site-packages/bluepy/btle.py", line 378, in _getResp
    self.delegate.handleNotification(hnd, data)
  File "/config/yeelightbt/connection.py", line 86, in handleNotification
    self._callbacks[handle](data)
  File "/config/yeelightbt/lamp.py", line 194, in handle_notification
    self._status_cb(self)
  File "/config/custom_components/light/yeelight_bt.py", line 158, in _status_cb
    self.update_ha_state()
AttributeError: 'YeelightBT' object has no attribute 'update_ha_state'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 215, in async_update_ha_state
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.6/asyncio/futures.py", line 331, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
    future.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 244, in result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/light/yeelight_bt.py", line 164, in update
    self._dev.state()
  File "/config/yeelightbt/lamp.py", line 41, in _wrap
    self.connect()
  File "/config/yeelightbt/lamp.py", line 85, in connect
    self._conn.disconnect()
  File "/config/yeelightbt/connection.py", line 67, in disconnect
    self._conn.disconnect()
  File "/usr/lib/python3.6/site-packages/bluepy/btle.py", line 417, in disconnect
    self._getResp('stat')
  File "/usr/lib/python3.6/site-packages/bluepy/btle.py", line 369, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/usr/lib/python3.6/site-packages/bluepy/btle.py", line 337, in _waitResp
    raise BTLEException(BTLEException.INTERNAL_ERROR, "Unexpected response (%s)" % respType)
bluepy.btle.BTLEException: Unexpected response (wr)

Does it sound familiar to you?

The component is so old, that HA’s API has changed at some point. I suppose it should read self.schedule_update_ha_state() now, can you change and check if that helps?

1 Like

Yep, did the trick.

Hi @Stewface,

Today yeelight anounced new bedside lamp with wifi and ble.

https://www.mi.com/mj-bedsidelamp/

Also in their forum, talk about the new item:

https://www.mi.com/mj-bedsidelamp/

:slight_smile: