Dim an RGB bulb with a simple button?

Hi guys,

The challenge is to use a simple button with one push, double tapped and held functions to be able to dim a RGB zigbee bulb up and down manually and not to a certain level.
For instance :
If it could be possible, one possibility would be to press and hold a button and bulb starts to dim up until it's released, press and hold again and it starts to dim down until it's released, alternately.

Would it be possible ?
Are there other ways to achieve this task ?


1 Like

yes i currently do this for each of my rooms, it's not "easy peasy" but if you follow my rule its not hard.

1 Like

obviously you don't need the party bit or the blind bit

This depends on your button. What events (if any) does it send when you hold and release it? You didn't mention released events in your post, so I'm wondering. The SmartThings Button (2018), for example, sends pushed, doubleTapped, and held, but it does not send a released event after a hold (or push). If your button also doesn't do that, there wouldn't be a way for Hubitat to know when the button is released, so the "dim while holding" idea--as above--won't work. There are workarounds you could use if you don't find them awkward (e.g., start dimming on first push, stop on second ... or use a button device that does :slight_smile: ).

Some of this also depends on your lights. To get smooth dimming up/down, you'll want to make sure they have the "Start Level Change" and "Stop Level Change" commands implemented (check the device page to be sure). Otherwise, if your bulb doesn't support these (most Zigbee bulbs do) or your device doesn't do released, you can still dim up/down, just by a specific amount/step each time. If you use the "Adjust..." actions in RM instead of the "Set..." actions, you can bump the level up/down by some amount relative to its current level.


If you want to do pushed to start, pushed to stop, you would have to do something like this:

Trigger:  Button 1 Pushed


IF Variable Moving = False THEN
     IF Dimmer level of light is < 50 THEN
          Start Raising Dimmer Level
          Start Lowering Dimmer Level
     Set Moving to True
     Stop changing Dimmer level
     Set Moving to False

The only caveat is that your button has to have a good response time. There are buttons out there, the Iris button comes to mind, that are very sleepy to save power and take a LONG time to react. While these are great to trigger scenes or individual actions, they would suck trying to do something like this.

1 Like

Thanks @BorrisTheCat @Ryan780 and @bertabcd1234

@bertabcd1234 yes I have a button that returns released event.

@Ryan780 and @BorrisTheCat to use your also good solutions I have to create variables, right ?
Is there any tutorial for RM 4 ? As I'm not a programmer and have very little knowledge of programming I need to learn from scratch.

Well, you only need a variable if your button doesn't support release. If it does, you can do things many different ways, I prefer to do it this way.

Set up a local string variable called "direction" and set it to the string "up". Then set up your rule as follows:

Trigger:  Button Device

Action for Button 1 Pressed:
    IF direction = "up" THEN
        Start Raising Dimmer Level
        Start Lowering Dimmer Level

Action for Button 1 Released
    Stop Changing Dimmer Level
    IF Dimmer level of Light is <5 or Light is off
        Set Variable direction to up
    ELSE-IF Dimmer level of Light is > 95 THEN
        Set Variable direction to down

That will keep the direction of the dimmer going in the same way until you reach the top or the bottom. You can see how to set up a local variable right in the rule machine tutorial. But the button is right there on the page when you create a rule.

But the question is, does your button also support hold? If so,m then you would want to change the first part of the rule to the action when button is HELD. Otherwise, it won't work.

Thanks @Ryan780,

It works but dims goes up and down too fast that I don't even have time to release button. Button supports hold.
I would like it to go gradually so I can adjust bulb's illuminance.
And I also would like rule to alternate up and down every time button is released.
I noticed that there is a fade over time option, but it only allows time in minutes, which I find it's too long.

My rule does this. Use bool variable and flip it on each release.

You could do adjust by % and have a repeat. It makes it more complex though. I would try the above 1st.

1 Like

I need to push (and hold in this case) button twice for rule to run. Does anyone knows why ?

Remove the OFF bit and just do what it says in my rule the release bit.

What type of device are we talking about?

It is an aqara button and a Gledopto RGB bulb

#Aliexpress R$ 137,69 51%OFF | GLEDOPTO LED ZIGBEE 12W RGB+CCT LED bulb AC100-240V RGBCCT dual white Smart LED bulb dimmable lamp work with alexa many gateways

#Aliexpress R$ 55,83 24%OFF | Xiaomi Mijia Aqara Smart Wireless Switch Smart Remote One Key Control Aqara Intelligent Application Home Security APP Control

It's working great now.
But still bulb raises and lower too fast.

