I have an IR receiver working on my ESP32 module, I’m able to detect key press on the remote controller and toggle a relay when I want with the following configuration
Now I’m looking for a way to detect double click on the same button of my remote controller.
I thought that configuring my binary sensor like follows would work, but it’s not :
My memory’s a bit hazy, but I was looking into this a couple of months ago and it might be because remote_receiver immediately sends an off command. This means that your remote has already triggered the toggle command by the time your finger has left the button.
From the remote_receiver docs: “Each time the pre-defined signal is received, the binary sensor will briefly go ON and then immediately OFF.”
You might be able to work around this by playing around with delayed_off together with min_length and max_length. Hopefully, applying a delayed_off won’t mess up your single click, since you are triggering on the on_press event.
Thank you
I tried to play with those parameters, but without any more success.
What I don’t understand is that only the on_press condition seems to be considered, the on_click condition doesn’t reacts when pressing the button while it’s still detected.
with on_press :
[15:16:46][D][binary_sensor:036]: 'TV Power': Sending state ON
[15:16:46][D][switch:012]: 'Relay' Turning ON.
[15:16:47][D][binary_sensor:036]: 'TV Power': Sending state OFF
with on_click :
[15:21:51][D][binary_sensor:036]: 'TV Power': Sending state ON
[15:21:52][D][binary_sensor:036]: 'TV Power': Sending state OFF
That’s weird, though to be honest I don’t really know if remote_receiver supports on_click (nothing indicates it shouldn’t though).
Might be a good time to google around for “remote_receiver” and “on_click” together. If that doesn’t get you anywhere, it would be a good idea to raise an issue on the ESPHome github.
Don’t forget to leave a link to any issues you raise, or any solutions you find, so anyone else with the same problem will be able to see how it’s done.
It probably has something to do with how IR codes are transmitted multiple times and then the IR receiver platform reads them and translates many into 1 button press event. Some of my remotes for example, the code is transmitted 7-8 times for 1 button press.
You could probably make a template binary sensor and then toggle that sensor on/off from your remote_receiver binary sensor.
What about a statistics sensor in HA that reads the binary sensor.
When it has two as the mean value during a time period of one second then it’s a double click.
It will require a bit of restructuring but I think it could work
A way to do it in HA is to set up an input_number. Have an automation that when it detects the button pressed once it calls a service input_number.increment. An automation to call whatever service you want when it reaches 2 and reset input_number to 0. Automation to reset the number to 0 after a second or 2 so if you press it once it doesn’t go to 2 if you press it again the next day.
I had this to do call a service if somebody pressed the door bell a certain number of times in a minute.
No, this doesn’t work.
My remote doesn’t send the same code when keeping the button pressed, but instead sends a specific “repeat code”. So the binary sensor detects a button press and validates it nearly instantaneously and a long press can’t be detected.
That’s why I’m trying to detect a double_click instead.
[16:29:05][D][binary_sensor:036]: 'TV Power': Sending state ON
[16:29:05][D][binary_sensor:036]: 'TV Power': Sending state OFF
[16:29:05][D][switch:012]: 'Relay' Turning ON.
[16:29:05][D][switch:055]: 'Relay': Sending state ON
long press :
[16:29:22][D][binary_sensor:036]: 'TV Power': Sending state ON
[16:29:22][D][binary_sensor:036]: 'TV Power': Sending state OFF
[16:29:22][D][switch:012]: 'Relay' Turning ON.
[16:29:22][D][switch:055]: 'Relay': Sending state ON