michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
411 stars 114 forks source link

Create Alert effect for entertainment api #225

Closed TripleNico closed 3 years ago

TripleNico commented 3 years ago

In the Q42.HueApi.Streaming.Sample/HueStreaming.cs file you describe lots of awesome effects. But now i'm looking for a way to use the Alert effect that is available for the normal api in the entertainment api. How would one create such a effect?

michielpost commented 3 years ago

The normal api can't be used when the lights are in entertainment more. But of course you can recreate the the basic alert effect. I think the easiest way is to use the Flash effect: https://github.com/Q42/Q42.HueApi/blob/master/src/Q42.HueApi.Streaming/Effects/IteratorEffects.cs#L109

Also see: https://github.com/Q42/Q42.HueApi/blob/master/src/Q42.HueApi.Streaming.Sample/HueStreaming.cs#L201-L203 IteratorEffectMode should be changed to All if you want to flash all lights at the same time.

You can also have a look at HueLightDJ for more effects: https://github.com/michielpost/HueLightDJ

TripleNico commented 3 years ago

Thanks for the info! I think the fastest way to create an effect is to rebuild the Flash effect as you suggested. Is that something you already done but isn't in this library yet?

michielpost commented 3 years ago

You won't have to rebuild the Flash effect, you can just use it and modify the parameters to your needs.

If you want to create a new 'effect', so you can really use it in the entertainment layer's PlaceEffect, then have a look at the RedLightEffect You can modify it, give it a large radius so all lights are triggered by the effect. Then in the start methode, add a Task.Run, inside the Task.Run add a delay/Timeout and then turn the lights on and off. Also see the RandomPulseEffect

All the things I've build are in this library and https://github.com/michielpost/HueLightDJ

TripleNico commented 3 years ago

I'm not really familair with the code structure but i gues something like this can also be done:

` Await Task.Run(Async Function() While True

                                                   For i As Integer = 0 To 2
                                                       localHueBridge.entGroup.entBaseLayer.SetState(ct, trig.RGB, 0.2, trig.Priv_Duration, False)
                                                       Await Task.Delay(trig.Priv_Duration, ct)
                                                       localHueBridge.entGroup.entBaseLayer.SetState(ct, trig.RGB, trig.Brightness / 255, trig.Priv_Duration, False)
                                                       Await Task.Delay(trig.Priv_Duration, ct)
                                                       localHueBridge.entGroup.entBaseLayer.SetState(ct, trig.RGB, 0.2, trig.Priv_Duration, False)
                                                       Await Task.Delay(trig.Priv_Duration, ct)
                                                       localHueBridge.entGroup.entBaseLayer.SetState(ct, trig.RGB, trig.Brightness / 255, trig.Priv_Duration, False)
                                                   Next

                                                   Await Task.Delay(TimeSpan.FromMilliseconds(trig.Priv_Duration.TotalMilliseconds * 10), ct)
                                               End While
                                               Return True
                                           End Function)`

If you got some time left, would be great if you can add it to the effects 👍