Matt49
August 21, 2024, 4:43am
1
I have tried many ways, but they all result in the previous actions running too. I only want the action to run for how many clicks I push the button. For example, if I push the button 3 times, I only want the third action to run, not the first and second.
Thanks
i presume it’s 3 times in a short time period? ie, if i press the button 3 times but 1 minute apart, those should run the first action each time?
Matt49
August 21, 2024, 3:58pm
3
Yes, for example I could press the button 3 times quickly.
something like this perhaps?
what this does is that it triggers on the event (i’ve used state change for button.your_button, but you should replace this with whatever your real event is that you get on the button click.
then it waits_for_trigger on another press. i have it set to wait 5 seconds. if a second press does not happen (so there’s no wait.trigger), then do action 1. if a second press does happen, then wait_for_trigger looking for the 3rd press. if that third press does not happen w/in 5 seconds, then do action 2. if it does happen, then don’t do action 2, and do action 3 instead…
adjust the 5 seconds as you please to determine how you define “quickly”
alias: test wait_for_trigger
description: ""
trigger:
- platform: state
entity_id:
- button.your_button
condition: []
action:
- wait_for_trigger:
- platform: state
entity_id:
- button.your_button
timeout:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- if:
- condition: template
value_template: "{{ not wait.trigger }} "
then:
- action: light.action_1
target:
entity_id: light.whatever
data: {}
else:
- wait_for_trigger:
- platform: state
entity_id:
- button.your_button
timeout:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- if:
- condition: template
value_template: "{{ not wait.trigger }} "
then:
- action: light.action_2
target:
entity_id: light.whatever
data: {}
else:
- action: light.action_3
target:
entity_id: light.whatever
data: {}
mode: single
Matt49
August 22, 2024, 12:45am
5
Thank you very much, this is what I want. However, could you please tell me how to add more pushes? I would probably like at least 8
Matt49
August 22, 2024, 1:04am
6
Never mind, for anybody wondering here it is.
alias: test wait_for_trigger
description: ""
trigger:
- platform: state
entity_id:
- input_button.test_multi
to: null
condition: []
action:
- wait_for_trigger:
- platform: state
entity_id:
- input_button.test_multi
to: null
timeout:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- if:
- condition: template
value_template: "{{ not wait.trigger }}"
then:
- data:
message: action 1
action: notify.mobile_app_matts_iphone
else:
- wait_for_trigger:
- platform: state
entity_id:
- input_button.test_multi
to: null
timeout:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- if:
- condition: template
value_template: "{{ not wait.trigger }}"
then:
- data:
message: action 2
action: notify.mobile_app_matts_iphone
else:
- wait_for_trigger:
- platform: state
entity_id:
- input_button.test_multi
to: null
timeout:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- if:
- condition: template
value_template: "{{ not wait.trigger }}"
then:
- data:
message: action 3
action: notify.mobile_app_matts_iphone
else:
- wait_for_trigger:
- platform: state
entity_id:
- input_button.test_multi
to: null
timeout:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- if:
- condition: template
value_template: "{{ not wait.trigger }}"
then:
- data:
message: action 4
action: notify.mobile_app_matts_iphone
else:
- wait_for_trigger:
- platform: state
entity_id:
- input_button.test_multi
to: null
timeout:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- if:
- condition: template
value_template: "{{ not wait.trigger }}"
then:
- data:
message: action 5
action: notify.mobile_app_matts_iphone
else:
- wait_for_trigger:
- platform: state
entity_id:
- input_button.test_multi
to: null
timeout:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- if:
- condition: template
value_template: "{{ not wait.trigger }}"
then:
- data:
message: action 6
action: notify.mobile_app_matts_iphone
else:
- wait_for_trigger:
- platform: state
entity_id:
- input_button.test_multi
to: null
timeout:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- if:
- condition: template
value_template: "{{ not wait.trigger }}"
then:
- data:
message: action 7
action: notify.mobile_app_matts_iphone
else:
- wait_for_trigger:
- platform: state
entity_id:
- input_button.test_multi
to: null
timeout:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- if:
- condition: template
value_template: "{{ not wait.trigger }}"
then:
- data:
message: action 8
action: notify.mobile_app_matts_iphone
else:
- data:
message: action default
action: notify.mobile_app_matts_iphone
mode: single
yup, you could just repeat the pattern i gave an arbitrary number of times.
however if you’re going to do a large number, it’d probably have greater code beauty to do a loop and do a condition on the repeat index…
however what you’ve got works.
something like this:
description: ""
mode: single
trigger: []
condition: []
action:
- repeat:
count: 8
sequence:
- wait_for_trigger:
- platform: state
entity_id:
- input_button.test_button
timeout:
seconds: 2
- if:
- condition: template
value_template: "{{ not wait.trigger }} "
then:
- choose:
- conditions:
- condition: template
value_template: "{{ repeat.index == 1 }} "
sequence:
- action: switch.action_1
- conditions:
- condition: template
value_template: "{{ repeat.index == 2 }} "
sequence:
- action: switch.action_2
- conditions:
- condition: template
value_template: "{{ repeat.index == 3 }} "
sequence:
- action: switch.action_3
- conditions:
- condition: template
value_template: "{{ repeat.index == 4 }} "
sequence:
- action: switch.action_4
- conditions:
- condition: template
value_template: "{{ repeat.index == 5 }} "
sequence:
- action: switch.action_5
- conditions:
- condition: template
value_template: "{{ repeat.index == 6 }} "
sequence:
- action: switch.action_6
- conditions:
- condition: template
value_template: "{{ repeat.index == 7 }} "
sequence:
- action: switch.action_7
- conditions:
- condition: template
value_template: "{{ repeat.index == 8 }} "
sequence:
- action: switch.action_8
- stop: ""
caveat, i haven’t tested this, just giving the concept framework… the notion here is that it’s a loop, and in each loop it waits for the button to be pressed, if it is not pressed, then it will pick the action to take based on how many times (repeat.index) it has looped. if it is pressed, it will cycle through and wait again (and the loop will increment the repeat.index)
What hardware is the button? (the below option may be supported)
Take a look at Switch Manager as this makes things super easy.
Matt49
August 23, 2024, 4:51pm
9
Thank you very much, this did work.