├── broadlink_to_home_assistant_encoder.py ├── sendCode.py ├── econtrol-db-dump.py ├── getBroadlinkSharedData.py └── README.md /broadlink_to_home_assistant_encoder.py: -------------------------------------------------------------------------------- 1 | import base64, sys, binascii 2 | 3 | packet = sys.argv[1] 4 | packet = binascii.unhexlify(packet) 5 | packet = base64.b64encode(packet).decode('utf8') 6 | 7 | print(packet) 8 | -------------------------------------------------------------------------------- /sendCode.py: -------------------------------------------------------------------------------- 1 | import broadlink 2 | import time 3 | import sys 4 | 5 | # settings 6 | device = broadlink.rm(host=("10.0.0.2",80), mac=bytearray.fromhex("b4430fffffff")) 7 | 8 | print "Connecting to Broadlink device...." 9 | device.auth() 10 | time.sleep(1) 11 | print "Connected...." 12 | time.sleep(1) 13 | device.host 14 | 15 | # Replace with your code 16 | 17 | codeData = "e90a4200df0909160916091616091609091616091609091616091609160916091609091616090916091616090916091616090916091609161609091616091609160909161609" 18 | 19 | 20 | 21 | device.send_data(codeData.decode('hex')) 22 | print "Code Sent...." -------------------------------------------------------------------------------- /econtrol-db-dump.py: -------------------------------------------------------------------------------- 1 | import sqlite3 as lite 2 | 3 | # This script will "parse" the broadlink e-Control Android application database and dump the IR / RF codes for selected accessories into a text file which can be later used with broadlink-python to send the codes to the RM PRO hub 4 | # You need to get the "rmt.db" file from your (rooted) android device or emulator (ARM), the file is located in "/data/data/com.broadlink.rmt/databases/rmt.db" and put it in the same folder as this script. 5 | # adb pull /data/data/com.broadlink.rmt/databases/rmt.db 6 | 7 | buttonIDS = [] 8 | buttonNames = [] 9 | 10 | # e-Control Database file 11 | con = lite.connect('rmt.db') 12 | 13 | # Get All Accessories 14 | with con: 15 | cur = con.cursor() 16 | cur.execute("SELECT id, name FROM subIRTable") 17 | 18 | rows = cur.fetchall() 19 | 20 | for row in rows: 21 | print "Accessory ID: " + str(row[0]) + " | Accessory Name: " + row[1] 22 | 23 | # Choose Accessory 24 | 25 | accessory = input("Select Accessory ID: ") 26 | 27 | cur.execute("SELECT name FROM subIRTable where id =" + str(accessory)) 28 | 29 | accessory_name = cur.fetchone()[0] 30 | 31 | print "[+] You selected: " + accessory_name 32 | print "[+] Dumping codes to " + accessory_name + ".txt" 33 | 34 | 35 | # Get Buttons id 36 | with con: 37 | cur = con.cursor() 38 | cur.execute("SELECT name, id FROM buttonTable where subIRId=" + str(accessory)) 39 | rows = cur.fetchall() 40 | 41 | for row in rows: 42 | buttonIDS.append(row[1]) 43 | buttonNames.append(row[0]) 44 | 45 | codesFile = open(accessory_name + '.txt', 'w') 46 | 47 | # Get Codes 48 | 49 | for i in range(0, len(buttonIDS)): 50 | cur.execute("SELECT irCode FROM codeTable where buttonId=" + str(buttonIDS[i])) 51 | code = cur.fetchone()[0] 52 | result = "Button Name: " + buttonNames[i] + "| Button ID: " + str(buttonIDS[i]) + " | Code: " + str(code).encode('hex') + "\n" 53 | codesFile.writelines(result.encode('utf-8')) 54 | codesFile.close() 55 | -------------------------------------------------------------------------------- /getBroadlinkSharedData.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | This script will "parse" the broadlink e-Control Android application "SharedData" json files and dump the IR / RF codes for selected accessories into a text file which can be later used with broadlink-python to send the codes to the RM PRO hub 5 | NO ROOT ACCESS REQUIRED 6 | 7 | Just connect your Android device to your computer and browse the SD card / External Storage folder "/broadlink/newremote/SharedData/" 8 | You need to get the following files: 9 | 10 | jsonSubIr 11 | jsonButton 12 | jsonIrCode 13 | 14 | and put them in the same folder as this script. 15 | 16 | run: python getBroadlinkSharedData.py 17 | 18 | or duplicate code by number 19 | 20 | python getBroadlinkSharedData.py 5 21 | 22 | ''' 23 | 24 | import base64, sys 25 | 26 | try: 27 | # Python 2.6+ 28 | import json 29 | except ImportError: 30 | try: 31 | # from http://code.google.com/p/simplejson 32 | import simplejson as json 33 | except ImportError: 34 | json = None 35 | 36 | if json is None: 37 | 38 | def dump_json(x, indent=None): 39 | """dumb not safe! 40 | Works for the purposes of this specific script as quotes never 41 | appear in data set. 42 | 43 | Parameter indent ignored""" 44 | if indent: 45 | result = pprint.pformat(x, indent) 46 | else: 47 | result = repr(x).replace("'", '"') 48 | return result 49 | 50 | def load_json(x): 51 | """dumb not safe! Works for the purposes of this specific script""" 52 | x = x.replace('\r', '') 53 | return eval(x) 54 | else: 55 | dump_json = json.dumps 56 | load_json = json.loads 57 | 58 | 59 | IS_PY2 = sys.version_info[0] == 2 60 | 61 | def hex2bin(x): 62 | if IS_PY2: 63 | return x.decode('hex') 64 | else: 65 | return bytes.fromhex(x) 66 | 67 | 68 | if len(sys.argv) > 1: 69 | MultipleCode = sys.argv[1] 70 | else: 71 | MultipleCode = "1" 72 | 73 | 74 | buttonIDS = [] 75 | buttonNames = [] 76 | 77 | 78 | jsonSubIr = open("jsonSubIr").read() 79 | jsonSubIrData = load_json(jsonSubIr) 80 | 81 | 82 | 83 | for i in range(0, len(jsonSubIrData)): 84 | print("ID:", jsonSubIrData[i]['id'], "| Name:", jsonSubIrData[i]['name']) 85 | 86 | 87 | choice = input("Select accessory ID: ") 88 | choice = int(choice) 89 | 90 | for i in range(0, len(jsonSubIrData)): 91 | if jsonSubIrData[i]['id'] == choice: 92 | accessory_name = jsonSubIrData[i]['name'] 93 | print("[+] You selected: ", accessory_name) 94 | 95 | 96 | jsonButton = open("jsonButton").read() 97 | jsonButtonData = load_json(jsonButton) 98 | 99 | 100 | for i in range(0, len(jsonButtonData)): 101 | if jsonButtonData[i]['subIRId'] == choice: 102 | buttonIDS.append(jsonButtonData[i]['id']) 103 | buttonNames.append(jsonButtonData[i]['name']) 104 | 105 | 106 | jsonIrCode = open("jsonIrCode").read() 107 | jsonIrCodeData = load_json(jsonIrCode) 108 | 109 | 110 | print("[+] Dumping codes to " + accessory_name + ".txt") 111 | codesFile = open(accessory_name + '.txt', 'wb') 112 | 113 | for i in range(0, len(jsonIrCodeData)): 114 | for j in range(0, len(buttonIDS)): 115 | if jsonIrCodeData[i]['buttonId'] == buttonIDS[j]: 116 | code = ''.join('%02x' % (i & 0xff) for i in jsonIrCodeData[i]['code']) * int(MultipleCode) 117 | code_bytes = hex2bin(code) 118 | code_base64 = base64.b64encode(code_bytes) 119 | code_base64 = code_base64.decode('utf-8') 120 | result = "Button Name: " + buttonNames[j] + "\r\n" + "Button ID: " + str(jsonIrCodeData[i]['buttonId']) + "\r\n" + "Code: " + code + "\r\n" + "Base64: " + "\r\n" + code_base64 + "\r\n" 121 | codesFile.write(result.encode('utf-8')) 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | https://github.com/clach04/Broadlink-e-control-db-dump 4 | 5 | Python 3.x and 2.7 scripts for processing data for BroadLink InfraRed / IR devices like the BroadLink New RM Mini3 IR Control Hub ,Smart Home Wi-Fi Enabled Infrared Universal Remote Control, One for All Control 6 | 7 | Friendly fork of https://github.com/NightRang3r/Broadlink-e-control-db-dump - pending merges of PRs 8 | 9 | Multiple scripts available, getBroadlinkSharedData.py is likely the most useful for regular Android users. 10 | Related project https://github.com/mjg59/python-broadlink 11 | 12 | # getBroadlinkSharedData.py 13 | 14 | This script will "parse" the broadlink e-Control Android application **"SharedData"** json files and dump the IR / RF codes (in HEX format) for selected accessories into a text file which can be later used with broadlink-python to send the codes to the RM PRO hub 15 | 16 | **NO ROOT ACCESS REQUIRED** 17 | 18 | Just connect your Android device to your computer and browse the SD card / External Storage folder "/broadlink/newremote/SharedData/" 19 | You need to get the following files: 20 | 21 | jsonSubIr 22 | 23 | jsonButton 24 | 25 | jsonIrCode 26 | 27 | and put them in the same folder as this script. 28 | 29 | ##### *** If you can't find the following files on your phone storage You may need to open the e-control app and on the left side menu choose "Share" and then "Share to other phones in WLAN" it should generate the files. *** 30 | 31 | run: `~# python getBroadlinkSharedData.py` 32 | 33 | or duplicate code by number 34 | 35 | `~# python getBroadlinkSharedData.py 5` 36 | 37 | ### Requirements 38 | 39 | simplejson 40 | 41 | `~# pip install simplejson` 42 | 43 | # sendCode.py 44 | 45 | This is a script you can use to test that your codes are working, It will send the command to the RM Pro 46 | You will need the python-broadlink library for the script to work. 47 | 48 | 49 |
~# git clone https://github.com/mjg59/python-broadlink.git50 | 51 |
~# sudo python setup.py install52 | 53 | You will also need to edit the script `line 6` with your RM Pro IP Address and MAC Address and `line 17` with the code in hex format (Which can be produced by "econtrol-db-dump.py" and "getBroadlinkSharedData.py"). 54 | 55 | 56 | # econtrol-db-dump.py 57 | 58 | This script will "parse" the broadlink e-Control Android application **rmt.db database** and dump the IR / RF codes (in HEX format) for selected accessories into a text file which can be later used with broadlink-python to send the codes to the RM PRO hub. 59 | 60 | You need to get the "rmt.db" file from your android device or emulator (ARM), 61 | 62 | **ROOT ACCESS REQUIRED** 63 | 64 | the file is located in "/data/data/com.broadlink.rmt/databases/rmt.db" and put it in the same folder as this script. 65 | 66 |
~# adb pull /data/data/com.broadlink.rmt/databases/rmt.db67 | 68 | 69 | # FOR TC2 RF SWITCHES 70 | 71 | In case you get the following error: `Input strings must be a multiple of 16 in length` when sending the TC2 codes you dumped from the DB you will have to do the following: 72 | 73 | Try sending the code one time using the "sendCode.py" script: 74 | 75 | e.g: 76 | `e90a4200df0909161609160909160916091609160916160909160916091609160916091609161609091609160916160916090916091609160916091616091609160909160916` 77 | 78 | If it is not working and you get the `Input strings must be a multiple of 16 in length` error again, try to duplicate it twice: 79 | 80 | e.g: 81 | `e90a4200df0909161609160909160916091609160916160909160916091609160916091609161609091609160916160916090916091609160916091616091609160909160916e90a4200df0909161609160909160916091609160916160909160916091609160916091609161609091609160916160916090916091609160916091616091609160909160916` 82 | 83 | If not working keep going 3,4,5,6 time until it works with the script. 84 | 85 | # broadlink_to_home_assistant_encoder.py 86 | 87 | This script will output the codes in a format that will work with home assistant 88 | 89 | `~# broadlink_to_home_assistant_encoder.py "packet"` 90 | 91 | `~# broadlink_to_home_assistant_encoder.py e90a4200df0909161609160909160916091609160916160909160916091609160916091609161609091609160916160916090916091609160916091616091609160909160916e90a4200df0909161609160909160916091609160916160909160916091609160916091609161609091609160916160916090916091609160916091616091609160909160916` 92 | --------------------------------------------------------------------------------