ESPHome IR transmitter/receiver woes

Hi all,

I’m in the process of deploying D1 Mini-based IR transceivers wherever I have TV’s or anything else controlled with IR remote controls so that I can create automations and trigger them via Hassio. The hardware part of this works great for the most part. I’m having some challenges with the configuration side though - specifically what I believe are yaml size limitations or limitations on the number of entities as well as data type…challenges.

My first stab at this was to put all of the commands for the given location into the D1’s yaml config but this caused odd wifi behavior. I’d backed out a bunch of the IR command codes thinking a typo might be the problem and things started working again. This led to me to remove/comment out a number of commands that I think won’t be used often and then the D1 started working as expected again. The issues with this route are that even by limiting the number of items in the yaml to stabilize wifi the built in web server doesn’t seem to be able to serve up a page that large. As you can see from the screen shot, a number of button/switch entities are missing even though they’re in the yaml config. I know they’re working because they ALL show in the Hassio UI. Even if the ESPHome web server issue were fixed, I still can’t define entities for all of the remote commands I want to. As soon as I uncomment out the commands that are commented out in the yaml below, the code compiles but the D1 Mini has difficulty with wifi handshakes, establishing and maintaining connections (NOT the 5 minute reboot loop issue) and it never responds when you try and bring up its internal webpage nor does it show up in HA. Screenshot of the D1’s web page and the associated yaml config are below.

esphome:
  name: ir_blaster_office
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "my_wifi"
  password: "my_pass"
  fast_connect: on
  power_save_mode: none
  
# Enable logging
logger:

# Example configuration entry
remote_receiver:
  pin: 
    number: GPIO13
    inverted: yes
    mode: INPUT_PULLUP
  dump: all
  #dump: 'lg'
  #dump: 'nec'
  #dump: 'panasonic'
  #dump: 'jvc'
  #dump: 'samsung'
  #dump: 'sony'
  #dump: 'rc_switch'
  #dump: 'rc5'

remote_transmitter:
  pin: GPIO12
  carrier_duty_percent: 50%

switch:
  - platform: template
    name: Samsung Mute
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0xE0E0F00F
  - platform: template
    name: Samsung Power
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0xE0E040BF
  - platform: template
    name: Samsung Left Arrow
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0xE0E0A659
  - platform: template
    name: Samsung Right Arrow
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0xE0E046B9
  - platform: template
    name: Samsung Up Arrow
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0xE0E006F9
  - platform: template
    name: Samsung Down Arrow
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0xE0E08679
  - platform: template
    name: Samsung Home
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0xE0E09E61
  - platform: template
    name: Samsung Enter
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0xE0E016E9
  - platform: template
    name: Samsung Return/Back
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0xE0E01AE5
  - platform: template
    name: Samsung Volume Up
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0xE0E0E01F
  - platform: template
    name: Samsung Volume Down
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0xE0E0D02F
  - platform: template
    name: PIP Switcher In 1
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x01FE48B7
  - platform: template
    name: PIP Switcher In 2
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x01FE58A7
  - platform: template
    name: PIP Switcher In 3
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x01FE7887
  - platform: template
    name: PIP Switcher In 4
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x01FE807F
  - platform: template
    name: PIP Switcher In Cycle
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x01FEC03F
  - platform: template
    name: PIP Switcher PIP
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x01FE50AF
  - platform: template
    name: PIP Switcher Select
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x01FED827
  - platform: template
    name: PIP Switcher Enter
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x01FEF807
  - platform: template
    name: HDMI 5 Switcher In 1
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0x1010F00F
  - platform: template
    name: HDMI 5 Switcher In 2
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0x101048B7
  - platform: template
    name: HDMI 5 Switcher In 3
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0x10109867
  - platform: template
    name: HDMI 5 Switcher In 4
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0x1010F807
  - platform: template
    name: HDMI 5 Switcher In 5
    turn_on_action:
      - remote_transmitter.transmit_samsung:
          data: 0x101038C7
