IR Change in NEC : what do I need to do?

The description in the release notes is minimal and I have no idea what I need to do, to get it working again.
What does this mean:

it is necessary to reverse the order of the address and command bits when moving to 2021.12 or above. For example, address: 0x84ED , command: 0x13EC becomes 0xB721 and 0x37C8 respectively.

I can not see any similarity or rule in this example.

This is my current configuration, that doesn’t work anymore:

      remote_transmitter.transmit_nec:
        address: 0x4CB3
        command: 0x8877

What exactly do I need to do?
How do I downgrade to the previous version?

You have to reverse the order of the bits.

0x4CB3 = 0b100110010110011

Reversed = 0b110011010011001 = 0x6699

Likewise:

0x8877 = 0b1000100001110111

Reversed = 0b1110111000010001 = 0xEE11

Tom, thank you for your reply!
Is there a tool that would help me with this?
I have about 50 commands to convert.

ok, windows calculator and Reverse Binary Number - Reverse Bits - Online - Browserling Web Developer Tools help

Nope. That is reversing bytes. That won’t help.

Well I use calculator to turn hex into binary, then use the online tool, to reverse the binary, then calculator again, to turn reversed binary in hex. It seems to work, but I’m still looking for a more convenient way :smiley:

1 Like

ok, so here is my powershell oneliner for future reference :slight_smile:

([convert]::toint32((([convert]::toString('0x8877',2)[-1..-100]) -join ""),2)).toString('x')

I’m sure there is a less convoluted way, but it does the job.

1 Like

EDIT: I was too slow.

You can do it all in this tool:

Load up hex → binary

under the output box select “chain with” reverse binary

then under the output box of that select “chain with” binary to hex.

1 Like

When I enter 0x4040 in this tool (or my script) it returns 0x101.
Shouldn’t this always have four digits?
Would I have to add a zero? In the front or the back?
You see I’m really getting confused with these conversions.

Add a leading zero to the result.

1 Like

ok, so I converted all the values but they still don’t work. I see the commands in the ESPhome-log on the device, but nothing happens.

Is there a way to install a previous version of ESPhome via command line on HassOS, similar to

ha core update --version

I can’t seem to find anything in this regard.

Restore the backup the upgrade created.

Yep, just had the same idea. Thanx!

Then you should open an issue here so it gets looked at:

Did you also try to work with a remote receiver (and fire a ir remote on it) to “see” how the new version interprets the button press?

You could also use your old/working version of esphome withthe transmitter and build a second new one with a receiver. You will be essentially doing a “manual” conversation then.

Maybe it brings new bits to light :bulb:

I did once, when I recorded the original commands on the same device.

remote_receiver:
  pin: 
    number: "${component_remote_receiver_pin}"
    # Remote Receiver Signal starts with a HIGH value. Usually this means you have to invert the signal using 'inverted: True'
    inverted: yes
  dump: all

But since the commands from the remote didn’t change I didn’t bother to record them again.

I see what you are getting at though: debugging by receiving what the “new” transmitter" sends and comparing it to the original command.

Not sure if I’m up to this right now. Spent already way to much time with this migration.

Apparently I’ve done the conversion wrong.
Thanks to Peter Gebruers in the comments to the issue New NEC remote protocol does not work · Issue #2815 · esphome/issues · GitHub I got it working by using his python-function for conversion:

def reverse_mask(x):
    x = ((x & 0x5555) << 1) | ((x & 0xAAAA) >> 1)
    x = ((x & 0x3333) << 2) | ((x & 0xCCCC) >> 2)
    x = ((x & 0x0F0F) << 4) | ((x & 0xF0F0) >> 4)
    x = ((x & 0x00FF) << 8) | ((x & 0xFF00) >> 8)
    return x

print(f"0x{reverse_mask(0x4040):04X}")
1 Like

This worked a treat, thanks.

For anyone who needs this and aren’t experienced with python, it’s not hard.
All you do is install python and save the above code from seanomat into a python file.
I called mine reverse.py and then just run it by typing “python reverse.py” in a command line terminal or powershell if using Windows.
My file looks like this,

def reverse_mask(x):
x = ((x & 0x5555) << 1) | ((x & 0xAAAA) >> 1)
x = ((x & 0x3333) << 2) | ((x & 0xCCCC) >> 2)
x = ((x & 0x0F0F) << 4) | ((x & 0xF0F0) >> 4)
x = ((x & 0x00FF) << 8) | ((x & 0xFF00) >> 8)
return x

print(f"0x{reverse_mask(0x01FE):04X} vol up address")
print(f"0x{reverse_mask(0x609F):04X} vol up command")
print(f"0x{reverse_mask(0x01FE):04X} vol down address")
print(f"0x{reverse_mask(0xA05F):04X} vol down command")
print(f"0x{reverse_mask(0x01FE):04X} Source address")
print(f"0x{reverse_mask(0x58A7):04X} Source command")
print(f"0x{reverse_mask(0x40BF):04X} Power command")

the output will look like this,

0x7F80 vol up address
0xF906 vol up command
0x7F80 vol down address
0xFA05 vol down command
0x7F80 Source address
0xE51A Source command
0xFD02 Power command

If anyone is wondering this is the codes for the Kef LS50 Wireless

1 Like