What's right to put on bk7231n based IR blaster to make it usable in HA?

Thanks a lot.
I’ve tried to add this to my own though, and can’t get it to compile. I get:

/config/esphome/ir-blaster.yaml: In lambda function:
/config/esphome/ir-blaster.yaml:187:50: error: no match for 'operator+' (operand types are 'const char [16]' and 'esphome::remote_base::ProntoData')
  187 |               std::string log_output = "Pronto: Data = " + x;
      |                                ~~~~~~~~~~~~~~~~~ ^ ~
      |                                |                   |
      |                                const char [16]     esphome::remote_base::ProntoData
In file included from src/esphome/core/entity_base.h:5,
                 from src/esphome/components/binary_sensor/binary_sensor.h:4,
                 from src/esphome/core/controller.h:5,
                 from src/esphome/components/api/api_server.h:9,
                 from src/esphome/components/api/api_connection.h:6,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/string_ref.h:118:20: note: candidate: 'std::string esphome::operator+(const char*, const esphome::StringRef&)'
  118 | inline std::string operator+(const char *lhs, const StringRef &rhs) {
      |                    ^~~~~~~~
src/esphome/core/string_ref.h:118:64: note:   no known conversion for argument 2 from 'esphome::remote_base::ProntoData' to 'const esphome::StringRef&'
  118 | inline std::string operator+(const char *lhs, const StringRef &rhs) {
      |                                               ~~~~~~~~~~~~~~~~~^~~
src/esphome/core/string_ref.h:124:20: note: candidate: 'std::string esphome::operator+(const esphome::StringRef&, const char*)'
  124 | inline std::string operator+(const StringRef &lhs, const char *rhs) {
      |                    ^~~~~~~~
src/esphome/core/string_ref.h:124:47: note:   no known conversion for argument 1 from 'const char [16]' to 'const esphome::StringRef&'
  124 | inline std::string operator+(const StringRef &lhs, const char *rhs) {
      |                              ~~~~~~~~~~~~~~~~~^~~
Compiling .pioenvs/smartirblaster/lib295/ESPAsyncWebServer-esphome/WebResponses.cpp.o
*** [.pioenvs/smartirblaster/src/main.cpp.o] Error 1
========================= [FAILED] Took 98.04 seconds =========================

I guess it might be a type mismatch? I’m not sure how to get it going though. Got any idea what I’m doing wrong pls?

Sorry there was a typo on this line
std::string log_output = "Pronto: Data = " + esphome::to_string(x.data);
I updated the post above

That’s got it to compile OK
I might still be getting something basic wrong here though. Sorry to make you sharing something a pain.

I press the Learn Command button in HA, then press a button on a remote. The log shows Pronto data it’s received, but I see nothing happen in HA.
The Learned Command sensor’s there in HA, showing as Unknown and doesn’t change.

I noticed Pronto: Data = doesnt show anywhere in the log, so tried changing that to Pronto: data= (no space before =) that does…
Then I get this in the log:

[17:43:48][D][switch:012]: 'Learn Command' Turning ON.
[17:43:48][D][switch:055]: 'Learn Command': Sending state ON
[17:43:53][D][switch:055]: 'Learn Command': Sending state OFF
[17:43:53][D][text_sensor:064]: 'Learned Command': Sending state 'Pronto: data= 0000 006D 0022 0000 00AA 00AD 0013 0044 0014 0042 0014 0044 0013 0019 0011 001A 0012 001A 0011 0019 0012 0019 0012 0044 0013 0043 0014 0044 0013 0019 0012 0019 0013 0017 0014 0019 0014 0018 0012 0019 0011 001A 0013 0018 0012 0019 0013 0019 0012 0043 0014 0044 0013 0019 0012 0044 0013 0043 0014 0044 0012 0044 0012 0044 0013 0018 0014 0019 0013 0042 0014 0181 06C3'

but see nothing change with Learned Command in HA?
What should happen?

Hmmm I think what’s going on here is that it’s too long for the text sensor and being rejected by HA…

So far I’ve been mostly using it with other protocols which are more compact, I’ll have a think how to handle that better unless you’ve got some ideas?

A text sensor is probably not the best option…

I’m just fumbling my way into ESPHome and ESPs in gneral tbh.
Well up for trying things out but have little to offer that might help, sorry.

So state data is definitely limited to 255 characters: WTH is 255 the max length for states?

A workaround is using state attributes instead of states, but esphome can’t publish to state attributes :upside_down_face: - Is esphome possible to expose entities to ha with attributes?

I don’t think this method I was using will work well for pronto data… If you’re using another protocol from the list which uses shorter data it will, but 9/10 you’re probably using pronto format

Looks like you’ll just have to use dump: all and follow the log output…

I was hoping to get your pronto approach working and then change things to use raw. Raw will probably end up even longer though.

Most/all of my remotes are detected as pronto, but then the data that’s logged seems pretty useless. At least I’ve not found how to use it.
Almost always ends up with Inconsistent data, not sending when I try to send it.
I haven’t been able to find why :man_shrugging:

After I capture a few (5-10) raw button presses, discard any obvious outliers, test sending any that are left and select the best responding, raw’s working spot on. Better than it was working while it was Tuya.
It’s a bit of a pain to do it for evey button, but the results are great so far.
This little thing’s got considrably better range/coverage than some of my original remotes.
I’ve got an aquarium light with a cheap IR remote that’s got to be close and pointed at the light just right for it to work. This little thing just has to be in the same room, can even be the opposite side of the fish tank with a load of wood cabinet in the way!

Aha I think I know what your problem is - your receive data is inverted. And your transmitter possibly is too.

If you’re able to read and broadcast RAW data then both your receiver and transmitter must at least be the wrong way around together… :slight_smile:

Try inverted: false on your receive and inverted: true on your transmit.

Are you sure you need the pullup on your receive too?

Without the pullup I get nothing at all.

Looking at the raw, I found not having the inverted always made codes start with a minus. I gather that’s starting with a delay/off, so has to mean it should be inverted?

Hmm yeah okay codes shouldn’t start with a minus…

Not too sure why that is then right now…

I dont remember playing with inverting remote_transmitter though, so i will

I can’t even get it to compile with inverted: true anywhere I can think to try it in either remote_transmitter or remote_transmitter.transmit_pronto :rofl:
Maybe its only a thing for remote_transmitter.transmit_rc_switch_type_a?

If what I’m capturing doesnt start with -/minus, and then sends OK… That means I’ve got to have this the right way round (and there’s some other reason for my troubles with pronto codes) doesn’t it? :worried:

Yeah if what you’re receiving raw isn’t negative that you should already have it the right way round as you say. Have you tried playing with the tolerance when you’re decoding/sending pronto data? Looks like you’ve made it tighter than the default which is maybe affecting things?

I made it tighter hoping to improve how codes are recognised, but it didnt at all.
I tried setting it to a few petty random numbers but saw no difference

I’ve done some looking into the inconsistent data error and I think it happens when the pronto data you’re sending is too long and then gets truncated.

But this is kind of secondary to another thing that seems to be happening, which is that I think you’re getting a really long pronto code because the input signal is varying too much for the library to decode and separate the repeats from each other, which may be affected by that tolerance config option?

I’m thinking if you make the tolerance higher/wider, you might get shorter pronto codes

Edit: Reading tolerance docs and source I’m getting confused whether you want a higher or lower value in this case to be honest :upside_down_face:

Try moving the remote further away from your unit when you’re learning the codes, it might help to get less varied signals so the lib can see the repeats

Just tried a few different tolerances:

Tolerance 0
[22:09:39][I][remote.pronto:233]: Received Pronto: data=
[22:09:39][I][remote.pronto:235]: 0000 006D 0022 0000 00A7 00B0 0013 0044 0012 0045 0012 0044 0011 001A 0011 0019 0012 0019 0013 0019 0014 0018 0013 0044 0013 0043 0012 0045 0012 0019 0013 0018 0012 0019 0013 0018 0011 001A 0011 001A 0011 001B 0012 0019 0011 0044 
[22:09:39][I][remote.pronto:235]: 0013 0018 0012 0045 0012 0045 0013 0017 0012 0046 0011 0044 0012 0047 000E 001A 0011 0045 0013 0018 0013 0018 0012 0045 0012 0181 06C3

Tolerance 25
[22:06:25][I][remote.pronto:233]: Received Pronto: data=
[22:06:25][I][remote.pronto:235]: 0000 006D 0022 0000 00A8 00AF 0013 0045 0012 0043 0013 0043 0014 0017 0014 0018 0014 0018 0012 0019 0013 0018 0013 0044 0013 0043 0014 0043 0013 0018 0014 0018 0013 0018 0013 0018 0012 001A 0012 0018 0012 0019 0012 0019 0012 0044 
[22:06:25][I][remote.pronto:235]: 0013 0017 0014 0045 0011 0043 0012 0019 0012 0045 0012 0044 0013 0043 0013 0018 0014 0043 0013 0018 0014 0018 0012 0045 0012 0181 06C3
[22:06:25][I][remote.samsung:061]: Received Samsung: data=0xE0E016E9, nbits=32

Tolerance 50
[22:03:35][I][remote.jvc:049]: Received JVC: data=0xE0E0
[22:03:35][I][remote.lg:054]: Received LG: data=0xE0E016E9, nbits=32
[22:03:35][I][remote.pronto:233]: Received Pronto: data=
[22:03:35][I][remote.pronto:235]: 0000 006D 0022 0000 00A8 00AF 0014 0043 0014 0043 0013 0043 0013 0018 0014 0017 0014 0018 0012 0019 0012 0019 0012 0045 0012 0045 0012 0043 0013 0018 0013 0018 0014 0018 0013 0018 0014 0017 0014 0018 0014 0017 0014 0018 0012 0046 
[22:03:35][I][remote.pronto:235]: 0011 0019 0013 0044 0012 0043 0014 0017 0014 0043 0013 0043 0014 0043 0013 0018 0012 0045 0012 0019 0012 0019 0012 0045 0012 0181 06C3
[22:03:35][I][remote.samsung:061]: Received Samsung: data=0xE0E016E9, nbits=32

Tolerance 75
[22:05:01][I][remote.jvc:049]: Received JVC: data=0xFFFF
[22:05:01][I][remote.lg:054]: Received LG: data=0xFFFFFFFF, nbits=32
[22:05:01][I][remote.nec:097]: Received NEC: address=0xFFFF, command=0xFFFF command_repeats=1
[22:05:01][I][remote.pronto:233]: Received Pronto: data=
[22:05:01][I][remote.pronto:235]: 0000 006D 0022 0000 00A8 00AF 0013 0045 0012 0045 0012 0043 0014 0017 0014 0018 0014 0017 0014 0018 0013 0018 0014 0044 0013 0042 0013 0044 0012 0019 0012 0019 0012 0019 0013 0017 0014 0018 0014 0017 0014 0018 0014 0017 0014 0044 
[22:05:01][I][remote.pronto:235]: 0013 0018 0013 0044 0012 0045 0012 0019 0012 0045 0011 0045 0012 0046 0011 0018 0014 0043 0013 0018 0012 0019 0012 0044 0012 0181 06C3
[22:05:01][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=3 data='00000000000000000000000000000000'
[22:05:01][I][remote.samsung:061]: Received Samsung: data=0xFFFFFFFF, nbits=32

Tolerance 100
[22:07:58][I][remote.jvc:049]: Received JVC: data=0xFFFF
[22:07:58][I][remote.lg:054]: Received LG: data=0xFFFFFFFF, nbits=32
[22:07:58][I][remote.nec:097]: Received NEC: address=0xFFFF, command=0xFFFF command_repeats=1
[22:07:58][I][remote.pronto:233]: Received Pronto: data=
[22:07:58][I][remote.pronto:235]: 0000 006D 0022 0000 00A8 00AF 0013 0044 0012 0045 0012 0044 0013 0018 0014 0017 0014 0018 0015 0016 0014 0018 0013 0044 0012 0045 0012 0045 0012 0019 0012 0019 0012 0018 0013 0018 0014 0017 0014 0018 0014 0017 0014 0018 0013 0043 
[22:07:58][I][remote.pronto:235]: 0012 0019 0013 0044 0012 0044 0012 0019 0012 0043 0012 0045 0013 0043 0014 0017 0014 0044 0012 0019 0012 0019 0013 0044 0012 0181 06C3
[22:07:58][I][remote.drayton:230]: Received Drayton: address=0x0000 (0x0000), channel=0x000 command=0x000
[22:07:58][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=3 data='00000000000000000000000000000000'
[22:07:58][I][remote.samsung:061]: Received Samsung: data=0xFFFFFFFF, nbits=32

This is with my Samsung TV remotes OK/Enter button
The pronto data doesn’t seem to change length at all, but I do get Samsung codes at 25%-100%.
The one I got with 25% and 50% (0xE0E016E9) works perfectly.

When I was recording button IR codes last night, I think I started with the remote from a cheap fan I’ve got, cranked down the tolerance and ended up setting it to capture raw so didn’t even look for ‘proper’ codes when I got to my TV remote. :man_facepalming:

Guess I’ll be doing a bunch of that again!
Thanks for sending me in the direction that lead to finding that

Great stuff, yeah it does look like 25% is best - you can see the signal is getting more false positives as the tolerance goes up and no perfect matches at 0. I understand that config too now at last :wink:

So if you wanna try the “learn” thing again, here’s it updated for samsung:


# Home Assistant controlled fake switch - to enable "learning mode"
switch:
  - platform: template
    name: Learn Command
    id: remote_learn_switch
    optimistic: true

# Home Assistant sensor to store remote command data
text_sensor:
  - platform: template
    name: Learned Command
    id: learned_command

remote_receiver:
  pin:
    number: P7
    inverted: true
    mode:
      # INPUT_PULLUP # Seems to do the same as seperate input & pullup
      input: true
      pullup: true
  on_samsung:
    - if:
        condition:
          lambda: 'return id(remote_learn_switch).state;'
        then:
          - lambda: |-
              id(remote_learn_switch).publish_state(false);
              std::string log_output = "Samsung: Data = 0x" + esphome::format_hex(x.data) + ", nbits = " + esphome::to_string(x.nbits);
              id(learned_command).publish_state(log_output.c_str());
          - delay: 80ms
          - light.turn_on: ir_status_light
          - delay: 500ms
          - light.turn_off: ir_status_light
  # # On all received pronto data
  # on_pronto:
  #   - if:
  #       condition:
  #         # If Remote Learn switch is on
  #         lambda: 'return id(remote_learn_switch).state;'
  #       then:
  #         # - Turn learn switch off
  #         # - Build data string
  #         # - Publish data string to text sensor
  #         - lambda: |-
  #             id(remote_learn_switch).publish_state(false);
  #             std::string log_output = "Pronto: Data = " + esphome::to_string(x.data);
  #             id(learned_command).publish_state(log_output.c_str());
  #         # Blink status LED
  #         - delay: 80ms
  #         - light.turn_on: ir_status_light
  #         - delay: 500ms
  #         - light.turn_off: ir_status_light
  # # Using SONY protocol instead
  # on_sony:
  #   - if:
  #       condition:
  #         lambda: 'return id(remote_learn_switch).state;'
  #       then:
  #         - lambda: |-
  #             id(remote_learn_switch).publish_state(false);
  #             std::string log_output = "Sony: Data = 0x" + esphome::format_hex(x.data) + ", nbits = " + esphome::to_string(x.nbits);
  #             id(learned_command).publish_state(log_output.c_str());
  #         - delay: 80ms
  #         - light.turn_on: ir_status_light
  #         - delay: 500ms
  #         - light.turn_off: ir_status_light


With that, the shorter Samsung codes (like 0xE0E016E9) make it into HA:
image

They have a bunch of 0s added though :thinking:

I guess it’d make sense to uncomment each block, and add more, for the common code standards. With the type of code ending up in HA, that should mean not having to go through the log…