One-button reusable automation. Best practice?

Hi,

I’m looking for a good example of a basic automation for a button and light.
The button only has 2 actions: “single click” and “long click”

This is what I want to happen:

  • single click: toggle light
  • long click: increase brightness
  • release: stop increase brightness
  • if a long click is immediatly (within 2 seconds) followed by another long click, the “increase brightness” becomes “decrease brightness” (and vice versa)

I suppose I need to define some extra entities (a timer to define if there is a long click within 2 seconds after another long click, and a “direction” parameter wether the brightness has to increase or decrease)

This behaviour should simulate the “normal” behaviour of an old school (wired) button in some offices where you can manipulate on/off and brightness with just one button.

Question:

  • does anybody have already implemented this automation? Can you share that example?
  • can this automation be “saved” and reused on other button/lights? Is it done with a “blueprint”? (never worked with this)

any help is appreciated,
kind regards,
Bart