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

Question: Fade In/Out 6 Lights #373

Closed
RGSMA opened this issue Aug 24, 2018 · 8 comments
Closed

Question: Fade In/Out 6 Lights #373

RGSMA opened this issue Aug 24, 2018 · 8 comments
Labels

Comments

@RGSMA
Copy link

RGSMA commented Aug 24, 2018

Hello and sorry if I didn't search enough to answer this question. I read closed issue #131 which helped quite a bit.

I have both your plugin running via Homebridge on a RPi as well as a 2nd generation Hue Bridge. I have 6 hue color bulbs in a straight line. I am trying to have all bulbs start at the same color 0% brightness, then the outer most 2 bulbs transition to 100% and fade down to 0%, followed by the next inner most 2 bulbs that transition to 100% and down to 0%, and finally the last 2 (and then repeat). Your plugin is fantastic for controlling individual bulbs in a group for this purpose. I'm just trying to figure out the most efficient way to accomplish this task. I will probably use the Eve app to create my scenes with transition times but since you are very knowledgable with regards to Hue, I'm wondering if you have any thoughts on the best way to accomplish this. Thanks in advance.

@ebaauw
Copy link
Owner

ebaauw commented Aug 25, 2018

Sure, you could create HomeKit scenes for each of your transitions. If you create them in Eve, you can include Transitiontime. Once created, you can recall the scene from any HomeKit app (or automation).

Controlling two lights simultaneously from a HomeKit scene will probably look OK, setting six lights, you might experience that not all lights seem to change at the same time. To overcome this, create groups on your Hue bridge or deCONZ gateway, and expose these groups to HomeKit (as Lightbulbs), and use those instead of the lights in the HomeKit scenes.

I'm not sure you'd be able to automate recalling the scenes at the appropriate timing in a loop from HomeKit. Depending on your use case, I would either write a simple bash script, like:

#!/bin/bash

# Groups
group_all=1
group_outer=2
group_middle=3
group_inner=4

# Transition time in seconds
transition=10

# Transitiontime in 0.1 secons
transitiontime=$((transition * 10))

ph put /groups/${group_all}/action '{"on": true, "bri": 1, "xy": [0.5, 0.5]}'
while true ; do
  ph put /groups/${group_outer}/action "{\"bri\":254, \"transistiontime\": ${transitiontime}}'
  sleep ${transition}
  ph put /groups/${group_outer}/action "{\"bri\":1, \"transistiontime\": ${transitiontime}}'
  sleep ${transition}
  ph put /groups/${group_middle}/action "{\"bri\":254, \"transistiontime\": ${transitiontime}}'
  sleep ${transition}
  ph put /groups/${group_middle}/action "{\"bri\":1, \"transistiontime\": ${transitiontime}}'
  sleep ${transition}
  ph put /groups/${group_inner}/action "{\"bri\":254, \"transistiontime\": ${transitiontime}}'
  sleep ${transition}
  ph put /groups/${group_inner}/action "{\"bri\":1, \"transistiontime\": ${transitiontime}}'
  sleep ${transition}
done

This script would run on your Raspberry (where deCONZ is running as well). To start or stop the sequence, you would have start of kill this script. Not very nice, but sufficient for a one-time use like a party (I used something like this during Xmas to alternate my lights between red and green - ho ho ho).

For full control from HomeKit, program the sequence in Hue bridge or deCONZ gateway rules:

  • Create a CLIPGenericFlag to trigger the sequence. Expose this to HomeKit, so you can enable/disable it from HomeKit as well;
  • Create a rule that initialises all lights when the flag is set from false to true (state.flag eq true and state.flag dx - note the subtle use of state.flag for dx instead of state.lastupdated);
  • Create a rule that starts the first transition a second later (state.flag eq true and state.lastupdated ddx PT00:00:01);
  • Create five more rules that start the subsequent transitions at the appropriate time (state.flag eq true and state.lastupdated ddx PT00:01:01, ..., PT00:05:01);
  • Create a seventh rule to set state.flag to true, so state.lastupdated is set and the ddx conditions will re-apply. This rule fires after the last transition has finished (state.flag eq true and state.lastupdated ddx PT00:06:00)
  • Create a final rule to turn the lights off, when state.flag is set to false (state.flag eq false and state.lastupdated dx)

There's no graphic environment to maintain bridge/gateway rules. I use bash scripts calling ph to create and maintain my rules (basically deleting and re-creating all 236 rules on my deCONZ gateway). See also https://github.com/ebaauw/ph.sh.

@RGSMA
Copy link
Author

RGSMA commented Aug 26, 2018

Thanks for the code, Erik. I'm not currently running deCONZ gateway; I use a hardware Hue Bridge as well as your plugin. Is deCONZ gateway pretty easy to configure?

@ebaauw
Copy link
Owner

ebaauw commented Aug 26, 2018

The API is very similar to the Hue API. It comes with a web app.

You could run the script on any unix-like system, where you also run homebridge.

@RGSMA
Copy link
Author

RGSMA commented Aug 27, 2018

I will give deCONZ gateway a shot. Thanks again for a fantastic plugin!

@ebaauw ebaauw closed this as completed Sep 2, 2018
@fezzz
Copy link

fezzz commented May 26, 2019

Hi @ebaauw, I created a scene in deconz that includes a 10min transition for a lights-group. Starting it from there, it's exactly what I want. Is there a way to expose this scene to homebridge similar to the "groups"? I didn't figure out, yet, how to trigger it with a time-based rule from homekit.
Thanks, felix

@fezzz
Copy link

fezzz commented May 26, 2019

fyi. for a quick workaround I'm calling the api "curl -i -X PUT http://192.168.x.x/api/xxxxx/groups/5/scenes/1/recall" using the homebridge-script2 plugin

@ebaauw
Copy link
Owner

ebaauw commented May 26, 2019

homebridge-hue doesn't expose bridge/gateway scenes to HomeKit. As a workaround, I create a CLIPGenericFlag sensor, which homebridge-hue exposes as a Switch to HomeKit. On the bridge/gateway, I create a rule to recall the "on" scene when the flag is set and another one to recall the "off" scene when the flag is cleared.

To trigger timed transitions from HomeKit, include the custom Transition Time characteristic in the HomeKit scene. This is in the service homebridge-hue creates for the bridge/gateway. Apple's Home app doesn't support this, so you need to create the scene in Eve or another HomeKit app. After that, you can recall it alright from Apple's Home app.

I suppose I could try and expose scenes to HomeKit. They would be mapped to Switch, which would revert automatically to Off after the scene has been recalled (cf. the Volume Change characteristic in homebridge-zp). Currently, neither the Hue nor deCONZ API reports whether a scene is still active, and there's no way to un-recall a scene.

Note however, that every other Hue app tends to create a lot of scenes, so this could lead to a lot of switches. I could try and expose the scenes as additional services to the group, to limit the number of accessories created, but then the scenes are bound to the same HomeKit room as the group. This might work well for deCONZ, where scenes are created under a group, but not for Hue, where all scenes are stored under /groups/0.

@fezzz
Copy link

fezzz commented May 26, 2019

thank you for your detailed answer! Maybe a whitelist in the config section could only allow certain scenes to be exposed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants