Automation to dim lights whilst putton is pressed

I have a Xiaomi button that sends an event when you hold the button down, and another one when you release the button. I’d like to use this to gradually dim or brighten the lights when I phold the button down, until such time that I release the button, and then the light stay at the brightness they were at upon release. Does anyone else do anything like this or have any suitable ideas?

I do not use node red or anything like that, preferring to code everything in YAML, though I would be willing to reconsider if it’s not possible in YAML.

Just an idea, probably there is a more sophisticated way.

Use the button event and brightness change as trigger. Check with condition that button is pressed. Change the brightness setting. And have a small delay in between to see when brightness is ok.

The condition is important or it wont stop triggering to brightness change.

Never got it working myself, but might be worth a look.
I’ve tried multiple attempts to get something smooth working in NodeRed but never got anything I was satisfied with.

im after doing something similar with 2 button wherby it sends IR packets to my broadlink RM Mini, for volume up and down on an old amplifier. Outcome wanting to have a smooth volume change like brightness/dimming control. I was hoping to use and ESP chip

1 Like

Thank you ewveryone for the replies - the answer posted by swifty looks like exactly what I need. Will give it a go this week.