New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E1812 Debouncing and optimized double press routine. #32
Conversation
Hi @vandalon, thank you for the contribution. :) I've just tested this version of the blueprint. IKEA E1812 with ZHA, so we have a quite similar setup. Unfortunately I don't get a consistent behaviour across multiple runs: sometimes debouncing works and a single short press is triggered, sometimes the automation runs multiple times. Increasing the value of |
Hmmm, that is strange. do you then also see multiple ahb_controller_events on one press? |
I have my E1812 connected to deconz, will test with ZHA tonight to see if I can reproduce you're issue. |
I understand why this happens. and we can not do much about it. The debouching still works but the condition never gets matched because we use the helper which only gets filled after the debounce period. Since we also need this helper for the double press we can not fill it before the debounce period because that will mess with the double press timings. Even though, I will test a bit more with writing to the helper before the delay and see if I can get that working. Now debouncing still works, when zha sends 5 events, the first 4 restart the automation but because of the debounce delay nothing else happens. only the 5th and last event will go trough. So maybe we can still release this so people can use it, and then we can try and make it work in such a manner that also to automation is not restarted 5 times. |
Yeah, it's not only the automation which gets triggered multiple times. The I'm also continuing testing different debouncing approaches, but still didn't get to a fully working solution. 👍🏻 |
That is very strange, do you notice that the delay is running at all? |
Forgot to fix to choses, made sure debounce_delay is an int.
I did a small change just now, to make sure that the debounce_delay is an int. Can you see if that helps? |
@EPMatt could you check if you still have double ahb_controller_events? |
Hi again. I've moved the delay till after update of the helper. This should help prevent automation restarts and does not seem to have a negative impact. |
I have an idea to prevent unnecessary automation restart, so bear with me :P |
So here it is, i don't see any automation restarts anymore except when releasing after a long press with "loop until release" enabled. Which makes sense because that automation takes a while and on release the debounce and double_press timeouts have expired. And we need that trigger for the "on release" event :) |
And to make you a bit more happy, i moved the debounce delay now to the double press routine, because in all other cases it's handled by the primary automation condition. So how debouncing now works: 1: event fires automation, On a double press we still need to do a debounce timeout because otherwise one of the events following the first will trigger the wait for trigger instantly. |
Hi @vandalon, Just as a note, even after increasing the |
@vandalon I've just performed a few additional tests on the blueprint, but unfortunately I encountered a few issues with the double press action. This is the automation config: use_blueprint:
path: EPMatt/ikea_e1812.yaml
input:
integration: ZHA
controller_device: <my_controller_id>
action_button_short:
- service: persistent_notification.create
data:
message: button short
action_button_long:
- service: persistent_notification.create
data:
message: button long
action_button_release:
- service: persistent_notification.create
data:
message: button release
action_button_double:
- service: persistent_notification.create
data:
message: button double
button_double_press: true
helper_last_controller_event: input_text.<my_input_text>
helper_debounce_delay: 1000
helper_double_press_delay: 5000 Short press seems to work quite well with With this configuration I'm rarely able to trigger the double press action, and when it happens, the action gets executed 5 times, exactly the number of I'll also try to investigate this issue but I suspect there might be something wrong with the P.S.: Sorry again for not being that active these days, unfortunately I've recently been really busy. But I want to underline that I truly appreciate your effort, time and energy you're putting into this and your other contributions as well. 👍🏻 |
If you have set the debounce delay 2 one 2nd the double press has to have a second between first and 2nd press. Is this the case in your test? |
Will test tomorrow:) |
Yeah, I waited 1+ seconds before pressing the button for the second time. Again, ZHA events were properly fired (I tested it in real time with HA Developer Tools). |
Thank you! Let me know if you need me to perform some additional tests. :) |
I can not reproduce your issue, for your automation just works :) Can you check the output of the automation trace in the HA UI? |
Hi @vandalon, Interestingly, today also single presses are not working as expected: I wasn't able to trigger one. 😅 As you can see debouncing is not working. Instead all automations are run, but after the By the way, some progress has been made into debugging the Thanks again for your time. :) |
That would be awesome :) Can you make sure there is nothing else interfering? Maybe multiple automation with the same device or something else? |
Definitely agree. I'm quite sure many of the problems we're dealing with are related to it. :)
Just checked and I can confirm nothing is interfering with this automation. I have only a single automation set up for that device, and as a safe measure I didn't setup any Hook with it. This is only my opinion, but maybe we can wait the |
Hi @eloo, thank you for reporting your tests here. I've just pushed a fix in this PR which solves the long press action issue, and simplifies the sequences for debouncing and double press events. Could you please check if everything works as expected with the latest version of this blueprint? Thank you so much for your valuable time and feedback! :) |
Why only debounce with delay if we can catch it in the primary conditions like you initially wanted? :) |
@EPMatt |
Good point @vandalon. :) I discovered that in HA automations For this reason and due to
I also deeply thought about this issue and found that assuming that a As stated in the Script Syntax regarding the
On the other hand, as stated in the Scripts documentation regarding script modes:
This means that even if the trigger is received in the I don't know whether this behaviour was caused by the HA Core I hope my explanation makes sense. Let me know what are your thoughts about it. :) |
@eloo thank you for testing. :) I think the issue is with the content of the text input helper. Thanks! |
@eloo thank you so much for your feedback! Happy to hear that the blueprint is working. 🎉
Right, you now have always to provide a valid We could also consider limiting the usage of the text helper only when necessary (eg. when debouncing is enabled and other conditions), but I think this might create a little bit of confusion among users: many reported that they weren't able to understand when the text helper was required, even after reading the docs. I guess it's not a big issue to ask users to provide a text helper for each controller automation they're setting, even if not strictly required; moreover this might be a good future-proof choice, since we might need it later to implement more advanced features in this blueprint. Just as a feedback, @eloo @vandalon what is your opinion about it? Thank you so much for your time. :D |
@EPMatt Also when you are going to set a double press action you can easily forget that you need to set this as well. PS: Thanks a lot for your great project. I really like the controller -> hooks pattern. |
@eloo totally agree with you, it's better to make the blueprint configuration as straightforward as possible. Thank you for the suggestion. 👍🏻
Thank you so much for your feedback! I'm really happy these blueprints are useful for you. 🚀 |
I've fixed #45 for this blueprint, as well as updated docs reflecting changes we are introducing here, and applied a few additional tweaks. Could you please test that the generated automation is properly working on your HA instances? Thank you very much for your precious help! |
I will do some testing after the weekend. I’m having a relax-weekend :P |
Hi @vandalon, don't worry, have a nice weekend. :D |
@vandalon the same goes with this PR. Since we received positive feedback from users regarding changes included here, I'm now updating changelog and merging this PR into Thank you for all your precious time and effort you put into this great contribution. 🚀 |
* Debouncing and optimized double press routine. * Update ikea_e1812.yaml Forgot to fix to choses, made sure debounce_delay is an int. * Fixed long press for zha. * Fixed issue where a button_short could happen after a button_double. * Moved debounce delay to beginning. Change double press check to make use of helper. * Enhanced debounce and double press logic. Simplified helper updates * Moved the debounce delay to the double_press routine * trigger GitHub actions * prettify * update zha and deconz mappings, fix long press * simplify double press, debounce only with a delay * simplify adjusted_double_press_delay calculation * optimize, refactor inputs, default debounce off * update docs * ignore non-json helper content, fix template warnings & formatting * fix double press recognition for deconz * fix debounce description, minor formatting changes * fix inputs wrongly stated as required * fix docs & update changelog Co-authored-by: Matteo Agnoletto <30753195+EPMatt@users.noreply.github.com> Co-authored-by: Matteo Agnoletto <info@epmatt.com>
Hi there, 🔒 This pull request has been automatically locked since there has not been any recent activity after it was closed. Thanks! |
A proper pull request this time :)
Added debouncing
Maximum loop option to prevent endless loops
Optimized double press routine
Some other small optimizations.
Closes #22.
Closes #45.