IR receiver fires multiple times on one keypress?

I have IR receiver with M5Stack Atom to get keypresses from universal remote and Broadlink RM4 to send commands to my TV, receiver, Roku…
Simple code in ESP fires homeassistant.event with every received sony code and HA automation sends commands with Broadlink to devices.

All this works, but with one key press on remote, IR code is detected several times.
It means, my automation also sends one command several times.
Obviosly not good for example ‘Channel_up’

Tried different things, but can’t find solution to prevent repeated events

remote_receiver:
  pin:
    number: GPIO32
    inverted: true
  dump: all  # sony

  # In this lambda, x is an SonyData. x.data is a uint32_t that identifies the button pressed.
  on_sony:
    then:  # Listen to events:  esphome.Remote
    - homeassistant.event:
        event: esphome.Remote
        data_template: 
          value: !lambda "return x.data;"

    - logger.log: 
        format: "Recieved IR: %0X"  # "Recieved IR: %0f"
        args: [ 'x.data']

1 Like

Do the ESPHOME logs give any extra hints about what’s going on?

If you don’t find a quick answer here, you might try this web site, forum and products. These are some real infrared gurus : ‘AnalysIR - All about infrared remote control, IR decoding and more’, main web site link below.

and fyi, it’s ‘i before e, except after c’. I’ve spend my life hating on human language :wink:
Recieved => Received

IR signals is really prone to distortion so many IR transmitters send the signal multiple times and then let the receiver handle the multiple repeated signal.
Because the IR remote and the IR receiver device is usually made together then it can be handled easily, but when we come in with a device and try take over things can go wrong here and there.
We can record a signal with multiple repeats and reuse that for other signals that do not have the repeats and our devices can be slower to transmit the repeated signal, which means the grace period in the receiver to not react on the signal is overflown.
Our IR transmitters are generally a better quality than the cheap once that came with the device, so a lower number of repeats can be good enough and often a single signal without repeats is fine too.
You need to remove the repeats here.

1 Like

Here one press ‘channel up’ > detected ‘90’ two times,
one press ‘channel down’ > detected ‘890’ four times

