Yeelight led ceiling light compatible with HA


Looks like moonlight mode is now supported in the library v0.4.0 as a “Power Mode” (5). So a boolean toggle for moonlight mode has be added to the light and multiple functions in the HASS side will need to be changed (bear with me, I’m new to this):

  1. Update: Check if power mode is 5 and set boolean.
  2. Turn_On: Add set_mode to set power mode.

The “transition presets” (HASS effects) in the library seem to be old and for RGB bulbs only. Since I don’t have an RGB yeelight, I can’t test those.

The new ones for the ceiling light, I can test once they are added to the library.


I’ve added the moonlight mode to the Home Assistant Component recently. Check the docs!


Yup saw that service LIGHT.YEELIGHT_SET_MODE now can set mode = moonlight. But it is not exposed in the UI.

EDIT: This is fine for me (and most) since I can use it in automations and scenes. The effects are probably better done first, IMHO.


Guys, I’ve also tested the new yeelight.set_mode service and it works nicely.
This one:

The only problem is when moonlight is activated, light.toggle on the wireless wall switch doesn’t work as intended anymore. I have to use HA or remote to take it back to normal.
Any workarounds or ideas?


What do you do (at HA) to take the light back to normal? May be we can improve the behavior of the component.


Well you have to change light.yeelight_set_mode back to normal, that’s the only way (call that service through separate automation for example), but then you get scorching white light, so it’s pretty useless for my scenario. It would be great it the mode could be turned to normal without turning the light on.

My scenario:

  1. on motion sensor turn moonlight mode on after midnight
  2. on motion sensor off turn moonlight mode off
  3. if someone presses the switch/button manually turn on normal mode (not last mode used which was moonlight).

Hope I’m making sense :slight_smile:


I think you cannot do this with light.toggle. I use light.turn_on with kelvin and brightness_pct and the mode switches automatically back to sun mode, with colour and brighness as specified.
I use one click to turn the light on and double click to turn it off (some xiaomi button).
You could also do some automation to switch back to sun mode and specify kelvin and brightness.


Yes, that’s what I thought. My problem is that it’s double wall switch (Aqara one) and I only have one button I can use for the ceiling lamp. So I have to use toggle :frowning:

If I make automation that changes back to normal (which is sun) it also turns the lamp on. That behavior just doesn’t work in my case.


For RGB: I can test if you want. What needs to be changed in the library? The support for the background light is missing, right?

For UI element to switch between moon/normal mode (@mouth4war):
To check if the ceiling light is in moonlight, use bulb.get_properties(["nl_br"]). It will return 0 if not in moonlightor [1…100] if in moonlight


ambilight for 650 is cool. I can test it too if anyone need.


@syssi: latest dev is causing exceptions.

ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/”, line 316, in _async_add_entity
await entity.async_update_ha_state()
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/”, line 222, in async_update_ha_state
attr = self.state_attributes or {}
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/light/”, line 501, in state_attributes
data[ATTR_MIN_MIREDS] = self.min_mireds
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/light/”, line 258, in min_mireds
return kelvin_to_mired(YEELIGHT_SPECS[‘rgb’][‘max_kelvin’])
KeyError: ‘rgb’


Could you post your configuration? You’ve defined a model called “rgb”, right?


I think I misinterpreted the exception. Paste above.


  - platform: yeelight
        name: Kitchen Ceiling Lamp
        use_music_mode: False
        model: ceiling1
        transition: 350


Your interpretation was fine. I fixed the error and prepared a PR now:


Tested here and it works fine now.


Anyone can explain me how to use “light.yeelight_set_mode” for set an rgb value to a turned on light?


The turn_on service is what you’re looking for:


I’m not at home for testing, so I ask: does it work also if light is already turned on?


Yes. You can call turn_on multiple times with different configuratins / data sets.


Could someone post an automation example with:
light.yeelight_set_mode {"mode": 5, "entity_id": "light.ceiling"} ??