Xiaomi Universal Remote Learn & Send

So i have this Xiaomi Universal Remote, it has about 4 types, mine is chuangmi.remote.v2 model(latest?). I Did the configuration, HA sees and uses it safe and sound.

I use the following python scripts for IR learn and send, so that it can learn all codes for all buttons on the remote easily and much faster than HA way. I got these codes from Domoticz forum. Please note that you have to install python3 miio for this ( pip3 install python-miio)

Learn Code Script:
This learns 5 keys in order every time it is started and writes these codes to a file called “codes.txt”

#!/usr/bin/python3
import sys
import ipaddress
from typing import Any
from miio import ChuangmiIr,DeviceException
import time
import json
num_lines = sum(1 for line in open('codes.txt'))
print ('Stored Ir Keys  ->'+ str(num_lines) )
id = num_lines + 1
ir =  ChuangmiIr('192.168.XXX.XXX',XXXXXX....')

for i in range(5):
  ir.learn(key=1)
  t=0
  while ir.read(key=1).get("code")=='' and t<=5:
    time.sleep(0.1)
    t +=0.1

  print (str(i)+': '+ir.read(key=1).get("code"))

  with open('codes.txt', 'a') as file:
 	  file.write(ir.read(key=1).get("code")+ '\n')

Send Code Script:

#!/usr/bin/python3
import sys
import ipaddress
from typing import Any
from miio import ChuangmiIr,DeviceException
import time
#id = input('Enter code:')
id=Input('Enter the Code:')
ir =  ChuangmiIr('192.168.XXX.XXX','XXXXXXXXX.....,debug=1)
print (ir.info())
ir.play(id)

This worked very well for Pioneer BDP150, Pioneer VSX and Epson Projector.

However, with Sony Bravia TV and a Sagemcom TV set top box, it learns the codes, however when sending it, the devices don’t get the codes at all. There is no error on the script or HA when sending. Bravia works OK with Mi Home application. Sagemcom set top box doesn’t have any pre defined device in Mi Home app so i can’t test it.

Now i was wondering if there is a tip or trick to make the learned commands work with Bravia TV and the Sagemcom set top box? Is there anyone who made it work with Sony TVs? Is there a way to decode or encode these raw codes of chuangmi.remote.v2?

Bravia Power Code: "mU0mUwlk1nEwlkxmQBDTYBDwEPlk2mgA5TUAeZjMgBCAQQDHgB7mEAA="
Sagemcom Power Code: "mU1mEsnE0mEsmUyADKZzYAQgEHAHKZTcAhpjMgImmMym4CKzkAdpjOQODAIKYQA="
2 Likes