I have a simble switch and I want to be able to do stuff on both single and double clicks/tabs. I have the double click working, but when I try to do a single click it gets triggered on the first click of the double click - I can’t figure out how to avoid this
You can’t avoid it; your automation is designed to trigger for a single-click.
A “double-click” is just two consecutive single-clicks with less than a second between the two.
Your automation is designed to trigger on a single-click then wait (for up to 900ms) for another single-click. If the second single-click is not received within 900ms, then it wasn’t a double-click but simply a single-click.
You can determine if the wait_for_trigger detected the second single-click or timed out by checking the wait variable.
BTW, you should add the max_exceeded option to your automation like this:
Thanks for taking the time!
I’m not sure I understand - are you saying that it can not be done (period) or are you merely saying that with the code I provided it can not be done?
I can throw away the code and start over if there is another way.
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.
Thank you both for this example. @123 gave the solution on how to do it, but ultimately, I found the post with the full example clearer and directly usable as the solution.
It’s easy to support triple clicks and more with this method by just nesting the wait_for_trigger, I love it.
For future reference, the point of the Solution tag is to identify the response post that supplies the answer to the question/problem described in the topic’s first post. Only on very rare occasions does a topic author actually solve their own problem.
The solution is to check the wait variable. Without that concept, kaninfod’s automation would remain faulty. FWIW, I also made a second recommendation that kaninfod overlooked to implement in his post.
If every person asking a question always marked their own post as the Solution, it would appear that everyone ultimately solves their own problem (even if they didn’t think of the actual solution). That’s not how the Solution tag was meant to be used.
After 5 years of helping thousands of users, I have found that the majority comply with the guideline on their own or shortly after it’s purpose is explained to them. Only a small minority continue to misinterpret or ignore it. A very small number even abuse it by copying a suggested example verbatim just so they can mark their own post with the Solution tag.
I think you take it too personally, there’s clearly no harm here.
As you quote the guidelines, one could consider that you helped the author to find the solution by giving him/her pointers, but you did not provide the complete solution to the question of the topic. The precise answer is
- if:
- condition: template
value_template: "{{ wait.trigger == none }}"
then:
<< HERE GOES SINGLE CLICK ACTIONS >>
else:
<< HERE GOES DOUBLE CLICK ACTIONS >>
i.e., checking that the wait variable was “none”, so in that case, marking his/her answer as valid seems acceptable.
Kaninfod started this topic because he did not know how to solve the problem. He then used the suggested solution (check the state of the wait variable) so guideline 21 applies, not 19.
Kaninfod originally did mark my post with the Solution tag but then promptly switched it to his own post. I was curious to know why but he hasn’t replied despite the fact he is still actively reading and posting.
I abandoned this topic as a lost cause until you replied.
Adhering to the guidelines makes this community forum run smoothly. Complying with guideline 21 is a benefit to all users (not just the topic’s author or the person who devised the solution). In this particular case, the topic is short but others can be very long; identifying the correct Solution post saves time for other users searching for answers. Marking the correct post with the Solution tag is a good habit to develop.