Okay, in the end I figured it out, might wright a longer post some time for others who are struggling with what they find on the web (or who like me didnt have enough math and informatics in school/university ), but for now the short version by going through one example (for 12bit codes, 15 and 20 work similar though):
“Volume up” code in hexadecimal (command and address in one, 12 bit version of SIRC): 0x490
Converted to binary: 010010010000
Now the first 7 bits are the command, the remaining 5 are the address
0100100 => command
10000 => address
BUT: the sony protocol/remote sends the binary command the other way around. Therefore:
0100100 => 0010010
10000 => 00001
0010010 converted to hex is 12, converted to decimal is 18
00001 converted to hex is 1, same for decimal
Depending on which resource for sony codes you use, they might use different methods to provide the codes.
Codes for IR Remotes - Tasmota uses the “command and address in one hex value” format: 0x490 for “volume up”
So funktioniert das SONY SIRCS/CTRL-S Protokoll / How SONY's SIRCS/CTRL-S protocol works uses “command and address separate, still in hex” format: 12 for “volume up”
SB-Projects - IR - Sony SIRC Protocol uses the “command and address separate, but in decimal” format: 18 for “volume up”
With that in mind you can basically use any (correct) Sony SIRC list on the web and calculate back and forth to the format that your code needs. esphome uses the “command and address in one hex number” version, the arduino libs I used so far use the “command and address separate, both hex” version.
I used Hex to Binary Converter to convert back and forth. Oh, one thing left: when you convert something that is supposed to be from the 15bit protocol (0x2CE9 for play/pause), a converter will give you 16 bits. Just cut off the first zero in that case, before you split up and revert the rest of the code as in the example above.
addition from 24.10.2024:
I now had the situation that I needed to do the calculation the other way around, so I thought I’d just quickly add that as an example as well. I used an arduino library on an esp32 to read some codes for my sony remote that I didn’t find online, but the library didn’t provide the format I needed for esphome.
So let’s go:
For the pause button of my remote, the arduino lib gives me 0x19 as the command code, and 0x97 as the address code (A=0x97 C=0x19)
So we start with:
19 97
Converting both numbers to binary I get this:
00011001 10010111
In this case the command is not a 12bit command, but a 15 bit command. But as the hex/binary converter filled up both binary numbers to 8 bits, we cut off the leading 0 from the command part. That gives us this:
0011001 10010111
Now we need to do the inversion (rewriting the individual bits, making the last one the first one, etcetc) of the order (as mentioned above), but only for the 2 individual parts. The order of the parts itself doesnt change. Result:
1001100 11101001
When we now combine the 2 parts to 100110011101001 and throw that into a hex converter, we get the code format we need for esphome:
0x4CE9
The working code in esphome now looks like this:
button:
- platform: template
name: SonyTVpause
id: sonytvpause
on_press:
- remote_transmitter.transmit_sony:
data: 0x4CE9
nbits: 15
repeat:
times: 5
wait_time: 50ms