Automation to change light temp/brightness while it is on - how?

Hello, HA community!

I am a newbie, starting my HA quest.

I have two LIFX bulbs, and I want to change their color temperature depending on the sun position (from cool to warm light in the evening, for example). How to do it while the bulbs are on already? “Light” has only on/off/toggle services. Should I call “on” action with the new parameters while the lights are on?

I found some github discussions related to this, but it is unclear to me if this functionality is now available and how to use it.

Thanks!

I achieve something similar with Hue.

Use the light.turn_on service, and supply the the new brightness/settings you want that way.

In one of my rooms, when it gets late, I have my lamp slowly dim down over 2 minutes using this code:

- service: light.turn_on
      entity_id: light.phils_lamp
      data:
        brightness: 50
        transition: 120

Could you use the Flux component? https://home-assistant.io/components/switch.flux/

Seems to do what you want. There is also an update function builtin so that you could use that to call the Flux service whenever you specifically want to update the lights.

I don’t use this… yet, but want to soon. Let us know if you implement it and it works out.

1 Like

Oh, that is exactly what I wanted to code manually! I wanted the color temp to be sliding all day long, regardless of the on/off state of the lights. Whenever I turn the lights on, they should be the correct color for the time of day, and keep changing if on. Let me try. Man, I love HAss.

It works! When I flip Flux on, it logs every minute, and I see the colors change.

Now I need to turn it off when I set lights to 50% brightness for movie scene. Flux overrides it if I leave it on, even when I do not specify brightness in Flux config.

Thanks, ammdc7!

Hmm, I broke it. When I had only one flux component, it worked. I could change bulbs’ temp from the LIFX app, and it will slowly drift back to what flux says. I aslo could see the new color temp reflected in the app. But it was interfering with movie scene (lights 50%).

I then modified that scene to turn off flux and make forced flux_update. After that the bulbs ignore color temp settings completely. IN the logs flux says it is setting temp 260, bulbs say they are at 260. But the LIFX app and my eyes see them at 125 (1,000,000/8000K). The bulbs change brightness, go off and on normally. Flux component goes off and on. In the logs I see flux every 30 sec, light service for both bulbs, but no state change from them. And the color is wrong.

When I change anything in the LIFX app, I see state changes in the log.

I tried to reboot HAss and bulbs. No change…

EDIT: bulbs seem to drift apart in color from each other after some time. I removed all changes, only kept the flux entry. After an hour one bulb is noticeably bluer than the other.

Very interesting… let me put some work on getting mine running this weekend to see if I can help. I will using this with some Osram Lighitfy bulbs and bridge, but as far as I know, it should work the same.

http://pastebin.com/xA4awvbM

I rebooted. Manually set bulbs to 7500K (eq to 133 mireds), turned them off. Turned flux on. That is the beginning of the pasted log file.

Then I turned on flux switch. You can see it working, but no replies from bulbs.

Then I switched flux off and activated “Movie on” scene, which does forced flux_update and turns the bulbs on at 50% brightness. You can see the bulbs have color_temp=420, which is eq to 2380K - nowhere near the actual value or desired value at that time of day.

Then I turned flux on again. It succeeded in turning the brightness to 100%, but did nothing to color temp. Both old and new state has the same color_temp=420. Meantime the actual bulbs are still on 7500K and not changing color at all.

Not sure how it worked at the very beginning. I cannot replicate it. Seems like the bulbs just ignore any color temp settings.

Please let me know how I can help. Log more? Test some changes?

switch 2:
platform: flux
lights:
- light.lifx_bulb_1
- light.lifx_bulb_2
name: Color Temp Magic
start_colortemp: 5000
sunset_colortemp: 3500
stop_colortemp: 2700
brightness: 255

scene:

  • name: Movie On
    entities:
    switch.color_temp_magic: off
    light.lifx_bulb_1:
    state: on
    brightness: 125
    rgb_color: [255,255,255]
    transition: 1
    light.lifx_bulb_2:
    state: on
    brightness: 125
    rgb_color: [255,255,255]

