Shift light hue from a rule

rule_machine

#1

I wanted to setup a Mi Cube Controller to adjust RGB LED hue on cube rotation, however in Rule Machine 4.0 actions i could not find a way to change hue. I wanted to have something like:

  • Rotate cube right -> rotate hue by 20 degrees
  • Rotate cube left -> rotate hue by -20 degrees

Is in possible with the Rule Machine? Are there any alternatives?


#2

The best thing to do if to post questions about custom drivers directly in the thread where the driver is released. That gives the best chance that the driver author will see it. This driver is by @bptworld. Hopefully he can answer your question.


#3

To clarify: the Cube driver does fire the events I need and the light switches driver allows to set color/hue. What I am missing is ability to wire the two together in a rule. There’s no action to be able to shift hue - I can only set a color.


#4

No, there is no stock command to shift the hue. Why not simply set it to the new color that you want. What are you trying to do? Are you trying to cycle colors? I'm not quite sure I understand what your're trying to do. Hue doesn't work like dimmer level where you can ramp from one to the other while holding a button. It doesn't work that way.


#5

What I'm trying to setup is ability to adjust RGB LED strip color using rotation gesture of the Mi Cube Controller as if rotating the color wheel:

mi-cube-rotate circle

The Mi Cube Controller supports rotation events, sending degrees rotated.
So for example if LED color is currently yellow and I rotate the cube clockwise the color starts to gradually change to green, blue, etc.
I stop rotating and the selected LED color remains.
If from yellow i rotate counter-clockwise the color changes to orage, red, etc.

Does it make sense?


#6

Yes. But as I understand it, there is no function built into HE like the one you speak of. But there's no reason you couldn't build one. First, how is the rotation of the mi cube expressed in Hubitat? Does it read out in a custom attribute? Or dimmer level? Trying to understand how you'd start to translate it.


#7

It has a custom attribute angle. Here is a snapshot of the state which lists all cube's attributes:

cube-states

What options do I have to build what I want? I only had a couple of attempts and writing custom code for Hubitat (drivers), so not sure how much i don't know.

I'm guessing I could do one of the following:

  • Write a custom app (or extend existing Magic Cube app by @bptworld)
  • Create a virtual device with a custom driver to convert cube's angle to dimmer level and then use it in Rule Engine.

Any other ways? What would be the easiest and/or quickest path to get where i want?


#8

Have you tried to use the "Custom Attribute" in RM4 as a trigger event? You can then trigger based on the angle value being changed and in your rule could perform actions based on the angle value.

I would still recommend to use @bptworld Magic Cube app though. It brings quite a few benefits like debouncing. The latest version allows you to run rule actions for the different movements. While not the most elegant solution, you could create rules that have only actions that you link in the app for the different movements


#9

Okay, so, you know the angle, but does it only give you an absolute angle or does it give you a delta value (how much the angle has changed)? You can definitely do this in rule machine using variable math but it's going to be different depending on whether we have to determine the delta value ourselves. I'll assume that the angle is just an absolute number and we won't know what the delta is.

First thing you are going to want to do in your rule is set up some number variables. You're going to need:
old_angle
new_angle
angle_delta
old_hue
new_hue

The trigger for your rule is going to be Custom Attribute and then get to the Mi Cube and pick the angle attribute and then "Changed".

In the action of your rule, the first step is to store the angle in new_angle and set the hue equal to old_hue. Then you want to do variable math. Each of this functions will have to be a different line in your action.
angle_delta set to new_angle minus old_angle
new_hue set to old_hue plus angle_delta
then an if statement that if new_hue >360
more variable math to subtract the constant 360 from new_hue

Then set the hue equal to new_hue and set old_angle equal to new_angle to store it for the next time.

This also assumes you're hue is defined as being 360 and not 100. If you're using 0-100 for your hue for this device, you'll have to do more variable math on new_hue before setting the device to that hue by dividing by the constant 3.6 and then more variable math to round to the nearest integer, since hue can't be a decimal I don't believe.

Were you able to follow all that? I know it's only in the broad strokes but it should work.


#10

That’s perfect, this is the level of detail I needed. Thank you.
I do get the delta angle from cube so the setup of the rules will be a bit easier.
Will give this a try in the next few days and report.


#11

But does it give it to you in + and - or just a raw number? You still may have to keep track of that or the direction it's rotated if that is given. I'll be curious to see how well this works and how quickly the Mi Cube reports back. I'm suspecting that it won't report back until you stop spinning it. So, instead of changing with you while you are rotating the cube it will most likely jump to the new setting once you stop moving. But hey, maybe it's better than I think. Only time will tell. Definitely report back how it goes!


#12

Yay, It works!

Yes, that's what's happening. It's a bit slow to respond, however it does what I wanted. There's about a second delay after rotation and the fired event plus one second for the color transition on the LED strip.

Here's the rule I've setup:

it already gives a delta with a direction.
Thanks for your assistance, it helped a lot!


#13

Sweet!! That's awesome.


#14

Here’s a quick demo of the end result: https://youtu.be/pvhKEa2dvwM


#15

That is VERY cool! They look really great!
I was in the middle of a project to add biased lighting under my couch like that as well. I was using a DIY solution with ESP8266 boards. Had the LEDs bought and the boards programmed ready to go. It wasn't till I tried them out that I realized that my damn couch is too low to the floor to make it look like anything. I only have about 1.5" of clearance, so it wasn't going to be worth it. So, I've re-purposed the LEDs for a Hyperion project for the living room instead.


#16

Hmm, i was going to put LEDs under a bed, but the clearance even smaller, so i'll give up this idea. Thanks for saving me time on this :slight_smile:

Very cool, I was also wondering about ambient lighting for my TV, so this would be a good start for me.