Python script to learn bulk amount of IR/RF codes for Broadlink devices

Going through and learning 200+ IR codes with Broadlink RM2 for my air conditioner was going to be a painful experience using the Home Assistant “learn_command” service in developer tools.

So I created a python script to make this less manual than trying to learn IR codes via home assistant. I’ve been learning python recently so I thought this would be fun little script for me to put together. If anyone wants to use it, link is below.

Basically just put a list of all the command names you want to learn into input.txt, then the script will cycle through the list and prompt you to press the corresponding button for each one. It will then save the entire output to output.csv which you can then open in any text editor or excel.

6 Likes

I was trying to use your script but when i’m running it i’m getting the following error. I can learn commands using broadlink manager. any help?

*** Press button for low_16 ***
Traceback (most recent call last):
  File "bulk_learn.py", line 107, in <module>
    main('input.txt', 'output.csv', False)
  File "bulk_learn.py", line 69, in main
    p = get_packet(device)
  File "bulk_learn.py", line 38, in get_packet
    device.enter_learning()
AttributeError: 'device' object has no attribute 'enter_learning'

It did work but for some reason none of the codes received worked when i tried them.

did you install the Broadlink module?
pip install broadlink

I did work but for some reason most times when I’m running the script it shows 2 broadlink devices (I have only one), when it founds only one device the script works like a charm.
And it was my fault that the commands didn’t work because I didn’t know that my remote wasn’t “on”. The remote I have it shows all the time something on the screen and it doesn’t turn on/off with the a/c so when I thought that I was sending commands In reality I wasn’t.