Is there a way to make it slower ?
Fade over time doesn't accept seconds.

I would add the delay bit that makes it so that when you start again it always goes up 1st. You also want to change the variable to a boolean rather than a string that will make it easier.


not like this, no. Once i get on ill paste a rule that is similar that would do it.

So, there was a new function added to a recent Zigbee driver, the RGBGenie Zigbee micro dimmer, that allows you to change the speed at which the startLevelChange command transitions. This isn't a function unique to that device but is a standard zigbee functionality. There has been discussion about expanding that function to other drivers as well. So, hopefully, @mike.maxwell has decided that it's a good idea and is going to do it for the other zigbee dimmer drivers. :crossed_fingers:

I don't understand what is going on in your released part of the rule.

You are changing the direction when you let go of the button for 5 seconds. That is one way to do it. mIne simply waits till you get to the top or the bottom of the dimmer range to change direction, the same way that a device with only a momentary button, like the some of the micro dimmers recently released, works. They go in one direction till they reach the end of the dimming range, then change direction. I think that is a lot easier method than having to re-hold the button in 5 seconds. One isn't more right than the other. But that will not affect the transition time. That is in the startLevelChange command.

The off bit you talk about is to catch if the dimmer dims all the way down to the light being off. If you Don't check for that, the dimmer will go to off and the direction of fade will still be down. Trust me on this one.

What do you mean by you have to do it twice? The first time you hold the button nothing happens? What is the starting state of the light? The issue is going to be that if you have dimmed the light all the way down, so the direction gets changed to up, then set the light to 100%, the direction is going to still be up till you hold the button. To address this, you would have to have two rules and the variable will have to be change to a global one. You would remove everything else from the released part of the rule except for the stop level change. Then you would add a second rule as follows:

Trigger:  Switch changing on the light  OR dimmer level of the light changing

IF Light is off or Dimmer level is <5 THEN
     Set direction to up
ELSE IF Dimmer level >90 THEN
     Set direction to Up

Now, there are still limitations with this. If you want to dim till you hit the end of the range and not change direction when you don't repress the button, then these are limitations you are going to have to live with. Most noteably, if the direction is up, because the light was previously going up or was off and you set the light to a level of 88, it will still brighten when you hold the button rather than dimming. Similarly if you are dimming the light and then you set the light to 10, it is still going to dim when you hold the button. This is what happens when you try to use a button to do the job of 2 buttons.

If this doesn't work for you, buy a different button controller. One designed for dimming.

I see what you mean. Actually I don't have a specific button for this purpose, do you recommend any ? But I'm ok with those limitations at the moment.

Guys, setting dim to zero is the same as turning bulb off ? I mean, if I set bulb dimmer to zero RM will assume it's off ?

No, the light will turn off but the dimmer level will still be whatever dimmer level the bulb was at when you began dimming.

Let me see if I can explain this better....this is what happens when you issue a startLevelChange command.

You tell hubitat to start raising your dimmer level. Hubitat in turn send a command to the light to start changing it's level up. It doesn't case what the current level of the light is. The light, in turns, begins brightening. Then, when you tell hubitat to stop changing the level of that light, Hubitat tells that light to stop changing its level, so the light does. THEN the light reports it's final dimming level to the hub. The bulb does NOT report it's dimming level until AFTER you stop changing it. If the light were to report back ever single level in between where you start and where you end, the network would be flooded with messages and the hub wouldn't be able to handle it. Plus, the hub doesn't care about all those intermediate levels. Just where the bulb finished.

So, when you are at 100% and issue a startLevelChange down command and you let the light go all the way to OFF. That light, in hubitat will read as being off with a dimmer level of 100. That is why I had checks in that rule to look for the light off or the dimmer level low. The light will never be at a dimmer level of 0. Ordering a level of 0 turns the switch component of the light off, which is all that really matters. The level attribute doesn't mean anything because the switch is off.

Does that make sense?

1 Like

This was also what the OP asked for.

I wrote mine like i did because that's how we do it professionally, all commercial products work this way and there is no choice in it. At least in HE you can choose what you want, to your own preference :+1:

correct that's the next thing they asked for i have another rule that can get over this

this is what the delay catches. The idea is that while you are dimming up and down its constantly canceling the delay, but after you have finished after 5 seconds it "resets it". This is so that it is always insync and always starts off in the same direction.

Also that's not needed on my setup because of the pressed bit, if it goes so low to off i just tap it again :slight_smile:.

my button is the fibaro dimmer 2 S2 input.

ensentaly this "should" do it to replace the raising or lower command and instead of raise volume you would have

or -5