found a solution: a trigger on the first state change, a delay of 500ms and then a check of the state change again. I used this to increase the brightness of a smart lightbulb stepwise when rapidly changing a smart wall switch from on to off back to on.
trigger:
- platform: state
entity_id: light.office
to: 'off'
from: 'on'
action:
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- condition: state
entity_id: light.office
state: 'on'
- service: light.turn_on
data_template:
transition: '1'
entity_id: light.office
brightness: "{% set n = states.light.office.attributes.brightness\
\ %} {% if n < 85 %}\n 85\n{% elif n < 170 %}\n 170\n{% elif n < 254 %}\n\
\ 254\n{% else %}\n 1\n{% endif %}\n"
on double toggle, it increases the brightness in steps of 33% and when triggered at full brightness it goes back to the lowest brightness.