├── README.md ├── broadlink_to_home_assistant_encoder.py ├── econtrol-db-dump.py ├── getBroadlinkSharedData.py └── sendCode.py /README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | # * All Scripts are written using python 2.7 4 | 5 | # econtrol-db-dump.py 6 | 7 | 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. 8 | 9 | You need to get the "rmt.db" file from your android device or emulator (ARM), 10 | 11 | **ROOT ACCESS REQUIRED** 12 | 13 | the file is located in "/data/data/com.broadlink.rmt/databases/rmt.db" and put it in the same folder as this script. 14 | 15 |
 ~# adb pull /data/data/com.broadlink.rmt/databases/rmt.db 
16 | 17 | # getBroadlinkSharedData.py 18 | 19 | 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 20 | 21 | **NO ROOT ACCESS REQUIRED** 22 | 23 | Just connect your Android device to your computer and browse the SD card / External Storage folder "/broadlink/newremote/SharedData/" 24 | You need to get the following files: 25 | 26 | jsonSubIr 27 | 28 | jsonButton 29 | 30 | jsonIrCode 31 | 32 | and put them in the same folder as this script. 33 | 34 | ##### *** 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. *** 35 | 36 | run: `~# python getBroadlinkSharedData.py` 37 | 38 | or duplicate code by number 39 | 40 | `~# python getBroadlinkSharedData.py 5` 41 | 42 | ### Requirements 43 | 44 | simplejson 45 | 46 | `~# pip install simplejson` 47 | 48 | 49 | 50 | # sendCode.py 51 | 52 | This is a script you can use to test that your codes are working, It will send the command to the RM Pro 53 | You will need the python-broadlink library for the script to work. 54 | 55 | 56 |
~# git clone https://github.com/mjg59/python-broadlink.git
57 | 58 |
~# sudo python setup.py install
59 | 60 | 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"). 61 | 62 | 63 | # FOR TC2 RF SWITCHES 64 | 65 | 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: 66 | 67 | Try sending the code one time using the "sendCode.py" script: 68 | 69 | e.g: 70 | `e90a4200df0909161609160909160916091609160916160909160916091609160916091609161609091609160916160916090916091609160916091616091609160909160916` 71 | 72 | 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: 73 | 74 | e.g: 75 | `e90a4200df0909161609160909160916091609160916160909160916091609160916091609161609091609160916160916090916091609160916091616091609160909160916e90a4200df0909161609160909160916091609160916160909160916091609160916091609161609091609160916160916090916091609160916091616091609160909160916` 76 | 77 | If not working keep going 3,4,5,6 time until it works with the script. 78 | 79 | # broadlink_to_home_assistant_encoder.py 80 | 81 | This script will output the codes in a format that will work with home assistant 82 | 83 | `~# broadlink_to_home_assistant_encoder.py "packet"` 84 | 85 | `~# broadlink_to_home_assistant_encoder.py e90a4200df0909161609160909160916091609160916160909160916091609160916091609161609091609160916160916090916091609160916091616091609160909160916e90a4200df0909161609160909160916091609160916160909160916091609160916091609161609091609160916160916090916091609160916091616091609160909160916` 86 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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 simplejson as json 25 | import base64, sys 26 | 27 | 28 | if len(sys.argv) > 1: 29 | MultipleCode = sys.argv[1] 30 | else: 31 | MultipleCode = "1" 32 | 33 | 34 | buttonIDS = [] 35 | buttonNames = [] 36 | 37 | 38 | jsonSubIr = open("jsonSubIr").read() 39 | jsonSubIrData = json.loads(jsonSubIr) 40 | 41 | 42 | for i in range(0, len(jsonSubIrData)): 43 | print "ID:", jsonSubIrData[i]['id'], "| Name:", jsonSubIrData[i]['name'] 44 | 45 | 46 | choice = input("Select accessory ID: ") 47 | 48 | for i in range(0, len(jsonSubIrData)): 49 | if jsonSubIrData[i]['id'] == choice: 50 | accessory_name = jsonSubIrData[i]['name'] 51 | print "[+] You selected: ", accessory_name 52 | 53 | 54 | jsonButton = open("jsonButton").read() 55 | jsonButtonData = json.loads(jsonButton) 56 | 57 | 58 | for i in range(0, len(jsonButtonData)): 59 | if jsonButtonData[i]['subIRId'] == choice: 60 | buttonIDS.append(jsonButtonData[i]['id']) 61 | buttonNames.append(jsonButtonData[i]['name']) 62 | 63 | 64 | jsonIrCode = open("jsonIrCode").read() 65 | jsonIrCodeData = json.loads(jsonIrCode) 66 | 67 | 68 | print "[+] Dumping codes to " + accessory_name + ".txt" 69 | codesFile = open(accessory_name + '.txt', 'w') 70 | 71 | for i in range(0, len(jsonIrCodeData)): 72 | for j in range(0, len(buttonIDS)): 73 | if jsonIrCodeData[i]['buttonId'] == buttonIDS[j]: 74 | code = ''.join('%02x' % (i & 0xff) for i in jsonIrCodeData[i]['code']) * int(MultipleCode) 75 | code_base64 = code.decode("hex").encode("base64") 76 | 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" 77 | codesFile.writelines(result.encode('utf-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...." --------------------------------------------------------------------------------