Yeelight led ceiling light compatible with HA

I have added template switch to enable changing mode from GUI:

switch:
- platform: template
  switches:
    yeelight_ceiling_lamp_bedroom_nightlight:
      value_template: "{{ is_state('binary_sensor.yeelight_ceiling_lamp_bedroom_nightlight', 'on') }}"
      turn_on:
        service: yeelight.set_mode
        data:
          entity_id: light.yeelight_ceiling_lamp_bedroom
          mode: moonlight
      turn_off:
        service: yeelight.set_mode
        data:
          entity_id: light.yeelight_ceiling_lamp_bedroom
          mode: normal

Thanks for response.

I use two different ceiling lights:
ceiling1 YLXD01YL

and one that is not mentioned in the list of supported models, but it works, is available in yeelight mobile application and has moonlight feature:
Xiaomi Mi MiJia LED Ceiling Light

I have a ceiling4 (it has a sensor) and 2 ceiling1 lights. The ceiling1 has moonlight support, I use it at the night light automation from since the beginning. Iā€™ll try to call the yeelight.set_mode: normal at the widget.

My yeelights are auto configurated, nothing special and it has moonlight ability.

The underlying library needs to be updated to enable the moonlight support for ceiling1 and celiling2. We will care about. At the moment ceiling3 and 4 is supported only.

Could you provide the mDNS / model name of this device? You can find the name probably next to the DHCP lease at your router.

Thank you for this explanation. This makes sense, although Iā€™d prefer that the light has the mode that it had when I switched it off (i.e., stay at moonlight). However, thanks to lovelace, it should be no problem with conditional cards to achieve both with your the planned two-lights-approach. So I am happy and will arrange with whatever you implement :grin:

I can already see there are some use cases for not having separate light entities. I will look at adding some config option, like moonlight_switch_type, with default value to ā€œnoneā€ and optional values ā€œseparate_lightā€ etc. It would also allow to add brightness slider moonlight / daylight switch option, as suggested by @zoe1337.

@thawizard I donā€™t think its possible now. Maybe using some custom lovelace cards ?

I did. Thanks to your binary_sensor :wink:

screenshot_1114

Cool, can you share config ? Iā€™ve meant on the light card, when you open some entity. I donā€™t think its customizeable now ?

Anything changed in 0.91.1? My Yeelights are stopped working (Ceiling light + RGB bulb), auto discovery.

https://pastebin.com/maXn1vuk

Thats the only change in 0.91.1 https://github.com/home-assistant/home-assistant/pull/22756/files . Iā€™m also running 0.91.1 and donā€™t have that problem. Whats your setup ? Looks like some kind of race condition in libs import ? Maybe it tries to import yeelight component as python-yeelight ? Did you change anything before upgrade ?

I am running hass.io on Ubuntu server, nothing special. On 0.91.0 I installed this:

and worked fine.

Today I upgraded to 0.91.1 and got the problem above. I restarted multiple times, not helped. I moved yeelight from custom_components folder then restarted, not helped.

Back to 0.91.0 Yeelights are found and working as usual.

Update!

I removed custom_components/yeelight folder, upgraded and now it is working.

While it is working in log I see:

_frozen_importlib._DeadlockError: deadlock detected by _ModuleLock('yeelight.enums') at 140112646206184
2019-04-06 18:43:18 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up platform yeelight
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 126, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/yeelight/binary_sensor.py", line 21, in setup_platform
    if device.is_nightlight_supported:
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/yeelight/__init__.py", line 235, in is_nightlight_supported
    return self.bulb.get_model_specs().get('night_light', False)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/yeelight/__init__.py", line 188, in bulb
    import yeelight
  File "/usr/local/lib/python3.7/site-packages/yeelight/__init__.py", line 5, in <module>
    from yeelight.main import Bulb, BulbException, discover_bulbs
  File "/usr/local/lib/python3.7/site-packages/yeelight/main.py", line 11, in <module>
    from .enums import BulbType, LightType, PowerMode
  File "<frozen importlib._bootstrap>", line 980, in _find_and_load
  File "<frozen importlib._bootstrap>", line 149, in __enter__
  File "<frozen importlib._bootstrap>", line 94, in acquire
_frozen_importlib._DeadlockError: deadlock detected by _ModuleLock('yeelight.enums') at 140112646206184

Can you describe your setup ? I donā€™t have that error :\ ( Are you using hassio, how HA is installed ). Iā€™ve looked at code and optimized some imports, lets hope it will solve it. Can you try this code and see if it solved issue for you ? https://github.com/home-assistant/home-assistant/pull/22804.

EDIT: Iā€™ve found out why custom_component didnā€™t worked well. It needs to use relative imports, and it was missed from auto relative imports migration, because it was not a component there. This should fix it https://github.com/home-assistant/home-assistant/pull/22839/files

1 Like

Hi @milakov, how you set the related binary sensor ?

It is automatically created by Yeelight component for my ceiling lamp.
This section creates a light and binary_sensor for me:

yeelight:
  devices:
    192.168.1.74:
      name: Yeelight Ceiling Lamp Bedroom
      model: ceiling3
      transition: 350
1 Like

Previously I used the yeelight set mode only at night light automation and it is worked well. Now it doesnā€™t work perfectly because the moonlight mode uses the brightness off previous daylight setup maybe because it is very bright, therefore I have to call the light switch on service with brightness attribute too. It is working but not exactly smooth, noticeably slower than before. I have only one benefit for me with the new platform so far, this is the ambilight.
Maybe would be better the moonlight function as a separate entity like the ambilight at the ceiling4.

I just retested it and when switching moonlight / daylight via set_mode, it uses correct brightness. When you switch mode, HA will now read brightness from correct property ( before it was always returning daylight brightness in ui ). Same bug exist in yeelight app. When you switch between daylight and moonlight, brightness slider stays at the same place. In new yeelight code in HA it should work as expected, after mode switch, it should change brightness. Try to set moonlight, change brightness, set normal mode, change to other brightness and set moonlight again and check brightness then plz.