Is this possible? “Adaptive automation”

Hi everyone,

I’m looking for an “adaptive” automation:

I have a button with only 2 actions:

  • click
  • hold

I want following automation:

  • click: toggle light
  • hold: increase brightness
  • release + hold within 1sec: decrease brightness
  • release + hold within 1 sec: increase colortemp
  • release + hold within 1 sec: decrease colortemp
  • etc …

So the trick is that the “hold” action depends on the previous action and the fact that the “hold” action is triggered within one second after a “click” or another “hold”

I think I need some helpers:

  • a timer to detect the “1 second”
  • a toggle that defines the active action

Is this possible?
Can somebody provide me with a sample code?

Thanx!
Bart

Example of detecting a Hue dimmer switch’s ‘long_release’ event immediately after an ‘initial_press’ event.

The automation listens for ‘initial_press’ event then uses a wait_for_trigger to listen for a 'long_release` event (but it doesn’t wait for longer than 2 seconds).

alias: example 
trigger:
  - platform: event
    event_type: hue_event
    event_data:
      id: 'your_dimmer_switch_button'
      type: 'initial_press'
      subtype: 4
condition: []
action:
  - wait_for_trigger:
      - platform: event
        event_type: hue_event
        event_data:
          id: '{{ trigger.event.data.id }}'
          type: 'long_release'
          subtype: 4
    timeout: '00:00:02'
    continue_on_timeout: false
  - service: script.turn_on
    target:
      entity_id: script.whatever

hi @123 ,
thanx for this sample!

But…
the script will be triggerd if you have a long_release within 2 secs after a initial_press, right?

what I want to achieve is

  • immediate action on “long press” (brightness up)
  • and the kind of action will change if this “long press” is initiated within a period of 1 second after another action (brightness down, colortemp up/down, hue up/down, …)

In fact I want to imitate the default behavior of a single butoon you can find in a lot of meeting rooms, f and where you can toggle light and dim up/down with only two actions: click and hold

What you want is achievable using the techniques employed in the example I provided.