Button Control Lamp Dimmer


#1

I replaced a couple smart plugs with smart bulbs in a couple of my lamps, but I still wanted to be able to dim my lamps.

This first piston will control a dimmable smart bulb and progress through three different definable steps with every push of a button: low, medium, high, and off

Then I expanded on this idea to to progress from low to high, then back down to low and then off.

Replace the “lamp” variable your bulb of choice and the “button” variable with your control button. You may have to edit the code to turn off the bulb after the 0% set level, but setting the level to 0% works for me and eliminates a flash when the bulb turns back on. If you get a flash, leave the set level 0% and add a turn off command after it. :+1:

Both pistons should work even if you turn on one of these using another method (app, Google Home, Alexa, etc) or set the dimmer level to something other than what’s defined at the top.

I’m sure I’m not the only one that has done something like this, but I don’t often see ‘simple’ examples like this, so I thought I’d share. :slight_smile:


#2

Thank you for this. Is this to be used with a 1 button device? Do you press each time to go to the next level or keep the button held?


#3

Yes, it’s meant for one button. I don’t have a button that has double press or hold yet. It shouldn’t be too hard to modify this though.