#  - platform: template
#    name: HDMI 5 Switcher Cycle Down
#    turn_on_action:
#      - remote_transmitter.transmit_samsung:
#          data: 0x1010B04F
#  - platform: template
#    name: HDMI 5 Switcher Cycle Up
#    turn_on_action:
#      - remote_transmitter.transmit_samsung:
#          data: 0x101030CF
  - platform: template
    name: HDMI 4 Switcher Power
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF629D
  - platform: template
    name: HDMI 4 Switcher In 1
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF02FD
  - platform: template
    name: HDMI 4 Switcher In 2
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FFE01F
  - platform: template
    name: HDMI 4 Switcher In 3
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF906F
  - platform: template
    name: HDMI 4 Switcher In 4
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF9867
  - platform: template
    name: HDMI 4 Switcher Sound
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF30CF
  - platform: template
    name: HDMI 4 Switcher 720P/1080P
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF7A85
  - platform: template
    name: HDMI 4 Switcher Single View
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF10EF
  - platform: template
    name: HDMI 4 Switcher Quad 1+3 View
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF38C7
  - platform: template
    name: HDMI 4 Switcher Quad Matrix View
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF5AA5
  - platform: template
    name: HDMI 4 Matrix Switcher Power
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF28D7
  - platform: template
    name: HDMI 4 Matrix Switcher Out A – In 1
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF906F
  - platform: template
    name: HDMI 4 Matrix Switcher Out A – In 2
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FFB847
  - platform: template
    name: HDMI 4 Matrix Switcher Out A – In 3
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FFF807
  - platform: template
    name: HDMI 4 Matrix Switcher Out A – In 4
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FFB04F
#  - platform: template
#    name: HDMI 4 Matrix Switcher Out A – Cycle Down
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x00FFD827
#  - platform: template
#    name: HDMI 4 Matrix Switcher Out A – Cycle Up
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x00FF8877
  - platform: template
    name: HDMI 4 Matrix Switcher Out B – In 1
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FFE817
  - platform: template
    name: HDMI 4 Matrix Switcher Out B – In 2
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF48B7
  - platform: template
    name: HDMI 4 Matrix Switcher Out B – In 3
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF9A65
  - platform: template
    name: HDMI 4 Matrix Switcher Out B – In 4
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF10EF
#  - platform: template
#    name: HDMI 4 Matrix Switcher Out B – Cycle Down
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x00FFAA55
#  - platform: template
#    name: HDMI 4 Matrix Switcher Out B – Cycle Up
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x00FF12ED
  - platform: template
    name: HDMI 4 Matrix Switcher Out C – In 1
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF7A85
  - platform: template
    name: HDMI 4 Matrix Switcher Out C – In 2
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF609F
  - platform: template
    name: HDMI 4 Matrix Switcher Out C – In 3
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FFA05F
  - platform: template
    name: HDMI 4 Matrix Switcher Out C – In 4
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FFC03F
#  - platform: template
#    name: HDMI 4 Matrix Switcher Out C – Cycle Down
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x00FFE01F
#  - platform: template
#    name: HDMI 4 Matrix Switcher Out C – Cycle Up
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x00FF02FD
  - platform: template
    name: HDMI 4 Matrix Switcher Out D – In 1
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF18E7
  - platform: template
    name: HDMI 4 Matrix Switcher Out D – In 2
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF22DD
  - platform: template
    name: HDMI 4 Matrix Switcher Out D – In 3
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FFF00F
  - platform: template
    name: HDMI 4 Matrix Switcher Out D – In 4
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x00FF8A75
#  - platform: template
#    name: HDMI 4 Matrix Switcher Out D – Cycle Down
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x00FF7887
#  - platform: template
#    name: HDMI 4 Matrix Switcher Out D – Cycle Up
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x00FF708F
#  - platform: template
#    name: Apple TV Up Arrow
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x77E1D027
#  - platform: template
#    name: Apple TV Down Arrow
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x77E1B027
#  - platform: template
#    name: Apple TV Left Arrow
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x77E11027
#  - platform: template
#    name: Apple TV Right Arrow
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x77E1E027
#  - platform: template
#    name: Apple TV Enter
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x77E1BA27
#    turn_off_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x77E12027
#  - platform: template
#    name: Apple TV Menu
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x77E14027
#  - platform: template
#    name: Apple TV Play/Pause
#    turn_on_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x77E17A27
#    turn_off_action:
#      - remote_transmitter.transmit_lg:
#          data: 0x77E12027

# Enable Home Assistant API
api:

ota:

# Enable Web server.
web_server:
  port: 80

# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time

…which gives this web page, with a number of switches/entities missing as well as the debug console, etc.

Thinking that I could shift the command codes to Hassio automations instead of keeping them all in the D1’s ESPHome yaml config, I think came up with this config yaml:

esphome:
  name: ir_blaster_generic_1
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "my_wifi"
  password: "my_pass"

# Enable logging
logger:

remote_receiver:
  pin: 
    number: GPIO13
    inverted: yes
    mode: INPUT_PULLUP
  dump: all

remote_transmitter:
  pin: GPIO12
  carrier_duty_percent: 50%

# Enable Home Assistant API
api:
  services:
    - service: send_samsung_command
      variables:
        my_command: int
      then:
        - remote_transmitter.transmit_samsung:
            data: !lambda 'return my_command;'
    - service: send_lg_command
      variables:
        my_command: int
      then:
        - remote_transmitter.transmit_lg:
            data: !lambda 'return my_command;'

ota:

I’d originally tried defining my_command as a string but got the error below on compile:

Compiling /data/ir_blaster_generic_1/.pioenvs/ir_blaster_generic_1/src/main.cpp.o
src/main.cpp: In lambda function:
src/main.cpp:179:14: error: cannot convert 'std::string {aka std::basic_string<char>}' to 'uint16_t {aka short unsigned int}' in return
return my_command;
^

