Just add a wait_for_trigger after each section with a timeout. It will wait for up to ‘timeout’ for the trigger to happen. If it doesn’t happen within timeout, it will stop the whole automation.
- alias: Heike Lampe schwach ein
trigger:
platform: state
entity_id: binary_sensor.esp_heike_bett_taster_schwarz
to: 'on'
condition:
- condition: state
entity_id: light.bf33
state: 'off'
action:
- service: scene.turn_on
entity_id: scene.heike_weiss_schwach_an
- service: input_boolean.turn_on
data:
entity_id: input_boolean.heike_bett_weiss_schwach
- wait_for_trigger:
platform: state
entity_id: binary_sensor.esp_heike_bett_taster_schwarz
to: 'on'
timeout: "00:00:03"
continue_on_timeout: false
- service: "< degrace light >"
- wait_for_trigger:
platform: state
entity_id: binary_sensor.esp_heike_bett_taster_schwarz
to: 'on'
timeout: "00:00:03"
Only issue is it will restart after each press.
Edit - oh, I misread. I thought you wanted to emulate double or triple click. This doesn’t make sense if you didn’t want that lol.
Every button press goes to the next speed. You can easily modify it to set a light brightness based on the current state/brightness attribute of the light:
- alias: Turn MBR Fan On With Scene Switch
trigger:
- platform: event
event_type: zwave.scene_activated
event_data:
entity_id: zwave.mbr_scene_switch
node_id: 35
scene_id: 1
scene_data: 0
action:
- service: fan.set_speed
data_template:
entity_id: fan.master_bedroom_fan
speed: >-
{% if states('fan.master_bedroom_fan') == 'off' %}
low
{% elif states('fan.master_bedroom_fan') == 'on' and state_attr('fan.master_bedroom_fan', 'speed') == 'low' %}
medium
{% elif states('fan.master_bedroom_fan') == 'on' and state_attr('fan.master_bedroom_fan', 'speed') == 'medium' %}
high
{% elif states('fan.master_bedroom_fan') == 'on' and state_attr('fan.master_bedroom_fan', 'speed') == 'high' %}
'off'
{% endif %}
You could just have 2 automations with the trigger look for ‘on’ for ‘X’ seconds. But, there is a chance both will fire if you weren’t careful enough.
Could do it in a single automation…trigger on the on state, then wait for the off state.
- alias: Heike Lampe schwach ein
variables:
short_press_s: 0.9
on_time: "{{ as_timestamp(now()) }}"
trigger:
platform: state
entity_id: binary_sensor.esp_heike_bett_taster_schwarz
to: 'on'
action:
- wait_for_trigger:
platform: state
entity_id: binary_sensor.esp_heike_bett_taster_schwarz
to: 'off'
- variables:
# Calculate how many seconds the button was pressed
press_time_s: "{{ as_timestamp(now()) - (on_time | float) }}"
- choose:
conditions:
condition: template
value_template: "{{ press_time_s | float < short_press_s | float}}"
sequence:
- service: "<< do something on short press >>"
- choose:
conditions:
condition: template
value_template: "{{ press_time_s | float >= short_press_s | float }}"
sequence:
- service: "<< do something on long press >>"
Considerations:
I’m not sure how precise the timing will be on an automation firing. You have to consider the latency of releasing the button, state updating in home assistant, and HA firing this automation. And, this latency could be variable depending on many different factors…
The real solution would be to implement the long press in the ESP button itself and have it send events rather than be a binary_switch.