INFO ESPHome 2023.11.1
INFO Reading configuration /config/esphome/esp32-ir.yaml...
INFO Starting log output from 192.168.1.44 using esphome API
INFO Successfully connected to 192.168.1.44 in 0.038s
INFO Successful handshake with 192.168.1.44 in 0.039s
[09:22:41][I][app:102]: ESPHome version 2023.11.1 compiled on Nov 17 2023, 21:36:30
[09:22:41][C][wifi:559]: WiFi:
[09:22:41][C][wifi:391]:   Local MAC: D4:D4:DA:85:17:40
[09:22:41][C][wifi:396]:   SSID: 'Antsumaja'[redacted]
[09:22:41][C][wifi:397]:   IP Address: 192.168.1.44
[09:22:41][C][wifi:399]:   BSSID: 20:B0:01:E6:17:DD[redacted]
[09:22:41][C][wifi:400]:   Hostname: 'esp32-ir'
[09:22:41][C][wifi:402]:   Signal strength: -80 dB ▂▄▆█
[09:22:41][C][wifi:406]:   Channel: 11
[09:22:41][C][wifi:407]:   Subnet: 255.255.255.0
[09:22:41][C][wifi:408]:   Gateway: 192.168.1.1
[09:22:41][C][wifi:409]:   DNS1: 0.0.0.0
[09:22:41][C][wifi:410]:   DNS2: 0.0.0.0
[09:22:41][C][logger:416]: Logger:
[09:22:41][C][logger:417]:   Level: DEBUG
[09:22:41][C][logger:418]:   Log Baud Rate: 115200
[09:22:41][C][logger:420]:   Hardware UART: UART0
[09:22:41][C][restart:068]: Restart Switch 'esp32-ir Restart'
[09:22:41][C][restart:070]:   Icon: 'mdi:restart'
[09:22:41][C][restart:091]:   Restore Mode: always OFF
[09:22:41][C][remote_receiver.esp32:054]: Remote Receiver:
[09:22:41][C][remote_receiver.esp32:055]:   Pin: GPIO32
[09:22:41][C][remote_receiver.esp32:060]:   Channel: 0
[09:22:41][C][remote_receiver.esp32:061]:   RMT memory blocks: 3
[09:22:41][C][remote_receiver.esp32:062]:   Clock divider: 80
[09:22:41][C][remote_receiver.esp32:063]:   Tolerance: 25%
[09:22:41][C][remote_receiver.esp32:064]:   Filter out pulses shorter than: 50 us
[09:22:41][C][remote_receiver.esp32:065]:   Signal is done after 10000 us of no changes
[09:22:41][C][captive_portal:088]: Captive Portal:
[09:22:41][C][mdns:115]: mDNS:
[09:22:41][C][mdns:116]:   Hostname: esp32-ir
[09:22:41][C][ota:097]: Over-The-Air Updates:
[09:22:41][C][ota:098]:   Address: 192.168.1.44:3232
[09:22:41][C][api:139]: API Server:
[09:22:41][C][api:140]:   Address: 192.168.1.44:6053
[09:22:41][C][api:144]:   Using noise encryption: NO
[09:22:56][D][main:062]: Recieved IR: 90
[09:22:56][I][remote.pronto:237]: Received Pronto: data=0000 006D 000D 0000 0059 001B 0014 001B 0015 001A 0014 001B 0014 001B 002C 001A 0014 001B 0015 001A 002C 001A 0014 001B 0014 001B 0015 001A 0014 0181 06C3
[09:22:56][I][remote.sony:065]: Received Sony: data=0x00000090, nbits=12
[09:22:56][D][main:062]: Recieved IR: 90
[09:22:56][I][remote.pronto:237]: Received Pronto: data=0000 006D 000D 0000 0059 001B 0014 001A 0015 001A 0016 001A 0014 001A 002B 001A 0014 001B 0014 001A 002B 001A 0014 001B 0015 001A 0014 001C 0014 0181 06C3
[09:22:56][I][remote.sony:065]: Received Sony: data=0x00000090, nbits=12
[09:22:56][I][remote.pronto:237]: Received Pronto: data=0000 006D 001D 0000 0061 004D 0016 000E 000C 000D 0008 000F 0017 0018 000B 000D 000B 000C 000C 000D 000A 000F 000A 000E 000B 000E 000A 000E 000A 000F 000B 000D 000B 000F 000A 000D 000A 000F 000A 000D 0016 000E 000A 000D 0009 001B
[09:22:56][I][remote.pronto:239]: 000B 000D 000B 000D 000A 000E 0017 0017 0018 0018 000C 000D 000B 000B 0018 0181 06C3
[09:22:56][I][remote.pronto:237]: Received Pronto: data=0000 006D 001D 0000 0060 004A 0017 000E 000A 000D 000C 000C 0016 001A 000B 000C 000A 000D 000B 000D 000B 000D 000B 000C 000B 000E 000A 000C 000B 000E 000A 000C 000C 000D 000A 000C 000C 000E 000A 000C 0018 000C 000C 000E 000A 0019
[09:22:56][I][remote.pronto:239]: 000C 000C 000B 000E 000B 000D 0016 0019 0017 0018 000C 000B 000C 000D 0016 0181 06C3
[09:22:56][I][remote.pronto:237]: Received Pronto: data=0000 006D 001D 0000 0060 004B 0016 000D 000B 000D 000B 000D 0016 001A 000A 000E 000A 000E 000A 000D 000B 000D 000B 000E 000A 000D 000A 000E 000B 000D 000B 000D 000A 000D 000B 000E 000A 000D 000B 000D 0016 000E 000B 000D 000A 0019
[09:22:56][I][remote.pronto:239]: 000C 000D 000A 000F 000A 000D 0016 0019 0016 0019 000D 000D 000A 000D 0016 0181 06C3
[09:22:56][I][remote.pronto:237]: Received Pronto: data=0000 006D 001C 0000 0060 004A 0017 000E 000B 000D 000B 000C 0017 0019 000B 000D 0009 000E 000B 000E 0015 001A 000A 000D 000A 000F 0009 000D 000B 000E 0008 000E 000B 000E 000A 000C 000C 000E 0014 000D 000D 000A 000B 001A 0009 000D
[09:22:56][I][remote.pronto:239]: 000B 000E 000A 000F 0017 0018 0018 000C 000A 0019 000C 000D 0016 0181 06C3
[09:23:06][D][main:062]: Recieved IR: 890
[09:23:06][I][remote.pronto:237]: Received Pronto: data=0000 006D 000D 0000 0059 001B 002B 001B 0014 001B 0014 001B 0013 001C 002B 001B 0013 001C 0013 001C 002B 001C 0014 001B 0013 001C 0014 001B 0014 0181 06C3
[09:23:06][I][remote.sony:065]: Received Sony: data=0x00000890, nbits=12
[09:23:06][D][main:062]: Recieved IR: 890
[09:23:06][I][remote.pronto:237]: Received Pronto: data=0000 006D 000D 0000 0059 001B 002B 001B 0014 001B 0013 001C 0013 001C 002B 001B 0014 001B 0014 001B 002B 001B 0014 001B 0014 001B 0014 001B 0014 0181 06C3
[09:23:06][I][remote.sony:065]: Received Sony: data=0x00000890, nbits=12
[09:23:07][D][main:062]: Recieved IR: 890
[09:23:07][I][remote.pronto:237]: Received Pronto: data=0000 006D 000D 0000 0059 001B 002B 001B 0014 001B 0014 001B 0013 001C 002A 001C 0014 001B 0014 001B 002B 001C 0013 001C 0014 001B 0014 001B 0014 0181 06C3
[09:23:07][I][remote.sony:065]: Received Sony: data=0x00000890, nbits=12
[09:23:07][D][main:062]: Recieved IR: 890
[09:23:07][I][remote.pronto:237]: Received Pronto: data=0000 006D 000D 0000 0059 001B 002B 001B 0014 001B 0014 001B 0014 001B 002B 001B 0014 001B 0014 001B 002B 001B 0014 001B 0014 001B 0014 001B 0014 0181 06C3
[09:23:07][I][remote.sony:065]: Received Sony: data=0x00000890, nbits=12
[09:23:07][I][remote.pronto:237]: Received Pronto: data=0000 006D 001C 0000 0062 004A 0017 000E 000B 000D 000B 000D 0016 0019 000A 000D 000C 000D 000A 000D 000B 000D 000A 000D 000C 000B 000B 000D 000C 000B 000B 000E 000B 000D 000A 000D 000A 000E 0016 0019 000C 000C 0017 0019 000B 000D
[09:23:07][I][remote.pronto:239]: 000A 000D 000B 000E 0016 001A 0014 001B 0009 000D 0018 0017 000C 0181 06C3
[09:23:07][I][remote.pronto:237]: Received Pronto: data=0000 006D 001C 0000 0061 0049 0018 000C 000B 000E 000B 000B 0017 0019 000C 000D 000B 000B 000B 000E 000B 000B 000C 000D 000C 000C 000B 000E 000B 000D 000B 000D 000A 000D 000B 000C 000B 000D 0017 0019 000B 000D 0017 0018 000B 000C
[09:23:07][I][remote.pronto:239]: 000A 000E 000C 000C 0017 0019 0017 0018 000B 000D 0017 0019 000A 0181 06C3
[09:23:07][I][remote.pronto:237]: Received Pronto: data=0000 006D 001C 0000 0060 0049 0018 000E 0008 000F 000A 000D 0016 001A 0008 000F 000A 000D 0008 0010 000B 000C 0009 000F 000A 000E 0008 0011 000A 000D 0008 000E 000B 000E 0009 000E 000C 000D 0016 001A 000B 000C 0018 0017 000B 000E
[09:23:07][I][remote.pronto:239]: 000A 000C 000C 000D 0015 001B 0016 0019 000A 000C 0018 0017 000C 0181 06C3
[09:23:07][I][remote.pronto:237]: Received Pronto: data=0000 006D 001B 0000 0060 0049 0018 000D 000A 000E 000B 000C 0016 0019 000A 000D 000C 000D 000B 000D 0016 0019 000B 000E 0008 000E 000C 000D 000B 000B 000D 000D 0009 000D 000B 000E 0015 001A 0008 000E 0018 0018 000A 000F 000B 000D
[09:23:07][I][remote.pronto:239]: 000B 000E 0015 001A 0015 000D 000B 0019 0017 0018 000A 0181 06C3
[09:23:07][I][remote.pronto:237]: Received Pronto: data=0000 006D 001C 0000 0063 004B 0017 000E 000A 000D 000A 000D 0017 0018 000A 000D 000B 000E 000B 000D 000B 000E 000B 000D 000B 000E 000A 000D 000C 000B 000C 000D 000B 000E 000A 000D 000A 000D 0017 0018 000B 000C 0017 0019 000A 000E
[09:23:07][I][remote.pronto:239]: 000B 000D 000A 000D 0016 001A 0015 001A 000B 000D 0016 0019 000B 0181 06C3
[09:23:07][I][remote.pronto:237]: Received Pronto: data=0000 006D 001C 0000 0061 004A 0016 000E 000B 000D 000A 000D 0016 001A 000B 000C 000B 000D 000B 000C 000A 000D 000B 000C 000B 000C 000C 000D 000A 000D 000B 000D 0009 000E 000B 000E 0008 000E 0018 0018 000C 000D 0016 0019 0009 000D
[09:23:07][I][remote.pronto:239]: 000B 000E 000A 000C 0017 0019 0017 0018 000B 000E 0016 001A 0009 0181 06C3
[09:23:07][I][remote.pronto:237]: Received Pronto: data=0000 006D 001C 0000 0060 0049 0018 000E 0009 000F 000A 000E 0016 001A 0009 000F 000A 000D 0008 000F 000A 000E 0009 0010 000A 000D 000A 0010 000B 000C 0008 000E 000C 000D 0009 000E 000C 000E 0015 001A 000A 000D 0017 0018 000C 000D
[09:23:07][I][remote.pronto:239]: 000A 000C 000D 000C 0015 001B 0016 0019 000B 000B 0018 0017 000D 0181 06C3
[09:23:07][I][remote.pronto:237]: Received Pronto: data=0000 006D 001B 0000 0060 004A 0018 000C 000B 000E 000A 000D 0016 0019 000B 000D 000B 000E 000B 000D 0016 0019 000B 000C 000A 000D 000B 000D 000B 000C 000B 000E 000B 000C 000A 000F 0017 0018 000B 000C 0017 0019 000B 000C 000A 000E
[09:23:07][I][remote.pronto:239]: 000B 000D 0017 0018 0016 000E 000B 0019 0017 0018 000B 0181 06C3