…since there is no unsigned int data type for ESPHome according to its API documentation I changed them to int as you see in the yaml above. My challenge now is that I cannot call the service because when I try and pass in command codes such as 0xE0E0F00F HA tells me it’s not valid JSON so I quote it but then it errors out because it’s not an int (since the quotes make it a string).

I thought about logging a bug for the ESPHome web page and yaml size limitation issues but wanted to post here first in case anyone had any other alternative solutions as this first scenario (my office) will be the smaller of the configs. Once I get into the home theater config, I’m expecting many more IR commands needing to be defined.

Thanks,

-joni-

Have you tried turning off receiver dump to see if it helps?

Hopefully you find the code solution to sending it the command over a service call. If not, the other thing you can do is make additional Wemos boards. It’ll split up your config so that should allow the Wemos to work. I actually stick my Wemos inside of the device I’m controlling if I can.

Another thing to try would be an ESP32.

Just an update - removing the receive code helped a lot although I still can’t add all of the commands/switches but I CAN more than double what I had working already. Thank you for that suggestion. Since receiving codes and using combinations to trigger automations was in my plans I’m still looking for alternatives. Worst case I’ll go the route you suggested of using two D1’s. Putting them directly in the chassis of what they’re controlling is an interesting idea too.

Re your suggestion of using an ESP32 - was that just because it’s faster and has more memory than a D1 Mini or have you had better experiences with their performance in cases like this? (Since it sounds like you’ve built a similar project)

Thanks,

-joni-

Nice!

I haven’t tried the ESP32 route myself, but it’s a much more beefier processor, so I would expect it wouldnt have an issues with that logic, if it’s simply a matter of memory and processing power.

Mine are pretty basic inside of fans, projectors and screens. Works great though.

An update and still looking for longer term solution:

I ordered a couple ESP32’s to play with and tried uploading the config to one today with all of the remote commands (so far) enabled and while I haven’t wired it up to IR LED’s yet to validate that part works, the web page DOES load and show all of the buttons and debug window at the bottom. This seems to be the solution for now though I’d still like to find a way to pass in the IR commands such as 0x00FF629D which come into the ESP as a string and then cast/convert them to uint which the IR transmitter “code” expected to be a uint in the data segment. If I can figure this out then I can keep the ESP’s as D1 Minis and keep them “dumb” with all of the IR codes within HA/NodeRed automations which sends the command strings to the ESP to convert to uint and ultimately transmit via IR out to the devices to control.

Thanks,

-joni-

Hi @rjchu,

Did you managed to send commands from HA to ESP and then via IR to control devices?

Thank you!
Ciprian

Instead of sending commands to the ESP (since the check for … logic got to be too much for the little ESP. Instead I’d implemented a handful of remotes (tv, receiver, etc) then defined each command I want to use as a service and call them from node red via an automation or
Alexa.

Thanks,

-Joni-

I’ve managed to send commands from HA to ESP instead of hardcoding them on the esphome.

Esphome:

api:
  services:
    - service: send_ir_code
      variables:
        code: int[]
        times: int
      then:
        - remote_transmitter.transmit_raw:
            carrier_frequency: 38kHz
            code: !lambda 'return code;'
            repeat:
              times: !lambda 'return times;'

Home Assistant service call:

service: esphome.esp8266_ircontroller_send_ir_code
data:
  code: [894, -873, 891, -876, 1784, -867, 896, -872, 893, -874, 901, -1750, 1780, -871, 894, -1757, 901, -867, 1780, -871, 894]
  times: 2

Thanks for sharing. I was tinkering with openmqttgateway yesterday and think I’ll use that for my whole home rollout. HA has certainly gotten better but after being burned several times with updates that broke things, I try and use MQTT and Node Red for as much as I can and only rely on HA for things that wouldn’t impact the house working if HA were down. Openmqttgateway fits the bill. I can send and receive IR command via MQTT and no longer have to rely on HA services. Might be worth looking at depending on your situation.

-Joni-

Thanks for the tip. I’ve actually gone the opposite way: moving most things from other services into HA. I’ve almost stopped using MQTT and migrated my NodeRed flows into HA Automations. Less services to maintain, and a single point to control and manage this. HA downtime is usually pretty low to be a problem for me.

That’s the beauty of this solution - everyone can use and adapt it to for their particular needs!

1 Like

I managed to resolve this! You can use string as the variable data type and convert the string to uint during the transmit call. Here’s an example:

- service: send_samsung_command
  variables:
    command: string
  then:
    - remote_transmitter.transmit_samsung:
        data: !lambda 'return strtoull(command.c_str(), nullptr, 16);'
        nbits: 48

With this configuration, you can pass a string like 0xB54AF50AA55A to the service, and it will be converted properly.