ESPHome IR Receiver

Hey guys,
Im using an ESPHome based node for a few things including ir controll for my Xbox one. Im using a cheap IR remote and an IR receiver on the esp8266 to receive the key presses and then send the key presses to home assistant/node red and then trigger actions on the xbox like dpad actions and such. Now comes my problem: When i set up a template binary sensor for every key with proper debouncing and then use the “state-changed to on” node in node-red, i cant hold down a button to scroll fast through a playlist from youtube or fast forward in a netflix series. If i listen for rc5 commands, send the command as the data of an event that i fire, split this in node-red up in a separete event for every monitored key and use these events to trigger my actions, i can fast scroll via holding a key, but most of the times i get unwanted double or tripple presses, due not having debouncing.
Is there any other implementation, that i missed or a way to add the debouncing with the event setup?

Hi @tenn0

I’m just in the process of trying to do something similiar with an IR receiver. how do you get the IR receiver commands linked to HA actions?

-Cheers,

There are a few ways. In esphome create a binary sensor for every key press and when it switches from low to high execute service calls. The part of reacting to state changes can be done in node-red. That way, every key press executes a service call only once, no matter how long the key is pressed.
My actual setup is using events: in esphome, I use the on_samsung function in the ir_receiver, triggering an event with the value as event data. In node-red, I use switch nodes to split the event that a key press occurred into events for every key press. Then, react to every key press event to trigger service calls.

My code is like this:


remote_receiver:
  pin: D3
  dump: all


binary_sensor:
  - platform: remote_receiver
    name: "Yamaha power"
    raw:
      code: [-208, 625, -104, 105, -104, 104, -625, 208, -208, 105, -104, 104, -104, 104, -208]
    filters:
      - delayed_off: 200ms  
  
  - platform: remote_receiver
    name: "Yamaha vol up"
    raw:
      code: [-208, 105, -104, 416, -104, 105, -104, 104, -104, 104, -417, 208, -208, 105, -104, 208, -312]
    filters:
      - delayed_off: 200ms  
      
  - platform: remote_receiver
    name: "Yamaha vol minus"
    raw:
      code: [-208, 104, -104, 417, -104, 104, -104, 104, -104, 105, -416, 209, -104, 208, -104, 208, -313]
    filters:
      - delayed_off: 200ms

and so on…

Then in node red:

[{"id":"d3186026.6482b","type":"delay","z":"94bc1df0.962d9","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":490,"y":2300,"wires":[["a7b634ca.81b1d8"]]},{"id":"9804f2ce.461dd","type":"trigger-state","z":"94bc1df0.962d9","name":"","server":"4bbca37b.1700ec","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.yamaha_vol_minus","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"kk3slv7yh7f","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":200,"y":2300,"wires":[["d3186026.6482b"],[]]},{"id":"a7b634ca.81b1d8","type":"api-current-state","z":"94bc1df0.962d9","name":"","server":"4bbca37b.1700ec","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.yamaha_receiver","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":760,"y":2300,"wires":[["b0d0f9c7.99dbe8"]]},{"id":"b0d0f9c7.99dbe8","type":"function","z":"94bc1df0.962d9","name":"","func":"msg.volume_level = msg.data.attributes.volume_level - 0.03\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1020,"y":2300,"wires":[["48888345.4ef9cc"]]},{"id":"48888345.4ef9cc","type":"api-call-service","z":"94bc1df0.962d9","name":"","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.yamaha_receiver","data":"{        \"volume_level\": {{volume_level}}    }","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1230,"y":2300,"wires":[[]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

4 Likes

Thank you for that; I now have that part working. I only wish there was a way to group a remote functions under one sensor of some type Makes for a lot of entities in HA.

-Cheers,

Hi @Hellis81

Quick question for you. I have my devices added into my .yaml file for ESPhome; but only 24 or so entities are working in NodeRed. I can see them all in HA; just not all in NodeRed; have you ever seen this?

-Cheers,

Not that specifically, but yes entities missing in node red.
Go to supervisor and restart node red.

Thanks. I have tried that and restating the entire host pc and so far nothing. I’ll keep trying.

Hi @tenn0

Did you eventually manage to implement a solution to differentiate between short and long key presses?

What I am trying to accomplish
My logitech harmony remote has died and Logitech stopped making them. So now I’m trying to replace it with a universal remote and still find a way to control my nvidia shield which doesn’t have IR.

My setup

  • hassio
  • esp8266 (with tsop receiver) with remote_receiver
remote_receiver:
  pin:
    number: D1
    inverted: True
    mode: INPUT_PULLUP
  dump: samsung
  on_samsung:
    then:
      - homeassistant.event:
          event: esphome.ir_command
          data_template:
            data: '{{ ir_command }}'
          variables:
            ir_command: !lambda |-
              int data = x.data;
              char hex[8];
              sprintf(hex, "%#.08X", data);
              return hex;
  • node-red to ‘switch’ (decode the commands) to send harmony-hub websockets commands
  • universal one for all remote (urc 7145)

But it does not recognize long key presses to perform an alternate action like:

  • fast scrolling
  • open a sub menus in e.g. kodi

Thanks,

TM

1 Like

No, i havent worked on this tbh. Currently, im not using kodi, because all my media im using is either on youtube, netflix or spotify. My kodi runs on my xbox one s, and when i restart HA and kodi isnt running, i just get errors all over the place. My “fast-scroll” is actually a fast repeating call of the scroll command.