I try to remove repeats, but unfortunately my YAML skills are quite limited for now. I was hoping that someone has already figured out how to do this.

No experience with IR, but for similar things, I’ve found adding a short delay to the automation at the end will prevent repeats. Maybe start with 100ms and fine-tune?

I use a Sonoff RF Bridge, so I see each signal I record and only one signal per line.
It is also then quite easy to see the repeats and the distortion from signal to signal.

1 Like

I can’t change what signals are coming from my remote control, so there is no point to investigate incoming signals. I must deal with this what I get.
I try to add delay in esp automation and hope that IR input stream in not queued somewhere in buffer.

I would keep the esp clean and have the HA automation that is listening to the events check if it has run recently. That way you keep full control and kan e.g. still detect long press v.s. short press.

I reckon you could figure out a way to throttle incoming signals to “debounce” them.

You make a new script: in ESPHome which just has a 1sec delay in it…

Then in your on_sony actions you have the following psuedo code:

If script is running
then do nothing
else start script and send event to HA.

Or could you use a binary sensor for this instead?

Then you can use a delay_off filter to debounce multiple codes in quick succession.

With binary sensor I must make for every command separate sensor and also separate automations for every operation. I try to stay with one automation which decodes commands and sends them to right device

1 Like

Sometimes the problem is that the signal is recorded from the original remote and it contains multiple signals I that recording.

1 Like

‘I can’t change what signals are coming from my remote control, so there is no point to investigate incoming signals. I must deal with this what I get.’

If as was pointed out by @WallyR that some ‘clone’ IR copying hardware does a poor job of cloning the signals and ‘solves’ their poor ability by sending the code multiple times, you have a real challenge. Does the original remote transmit the signal multiple times?

How are you going to differentiate between you wanting to press the button multiple times and remote resending the signal? Seems link you are going to end up with a less than ideal user experience by trying to ‘debounce’ in some way.

It is actually not the cloning hardware that does this.
It is the original transmitter hardware.
This is why you often get a high, low and mid value from a recording.