I think I have sorted it, I copied my remotes to the e Control cloud and then deleted the app, reinstalled it and downloaded the remotes from the cloud. I then ran your script and I now have code in each switch. I’m on to the next stage now of how to integrate my Broadlink RMs into HA. Learning as I go.
nicely done!!
all you now need to do is copy that what you have in the yaml into your HA configuration on the right place.
then restart HA and if copied to the right places you have your switches in HA.
I cannot install simplejson. I tried (via SSH) sudo apt-get install simplejson…and pip install simplejson…but the same result …5. Unable to locate package simplejson
Anyway, after move the directory Broadlink-e-control-db-dump-master in the same place where are located the configuration.yaml file…I run > python getBroadlinkSharedData.py…but it seems that i cannot found the file…(cant’t open file …Errno 2 no such file or directory.
I copied correctly the 3 requested files fron android in the same directory of…py file…
Anyone could help me??..i’m no so much expert…maybe I’m wrong in some procedure steps…
Thanks so much.
E.
I was having the same problem as described by Paul. It is caused by some small errors in the code. Below corrected version. In this version you need to select the ID, not the row of the ID.
Good luck!
# -*- coding: utf-8 -*-
'''
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
NO ROOT ACCESS REQUIRED
Just connect your Android device to your computer and browse the SD card / External Storage folder "/broadlink/newremote/SharedData/"
You need to get the following files:
jsonSubIr
jsonButton
jsonIrCode
and put them in the same folder as this script.
run: python getBroadlinkSharedData.py
'''
import simplejson as json
import codecs
buttonIDS = []
buttonNames = []
jsonSubIr = open("jsonSubIr").read()
jsonSubIrData = json.loads(jsonSubIr)
for i in range(0, len(jsonSubIrData)):
print("ID:", jsonSubIrData[i]['id'], "| Name:", jsonSubIrData[i]['name'])
choice = input("Select accessory ID: ")
for i in range(0, len(jsonSubIrData)):
if jsonSubIrData[i]['id'] == int(choice):
accessory_name = jsonSubIrData[i]['name']
print("[+] You selected: ", accessory_name)
break
jsonButton = open("jsonButton").read()
jsonButtonData = json.loads(jsonButton)
for i in range(0, len(jsonButtonData)):
if str(jsonButtonData[i]['subIRId']) == str(choice):
buttonIDS.append(jsonButtonData[i]['id'])
buttonNames.append(jsonButtonData[i]['name'])
jsonIrCode = open("jsonIrCode").read()
jsonIrCodeData = json.loads(jsonIrCode)
print ("[+] Dumping HEX codes to " + accessory_name + ".txt")
print ("[+] Dumping yaml to " + accessory_name + ".yaml")
codesFile = open(accessory_name + '.txt', 'w')
yamlFile = open(accessory_name + '.yaml', 'w')
groupstext = "\n\n\ngroup:\n"
groupstext = groupstext + " " + accessory_name + ":\n"
groupstext = groupstext + " name: " + accessory_name + "\n"
groupstext = groupstext + " view: yes\n"
groupstext = groupstext + " entities:\n"
yamltext = " switches:\n"
for i in range(0, len(jsonIrCodeData)):
for j in range(0, len(buttonIDS)):
if jsonIrCodeData[i]['buttonId'] == buttonIDS[j]:
code = ''.join('%02x' % (i & 0xff) for i in jsonIrCodeData[i]['code'])
code_b64 = codecs.encode(codecs.decode(code, 'hex'), 'base64').decode()
result = "Button Name: " + buttonNames[j] + " | Button ID: " + str(jsonIrCodeData[i]['buttonId']) + " | Code: " + code
namepart = buttonNames[j].replace(" ","_")
yamltext = yamltext + " " + accessory_name + "_" + namepart + ":\n"
yamltext = yamltext + " friendly_name: " + accessory_name + " " + buttonNames[j] + "\n"
yamltext = yamltext + " command_on: '" + code_b64[:-1] + "'" + "\n"
groupstext = groupstext + " - switch." + accessory_name + "_" + namepart + "\n"
codesFile.writelines(result)
codesFile.close()
yamlFile.writelines(yamltext)
yamlFile.writelines(groupstext)
yamlFile.close()