Detect double click on remote receiver

Hi,

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

switch:
  - platform: gpio
    pin: GPIO13
    name: "Relay"
    id: relay_1

binary_sensor:
  - platform: remote_receiver
    name: "TV Power"
    samsung:
      data: 0xE0E036C9
      nbits: 32
    on_press:
      then:
        - switch.toggle: relay_1

remote_receiver:
  pin:
    number: GPIO26
    inverted: true
    mode:
      input: true
      pullup: true

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 :

binary_sensor:
  - platform: remote_receiver
    name: "TV Power"
    samsung:
      data: 0xE0E036C9
      nbits: 32
    on_double_click:
      then:
        - switch.toggle: relay_1

I also tried with an on_multi_click configuration but without more success
Does anyone have a working solution to do what I want ?

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

I may have missed something about remote_receiver

Did you change your config to trigger on on_click instead of on_press?

binary_sensor:
  - platform: remote_receiver
    name: "TV Power"
    samsung:
      data: 0xE0E036C9
      nbits: 32
    on_click:
      then:
        - switch.toggle: relay_1

yes, that’s what I tested just above

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.

1 Like

I couldn’t find anything with search engines.
I opened an issue there : on_click condition never reached with remote_receiver · Issue #5765 · esphome/issues · GitHub

1 Like

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.

I’m not fluent enough in lambda programming to do that

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.

My guess is that the “click” is too short?

  • min_length (Optional, Time): The minimum duration the click should last. Defaults to 50ms.

Edit: Although looking at your logs closer that doesn’t seem to be the case.

I want it to be managed within the esphome ESP32 module, not HA. So this can be used without being connected to a HA

Oh ! You’re right !
I configured min_length to 10ms and now on_click works !
I still am unable to make on_double_click work but that’s a step forward :slight_smile:

Would a long press work instead of double click?

I know I struggled with the same and now that I look at my yaml it seems I gave up and opted for long press instead.

binary_sensor:
  - platform: gpio
    pin: 3
    internal: true
    filters:
      - invert:
    name: "Blitzwolf btn"
    on_click:
    - min_length: 10ms
      max_length: 500ms
      then:
        - switch.toggle: relay_1
    - min_length: 500ms
      max_length: 2000ms
      then:
        - switch.toggle: relay_2

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.

Can you paste what the ESP detects when you do a long vs short press on your button?

Logs are exactly the same :confused:

short press :

[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

Sorry, should have been clearer. What do you get if you get a remote dump for every possible remote code in ESPHome, for short vs long press?

remote_receiver:
  pin:
    number: GPIO26
    inverted: true
    mode:
      input: true
      pullup: true
  dump: all

Oh! ok

short press :

[16:41:45][I][remote.pronto:237]: Received Pronto: data=0000 006D 0022 0000 00AD 00AD 0016 0040 0016 0040 0016 0040 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0040 0016 0040 0016 0040 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0040 0016 0040
[16:41:45][I][remote.pronto:239]: 0016 0015 0016 0040 0016 0040 0016 0015 0016 0040 0016 0040 0016 0015 0016 0015 0015 0041 0015 0016 0015 0016 0016 0040 0016 0181 06C3
[16:41:45][I][remote.samsung:061]: Received Samsung: data=0xE0E036C9, nbits=32
[16:41:45][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000B 0025 000C 000F 000C 0019 000B 0181 06C3
[16:41:45][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000B 0025 000C 000F 000B 001A 000B 0181 06C3

long press :

[16:42:35][I][remote.pronto:237]: Received Pronto: data=0000 006D 0022 0000 00AD 00AD 0016 0040 0016 0040 0016 0040 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0040 0016 0040 0016 0040 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0040 0016 0040
[16:42:35][I][remote.pronto:239]: 0016 0015 0016 0040 0016 0040 0016 0015 0016 0040 0016 0040 0016 0015 0016 0015 0016 0040 0016 0015 0016 0015 0016 0040 0016 0181 06C3
[16:42:35][I][remote.samsung:061]: Received Samsung: data=0xE0E036C9, nbits=32
[16:42:35][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000B 0025 000C 000F 000C 0019 000B 0181 06C3
[16:42:35][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000C 0024 000C 000F 000C 0019 000B 0181 06C3
[16:42:35][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000B 0025 000C 000F 000C 0019 000B 0181 06C3
[16:42:35][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000B 0025 000C 000F 000C 0019 000B 0181 06C3
[16:42:36][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000B 0025 000C 000F 000C 0019 000B 0181 06C3
[16:42:36][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000C 0024 000C 000F 000C 0019 000C 0181 06C3
[16:42:36][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000B 0025 000C 000F 000C 0019 000B 0181 06C3
[16:42:36][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000B 0025 000C 000E 000C 0019 000B 0181 06C3
[16:42:36][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000B 0025 000C 000F 000C 0019 000B 0181 06C3
[16:42:36][I][remote.pronto:237]: Received Pronto: data=0000 006D 0004 0000 000B 0025 000C 000F 000C 0019 000B 0181 06C3