Xiaomi Yeelight E27 bulb component

Well, this would require some changes in the library I guess. I will give it a try when I find some time.

Thank you for your response. it would be nice if you give it a try.
I created sort off a little workaround. It dims the lights based on two scenes which are called from a script.
But i think if you manage to implement it, it would look better.

Workaround to dim light and then turn them off:

scenes.yaml

name: dim
entities: 
   light.grotetafel:
      state: on
      brightness: 2
      transition: 5
   light.kleinetafel:
      state: on
      brightness: 2
      transition: 5

and

name: offf
entities: 
   light.grotetafel:
      state: off
   light.kleinetafel:
      state: off

Then i use this script to activate both scenes:

script.yaml

dimoff:
  sequence:
   - service: scene.turn_on
     entity_id: scene.dim
   - delay:
      seconds: 5     
   - service: scene.turn_on
     entity_id: scene.offf

@Mister-Espria I have submitted a pull request to @mxtra for the fade on and fade off feature.

@jared Thank you!! Can’t wait to test it out.

Hey i just tried the code, for turning on it is looks really awesome! Thanks again.
but i don’t manage to get fade to off to work.

I tried this:
config.yaml

light:
   platform: yeelight
   automatic_add: False
   transition: 1000
   devices:
     192.168.1.15:
        name: kleinetafel
     192.168.1.16:
        name: grotetafel

scenes.yaml:

name: offf
entities: 
   light.grotetafel:
      state: off
      transition: 1000
   light.kleinetafel:
      state: off
      transition: 1000

scripts.yaml:

dimmenduit:
  sequence:
   - service: light.turn_off
     data:
           entity_id: light.grotetafel
           transition: 1000

and some more possibilities.

I somehow managed by reading the documentation to telnet into the lamp and when i send this command:

{“id”:1,“method”:“set_power”,“params”:[“off”, “smooth”, 2000]}

it does fade to off (so it’s not the bulb).

1 Like

@mxtra is either really busy or doesn’t want to merge my pull request. You need to wait on him.

Waiting is not a problem at all for me. It’s already awesome what is done!
But i messed with it a little bit. I used your _ init_.py and yeelight.py from your github.
It should work right?

For me at least it is working fine with fade-to-on. But fade-to-off was not working. Which is kind of strange because the code for turnOn and turnOff is the same.
(But i read in the yeelight documentation that when the effect is sudden the parameter transition will be ignored. But then it would be strange turnOn is working. Maybe i have this all wrong i am not a developer only did a few things in vba excel this is another level)

I modified turnOff in _ init_.py to make the effect variable :

def turnOff(self, transtime, effect):
    self.state = 0
    self.operate_on_bulb('set_power', '"off","' + effect + '",' 
                        + str(transtime))

And this is the modification in yeelight.py:

def turn_off(self, **kwargs):
    """Turn the bulb off."""
    transtime = 0
    effect = 'sudden'
    if ATTR_TRANSITION in kwargs:
        transtime = kwargs[ATTR_TRANSITION]
        effect = 'smooth'
    elif self.transition:
        transtime = self.transition
    
    if self.is_on:
     self.bulb.turnOff(transtime, effect)

With this change fade-to On and Off is working for me, but it also comes with a problem and that is that i can’t use transition in scenes or anything. Only in config.yaml. When is use transition in a scene the default of 350 is used and not the value i entered.
But maybe i just have to wait till everything is merged?:slight_smile:

I’ll merge it tonight.

Awesome! Thank you.

I’m sorry. I recently started my studies and was really busy for the last two weeks.
I did now merge it.

@Mister-Espria Is this working? I ran into some issues setting my own lights up. For whatever reason when I was testing the fade on / fade off , it was working, but it shouldn’t have.

If it’s not working, try setting your dependency to my tag (line 20):
REQUIREMENTS = [‘https://github.com/jjensn/pyyeelight/archive/v1.7.zip#pyyeelight==1.7’]

@jared No for me it isn’t working either. I have the same issue as in post 87

So only fade to on is working and fade to off is just instantly off.
Sorry for not reporting back but i have some segfault issues with my ha at the moment. But i’m gonna try your dependency now.
I will report back soon.

@jared I tried the code, but i don’t get it to turnoff the bulbs not with fading and not instantly.
I saw home assistant installing your v1.7, but to be sure which yeelight.py are you using your forked one or the one from mxtra from 17 days ago?

when turning off i get this in the log:

16-10-29 22:01:25 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py", line 1221, in job_handler
    func(*args)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py", line 1075, in execute_service
    service_handler.func(service_call)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/light/__init__.py", line 223, in handle_light_service
    getattr(light, service_fun)(**params)
  File "/home/hass/.homeassistant/custom_components/light/yeelight.py", line 135, in turn_off
    self.bulb.turnOff()
TypeError: turnOff() missing 1 required positional argument: 'transtime'

@Mister-Espria right right right, you also need to update your device code:

@jared Thank you! now we are getting there. Fading on and off is now working. Turning off and on is also working but it uses (i think) the default transition time. I don’t know if this is intended or not?

When i use scenes with a transition time of 5000 it still uses the default transition time (i think because it’s a lot quicker than 5 seconds). When i use transition: 0 in a scene it will do it instantly.

This is not new in your code i had the same with the previous versions.

you should submit a pull request with the fix

? I didn’t do anything. i’m just using your files. And if i have a solution for the current problem i’m happy to share it. But i don’t know if i can manage to get transition working.

Thanks for your work,

This has not been working for me for few weeks already.

I am using…

This is what I have in my configuration…

platform: yeelight
transition: 500
devices:
  192.168.1.6:
    name: entrance
  192.168.1.7:
    name: carporch_1
  192.168.1.8:
    name: carporch_2
  192.168.1.9:
    name: carporch_3

Is anyone else facing the same problem?

1 Like

Yeelight is now available in the latest release:

1 Like