Yeelight light effects don't work

The effects were added to the yeelight component in HA 0.47. I have two YLDP02YL bulbs and when I try to turn on the effect I have error in log and nothing happens:

2017-06-18 13:10:54 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/core.py", line 1021, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/light/__init__.py", line 272, in async_handle_light_service
    yield from light.async_turn_on(**params)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/light/yeelight.py", line 410, in turn_on
    self.set_effect(effect)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/light/yeelight.py", line 98, in _wrap
    return func(self, *args, **kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/light/yeelight.py", line 374, in set_effect
    self._bulb.start_flow(flow)
UnboundLocalError: local variable 'flow' referenced before assignment

I turn on effect by Services tab: light -> turn_on -> { "entity_id": "light.yeelight_color_bulb_salon_1", "effect": "police" }
It’s issue with component or I’m doing something wrong?

i see the same behaviour. I will investigate it further. but trough the UI it is working.

1 Like

Oh i see now. It is working. Only the name is case-sensitive.
So this is working:
{ "entity_id": "light.yeelight_color_bulb_salon_1", "effect": "Police" }

So you can use these effects:

Disco
Slow Temp
Strobe epilepsy!
Strobe color
Alarm
Police
Police2
Christmas
RGB
Random Loop
Fast Random Loop
Slowdown
WhatsApp
Facebook
Twitter
Stop

3 Likes

Yes, with case-sensitive effect name it works greate.

2 Likes

Thanks for adding this function.

If I run the script below when the light is turned off it ends up back at the last on state I used, how would I add a command to turn it off again? Probably obvious but this is my first script so be gentle! Thanks.

script:
  flash:
    alias: Flash
    sequence:
      - alias: on
        service: light.turn_on
        data:
          entity_id: light.lounge_corner_lamp
          effect: WhatsApp

I’ve written this but the results are random, sometimes you get a momentary dim flash, sometimes it does the two green flashes and then goes back to normal for a second before turning off. Assume there must be a ‘proper’ way to do this?

script:
  flash:
    alias: Flash
    sequence:
      - service: light.turn_on
        data:
          entity_id: light.lounge_corner_lamp
          effect: WhatsApp
      - delay:
          seconds: 1
      - service: light.turn_off
        data:
          entity_id: light.lounge_corner_lamp
- service: light.turn_off
  entity_id: light.lounge_corner_lamp

is correct. Maybe longer delay?

Longer delay just extends the amount of time the light goes to static yellow unfortunately.

Guess I might be more successful using an effect that goes continuously and then just turning it off after it’s gone as long as I want.

How would you go about adding a new effect to get different colours or is there a better way to create a notifcation flash?

I understand what you want to achieve. As of right now there is no nice way to turn it off after the effect in case of notifications.

But i changed line 367 in the yeelight.py file Which for my installation i found here: \srv\homeassistant\lib\python3.4\site-packages\homeassistant\components\light\
into this:
flow = Flow(count=2, action=Flow.actions.off, transitions=pulse(37, 211, 102))

So lines 367 changes the Whatsapp effect in going off after it ran. Problem with this is it turns off everytime also when you want the bulb the stay on. So an easy solution i can think of right now is to have two effects. So an WhatsApp and WhatsAppOff effect. Then you can let automations decide to run the WhatsApp effect to run when the bulb is on and the WhatsAppOff effect to run when the bulb is off.

But i think there is still a problem with this change. it seems that turning on and off lights gets quite unresponsive. So that’s something to look into.

Thanks, this is just what I was after, had seen the bits of code like that but couldn’t find any reference to ‘WhatsApp’ to know for sure …was also afraid of buggering the bulb up if I changed things :slight_smile:

Is the unresponsive issue something to do with music mode as I sure it said somewhere that that removes some delay?

To get over the off and on problem I was happy just to use one of the others in it’s original state but how would I go about adding another effect given there doesn’t seem to be a direct coloration between what’s in the menu and what’s in the code?

I don’t know exactly what causing the delay. I have to wait a few seconds before the light turns on when it turn it on since i changed the code.

The corolation you mean you can find at line 56:

EFFECT_DISCO = "Disco"
EFFECT_TEMP = "Slow Temp"
EFFECT_STROBE = "Strobe epilepsy!"
EFFECT_STROBE_COLOR = "Strobe color"
EFFECT_ALARM = "Alarm"
EFFECT_POLICE = "Police"
EFFECT_POLICE2 = "Police2"
EFFECT_CHRISTMAS = "Christmas"
EFFECT_RGB = "RGB"
EFFECT_RANDOM_LOOP = "Random Loop"
EFFECT_FAST_RANDOM_LOOP = "Fast Random Loop"
EFFECT_SLOWDOWN = "Slowdown"
EFFECT_WHATSAPP = "WhatsApp"
EFFECT_FACEBOOK = "Facebook"
EFFECT_TWITTER = "Twitter"
EFFECT_STOP = "Stop"

But the real effects are coming from the \deps\yeelight\transitions.py file.
If you want to add effects you need to add them to here and than also update/ reference them in the yeelight.py file on the home-assistant github.

1 Like

Thanks for the advice, will have a proper play over the weekend.

1 Like

What happens if you add another effect after that: “EFFECT_STOP” ?
Doesn’t it return to it’s original state afterwards then (which means “off” when the light was off when the automation fired)?

Don’t think so, because the light has to be on in the first place to set the effect. so when you use effect_stop it’s last state is on.
What is it you exactly want to achieve: having an effect run only when te bulb is on or having a effect run no matter what if the bulb is on or not. ?

The last one.
But I just tried and indeed the light stays on after the automation unfortunately. I guess two seperate automations is the way to go then.

I was just playing with the fairly new update from the yeelight app. Which enables you to make your own effects and then select them to play on a bulb.
I just discovered that you can activate the effect when the bulb is in “off” mode. after the effect ended it goes off again.
So this means it is possible. so maybe to code needs to be altered a bit.

Nice! I can’t find that option. What version and OS are you using? I’m using version 3.1.09 (Android).

That’s the right one i have the same. if you select the hamburger menu in the top left and click on “personalisatie” ( i think your’s is in dutch aswell?)
then you can create something with the plus icon in the top right.

Found it, thanks :slight_smile:

1 Like