automation:

  • alias: “Kodi playing”
    trigger:
    • platform: state
      entity_id: media_player.kodi
      to: “playing”
      action:
    • service: switch.flux_update
      entity_id: switch.color_temp_magic
    • service: scene.turn_on
      entity_id: scene.movie_on

Just found out that when I call service to turn a bulb off, it appears to work and the state changes in the UI. But the bulb itself is still on. When I flip the switch in the UI, that works as expected, the bulb goes on and off, no delay and no fail.

That means I cannot trust the log file. It says a lot of things, but there is no real action.

Can you still control the bulb via the LIFX app? The local API that is used to control the bulbs has no rate limiting so sending to many requests back to back can cause the LIFX bulb to lockup and need a restart, usually by turning the power to the LIFX bulb on and off.

I didn’t know that about LIFX bulbs as I don’t have any, but that would make aymercury’s log make more sense. If you look through the event state changed time-stamp, almost every one references the state change at 12:11:29 indicating to me that the bulb just isn’t changing. If it locked up due to the number of requests, that would make sense. (At least to me anyway!)

Yes, I can control the bulbs thru the LIFX app and, strangely, thru HAss UI. I can click on any bulb and change its color and brightness by dragging sliders. At the same time, flux can’t. It looks like it uses some other communication method with bulbs, or lower priority. Or HAss ignores what flux asked. The bulbs are definitely reacting, not frozen.

still does not work…

I have been testing this and can confirm… the flux switch does not work. I did see that 0.26 has some fixes for switch.flux so hopefully this won’t be for long.

Thank you!

I upgraded to 0.26.2 and flux still does not work. I can change color temp from UI manually - that works. I see flux sending commands in the log, but no visible color change happens in this case.

@aymercury Try updating to the new 0.27.0. I have been testing it out this afternoon and it seems to be working as intended. I did have to change the ‘mode’ to mired in order for my Osram Lightify bulbs to recognize the flux.switch, but it seems to be working for me now.

Of note… this update has a number of updates that made this possible through the Wink hub and Osram lightify bulbs. Before this update, I was not able to get this working correctly in this configuration.

Updated to 0.27.1. I saw new flux options, tried them all.

Good news: flux now can change the color temperature of my LIFX bulbs, both in sync. Works ONLY if I set the mode to ‘mired’. In ‘kelvin’ mode the bulbs reject the value flux tries to pass, I see errors in log (passed value 5100, max 400). In ‘xy’ mode it does not work at all.

Bad news: the bulbs (or lifx component) misread the values! In the logs I see the desired color in K (below it is 5545K). The next two lines show it as 180 mired, which is 1000000/180 = 5555K, very close. But the bulbs are set to 2996K, as reported in the LIFX android app. And they are ridiculously red/yellow for the time of day.

I can manually change the color, and flux will bring it back. At least this is reliable now. But the result is wrong…

Aug 31 11:14:00 raspberrypi hass[15464]: INFO:homeassistant.components.switch.flux:
Lights updated to temp:5545.163946540549, 38% of day cycle complete at
2016-08-31 11:14:00.501246-04:00

Aug 31 11:14:30 raspberrypi hass[15464]: INFO:homeassistant.core:Bus:
Handling <Event call_service[L]: domain=light, service=turn_on, service_call_id=1978463184-42,
service_data=transition=30, entity_id=light.lifx_bulb_1, color_temp=180>
Aug 31 11:14:30 raspberrypi hass[15464]: INFO:homeassistant.core:Bus:
Handling <Event call_service[L]: domain=light, service=turn_on, service_call_id=1978463184-43,
service_data=transition=30, entity_id=light.lifx_bulb_2, color_temp=180>

Beyond my scope at this point…

Maybe @HBDK or @nkgilley could lend a hand as to what is happening.

Thanks! I looked at lifx.py and it seems that color temp calculations may be the issue. Can I just edit that file and see the effects (maybe, after HAss restart)?