Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for a transition argument to power{On,Off,Toggle} #5

Open
lopter opened this issue Oct 13, 2015 · 16 comments
Open

Add support for a transition argument to power{On,Off,Toggle} #5

lopter opened this issue Oct 13, 2015 · 16 comments
Assignees
Milestone

Comments

@lopter
Copy link
Owner

lopter commented Oct 13, 2015

Equivalent to:

prev_color = get_light_state(target)
set_light_from_hsbk(target, 0, 0, 0 or 1, temperature, 60 * 1000 * 5)
sleep(60 * 5)
powerOff(target)
set_light_from_hsbk(target, prev_color, 0) # requires firmware >= 1.5 for the Original 1000

The LIFX REST API doesn't seem to update the state (color) of the bulb during the transition, but this will.

On top of my head:

  • add new optional argument to the power functions;
  • wrap something around lgtd_timer.
@vegansbane
Copy link

Thanks lopter, this will help free me from cloud dependence with my use case!

@chendo
Copy link

chendo commented Oct 27, 2015

You could use Light::SetPower (http://lan.developer.lifx.com/docs/light-messages#section-setpower-117) and specify the duration there so you don't need to use Light::Set at all

@lopter
Copy link
Owner Author

lopter commented Dec 27, 2015

Hello @chendo,

Sorry I never followed-up on that, it's a very good tip and I see it's supported as far back as firmware 1.5 of the Original 1000!

Unfortunately, the state of the bulb doesn't get updated with this command (i.e: the brightness isn't updated and power is set to toggled immediately), so I'll still emulate the feature as I described.

It's actually cool, it will make me add an internal effects API in lightsd that I'll leverage to implement other features.

@chendo
Copy link

chendo commented Dec 27, 2015

Ah, as you want it to block the method until he transition completes?

On 28 Dec 2015, at 9:43 AM, Louis Opter notifications@github.com wrote:

Hello @chendo,

Sorry I never followed-up on that, it's a very good tip and I see it's supported as far as back as firmware 1.5 of the Original 1000!

Unfortunately, the state of the bulb doesn't get updated with this command (i.e: the brightness isn't updated and power is set toggled immediately), so I'll still emulate the feature as I described.

It's actually cool, it will make me add an internal effects API in lightsd that I'll leverage to implement other features.


Reply to this email directly or view it on GitHub.

@lopter
Copy link
Owner Author

lopter commented Dec 27, 2015

I'm not sure what you mean by block, I just want the state of the bulb to reflect the transition in real time.

@chendo
Copy link

chendo commented Dec 28, 2015

As in you want the physical state of the bulb or what LightState reports to reflect the transition in real time?

@lopter
Copy link
Owner Author

lopter commented Dec 28, 2015

Yes!

@chendo
Copy link

chendo commented Dec 28, 2015

Yes to which one?

@lopter
Copy link
Owner Author

lopter commented Dec 28, 2015

I mean, yes as in LightState should reflect the transition in real time.

@chendo
Copy link

chendo commented Dec 28, 2015

Power transitions are reflected through the power UINT16 in LightState if that helps?

@lopter
Copy link
Owner Author

lopter commented Dec 28, 2015

Ah I did notice that however I'm clamping the value to 0 or 0xffff (I think I have seen some LIFX code do the same thing) since the documentation explicitly says only those values are supported.

How is this value related to the brightness? Is there a (mathematical) formula/function to convert between the two?

Thanks for the help!

@chendo
Copy link

chendo commented Dec 28, 2015

Yeah, you can only set 0 for off and non-zero for on for power. I'd have to check the code to be sure but I assume the brightness is multiplied by the percentage of power. If you want to handle transitions nicely, I have logic in the HTTP API that does stuff like set a 0-brightness version of the desired colour before turning the bulb on, then do the transition to the desired colour to fade on properly, so you can do something similar if you want to deal with that nicely.

@lopter
Copy link
Owner Author

lopter commented Dec 28, 2015

Hmm, I think I get it, SetPower is just misnamed, it should be named SetBrightness am I correct?

Edit: Hang on, I'm confused.

@lopter
Copy link
Owner Author

lopter commented Dec 28, 2015

Ok, here is how I get it:

SetPower is indeed SetPower and works in a boolean way.

However StatePower does uses the full 0-65535 range, and its value isn't related to the brightness or the power level, but is instead the transition: if I do SetPower with a 4s transition at t 0s StatePower will be 0 at t 2s StatePower will be 32767 and at t 4s StatePower will be 65535 not matter what the targeted brightness is.

So I'll keep doing what I was saying because it will naturally reflect the absolute brightness value as I'm already sampling the bulbs with Get.

@chendo
Copy link

chendo commented Dec 28, 2015

That'll work assuming that the user exclusively only uses lightsd for control. The HTTP API and the app does use SetPower with transitions where applicable as to preserve the brightness level before off.

@lopter
Copy link
Owner Author

lopter commented Dec 29, 2015

No worries, lightsd will implement it in a correct way, you can actually see my work in progress in the lightsd-mq repository.

@lopter lopter added this to the 1.3.0 milestone Jan 7, 2016
@lopter lopter self-assigned this Jan 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants