I have a Lightify 4-Button controller and three lights in my living room. Here's what I want to do:
I want to long-press Button 1 to select a light (and maybe make it flash a specific colour once so I know it's selected). If I long-press and release, Light 1 should be selected. If I long-press and release again, Light 1 should be deselected and 2 should be selected, and so on...
Once a light is selected, long-pressing button 2 should increase the light's brightness & long-pressing button 3 should decrease the light's brightness.
Long-pressing button 4 should exit this process.
Is there any way I can set this up with rule machine?
I would setup a numeric global variable that is your 'last selected light'. Use the long press 1 as your trigger then conditionalize on your global variable.
If 'last selected' = 4 then
Set 'last selected' to 1
(do whatever you want to light 1)
Else if 'last selected' = 1 then
Set 'last selected' to 2
You can use this global variable in your other long press triggered rules, too.
I'm not sure I get the logic completely. I get how to program the selection process. I can use [SelectedLight] as a global variable and program a rule to increase it by 1 whenever Button 1 is pressed. What I don't understand how to do is the (do whatever you want to light 1) part.
Once I've set [SelectedLight] to 1 by holding Button 1, I want to increase the brightness of Light 1 by Holding button 2 and decrease the brightness by holding Button 3.
How do I program that part in? Would I need to create a separate increase/decrease brightness rule for every light I have?
My thinking (others may have a better solution) is that you will need multiple rules and the Global variable to keep track of the selected light.
Rule #1 'Light Selection' - Triggered on #1 Long press then follow my code above for the selection process, If you don't want to do anything to the light (like turn it on, etc) at this time then you can ignore the 'do whatever you want' comments.
Rule #2 - 'Increase Brightness' - Triggered on #2 Long Press then your code will need to use the Global variable to act upon the correct light, like so...
If 'Selected Light' = 1 then
(code to increase brightness on light #1)
Else If 'Selected Light = 2 then
(code to increase brightness on light #2)
Else if 'Selected Light' = 3 then
(code to increase brightness on light #3)
(code to increase brightness on light #4)
Rule #3 - 'Decrease Brightness' - Trigger on button #3 long press, use the same code as above but obviously decrease instead of increase brightness.
Hope that helps, good luck.
I set four rules up:
Show Selected Light flashes the light that's currently selected (based on the "SelectedLight" Global Variable)
I have a group for Bulb 1, 3, 4, and 6, but for some reason the capture and restore doesn't work with groups.
The Select Light rule increases the global variable by 1 and flashes the selected light:
Finally, there's the adjustment rules. One for increasing the brightness:
and one for reducing it:
The brightness reduction rule also checks if the light is switched on. If it's off, then it makes no sense reducing the brightness.
I can't think of a better way to implement this. If anyone here has any suggestions to clean this whole operation up, that'd be awesome.
Ideally, it would be amazing if I could create something like a look up table where I can specify
1 = Hanging Lamp
2 = Ceiling Lamp
and so on, so that I don't need to create multiple conditions in each rule.
This would also help with streamlining the brightness steps. If I could make a global variable called "BrightnessStep" and then use this in the rule to increase and decrease the brightness based on this variable, I woudn't need to edit multiple statements if I want to change the steps.
Great job, that looks pretty clean! I don't know how much more you could streamline it other than how you mentioned; with mapping the lights to a variable. I have not heard or have seen a way to do that. I think you should be able to use global variables for the step value though, create the variables then instead of putting 10 in the field use %GlobalBrightnessIncrease% (set to 10) or %GlobalBrightnessDecrease% (set to -10).
You'll see the discussion of the use of many simple rules vs. lesser more complex rules pop up from time to time here and it's a matter of preference. Since rules are free, my preference is many simple rules so what you have looks really good to me.
All righty, here's what I've done:
I set two numerical variables up
And added them to both rules:
Seems to be working.
Now I need to figure out if there's a way to do this for lights as well.
Old Setup that didn't work
I tried to set it up like this. I set up a variable:
But trying to use it in the rule doesn't work:
Glad you got it working. Usually the variable approach works wherever a value is needed. Assuming no typos I'd have to defer to Bruce, the RM master, to see why this specific use case is not working,