Confusion around Sony Infrared codes (SIRC)

Heyhey, might be a bit farfetched, but maybe I’m lucky. I’m currently working on replacing my default IR tv remote control with an esphome-based one. Part of that is that I’d like to make the HDMI inputs directly selectable, without having to press the input button to cycle through the available inputs until I’m at the right one. My current remote control doesnt have dedicated buttons for that.
So I started with connecting an IR receiver to an esp32 and documenting existing codes via GitHub - IRMP-org/IRMP: Infrared Multi Protocol Decoder

The codes I get for the relevant buttons I also want to use (volume up/down, mute, play, pause, …) all line up nicely with what I find online about the Sony protocol (e.g. on So funktioniert das SONY SIRCS/CTRL-S Protokoll / How SONY's SIRCS/CTRL-S protocol works):
12 for volume up, 13 for volume down, 14 for mute, etcetc

grafik

The problem I’m facing: my remote doesnt have dedicated “switch to hdmi1”, “switch to hdmi2” etc buttons. They do exist for sony tvs, I found a remote controller online:

And when I’m searching for other SIRC lists I can find entries that mention the hdmi buttons, but they dont match the code format that I get for my remote. Here is a list e.g. (Codes for IR Remotes - Tasmota) where volume up and down hsa different codes than mine:
grafik

In case I’m lucky: does anyone here have experience with SIRC across different devices and device classes and can explain the differences to me? First I thought I just need to transform the values, but now I think that Sony got less consequent with its code usage over the years…

Thanks in advance! Cheers :slight_smile:

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 :wink: ), 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
2 Likes

@Lakini thanks a lot for the share but did you find out how to handle SIRCS code like these:
Power On: category: 0x01 and data: 0x2E
Power Off: category: 0x01 and data: 0x2F
As I can’t find out how to use these in ESPHome :frowning:

Thanks

Vincèn

The codes you shared are in the same format as the ones listed in So funktioniert das SONY SIRCS/CTRL-S Protokoll / How SONY's SIRCS/CTRL-S protocol works, so I’d assume the “category” part is just the address.

I didnt use sony codes in esphome so far, but going by Remote Transmitter — ESPHome I would guess the “data:” part needs to be the combined hex value for both address and command. You would basically have to go backwards in the calculation I did above, so that your result is a single hex value again.

Oh wait, actually the list in Codes for IR Remotes - Tasmota includes the commands you need in the right format for esphome:

Power On {Protocol:SONY,Bits:12,Data:0x750}
Power Off {Protocol:SONY,Bits:12,Data:0xF50}

Give those value a try in esphome an see if it works, so 12 for nbits:, and 0x750 for data:, and come back with the result :slight_smile:

Hi @Lakini

Thanks a lot for help but unhappy it doesn’t work at all :frowning: I tried that but TV doesn’t react at all !

button:

  • platform: template
    name: TV On
    on_press:
    • remote_transmitter.transmit_sony:
      data: 0x750
      nbits: 12
  • platform: template
    name: TV Off
    on_press:
    • remote_transmitter.transmit_sony:
      data: 0xF50
      nbits: 12

I checked the Tasmota list but it’s the classic list of IR codes from Sony and they don’t work on that model as I had already tried these :frowning: Any ideas what else I could try ?

Thanks

Does the sending actually work? You can check with your phone camera to see if the IR diode actually sends something out.

What do the esphome logs show when you trigger the sending?

I’m sure of hardware as I do with the Kincony box that I use to control quite a lot of devices in IR :wink:
but I gave a check at logs and good idea it looks like it transmits nothing !
logs I get with an other working control:

19:08:53 [D] [button:010]
‘sky_mrs CH +’ Pressed.
19:08:53 [D] [remote.pronto:101]
Send Pronto: frequency=36kHz
19:08:53 [D] [remote.pronto:106]
Send Pronto: intros=0
19:08:53 [D] [remote.pronto:107]
Send Pronto: repeats=60

and what happens when it sends the sony code or supposed to:

19:37:55 [D] [button:010]
‘TV Off’ Pressed.

19:37:56 [D] [button:010]

‘TV Off’ Pressed.

19:37:57 [D] [button:010]

‘TV On’ Pressed.

19:37:58 [D] [button:010]

‘TV On’ Pressed.

19:37:59 [D] [button:010]

‘TV Off’ Pressed.

but I don’t see anything wrong in the code no ?

esphome:
  name: esp-of-01

esp32:
  board: esp32dev
  framework:
    type: arduino

logger:

web_server:

ota:

wifi:
  networks:
  - ssid: !secret wifi_ssid
    password: !secret wifi_passwd
  manual_ip:
    static_ip: 172.16.2.141
    gateway: 172.16.1.1
    subnet: 255.255.252.0
  ap:
    ssid: esp-of-01

captive_portal:

api:
  reboot_timeout: 10min

sensor:
  - platform: uptime
    name: esp-of-01 Uptime
    filters:
      - lambda: return x / 60.0 /60.0 /24;
    unit_of_measurement: d
  - platform: wifi_signal
    name: esp-of-01 WiFi Signal
    update_interval: 60s

remote_transmitter:
  pin: GPIO2
  carrier_duty_percent: 50%

button:
  - platform: template
    name: TV On
    on_press:
      - remote_transmitter.transmit_sony:
          data: 0x750
          nbits: 12
  - platform: template
    name: TV Off
    on_press:
      - remote_transmitter.transmit_sony:
          data: 0xF50
          nbits: 12

I also dont see anything obvious. You might want to open a dedicated thread just around this

This might make a difference: Trouble getting IR emitter to send Sony codes - #4 by LPD

That’s a very detailed instruction
I had the same issue with my sony tv way back then but luckily logitech harmony database has the codes.

Thanks for the link and tried it but not better :frowning: It emits well the IR (I can see it with camera) but TV doesn’t react :frowning:

Not 1 set of IR codes will work for all Sony Tv’s.

I don’t know if this topic is still an open one for you, but I now had the situation that I had to do the calculation the other way around, I added that to me comment above which is ticked as the solution. At the bottom you can see how I did the steps for another command, but it might work for yours as well with that method.