Broadlink e-control to yaml

What directory are you in when you do python3 getBroadlinkSharedData.py?

I think root.

maybe I have to do:
cd /home/homeassistant/.homeassistat/Broadlink-econtro-db-dump-master…and then run the command??

…I’m going to try.

1 Like

That would be correct or you can put in the full pathname before the broadlink.py filename :slight_smile:

WOW…Now working…Thanks a lot for your time.

No worries glad you have it working :slight_smile:

1 Like

Are there some remote controls that cannot be added to home assistant or maybe even the broad link device?

I struggled with one remote for an Arlec Air Conditioner, I captured multiple clicks off the remote and compared them and they are quite different.

Output from script for the same button (which has worked great for other devices, thanks)

  kitchenfan_kitchenlight:
    friendly_name: kitchenfan kitchenlight
    command_on: 'JgAnAAkHGgcaBxoHGhgJBxoIGhgJBwABFgcaGQkGGxgJBxoYCQcaCAANBQA='
  kitchenfan_kitchenlight2:
    friendly_name: kitchenfan kitchenlight2
    command_on: 'JgAjABgICBoZCAcaGQgIGgcaBxoHGggZGQkHGgcaBxoIAAE/AA0FAAAAAAA='
  kitchenfan_kitchenlight3:
    friendly_name: kitchenfan kitchenlight3
    command_on: 'JgAkAAgHGhgJBxoZCAgZCBoHGgcaBxoZCAgaBxkIGgcaBQABPgANBQAAAAA='
  kitchenfan_kitchenlight4:
    friendly_name: kitchenfan kitchenlight4
    command_on: 'JgAkAAgHGgcaBxoIGQgZGggIGQgZCBoHGhkIBxoIGRkICAABQgANBQAAAAA='

Thanks.

I think some use a rolling code, so those won’t work :frowning:

That sounds likely, thanks.

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()

2 Likes

thx. i did rewrite that code in the beginning from my python learning.
and because i didnt use it much after that i never bothered to make it better.

Hello guys!

I’ve compiled this Python script into an executable Windows program for easy of use. You don’t even need Python installed on the machine.

Here is a video showing how it works: https://photos.app.goo.gl/jzd6cGrGfWnRnQUn9

Here is the program: https://mega.nz/#!7N91xabJ!NXVBw6tSe8RIoCVaULGB5rJ5uUB8nsWTR4nJPgrBLC8

VirusTotal results (just for peace of mind, you can create your own if you want :slight_smile:): https://www.virustotal.com/#/file/51a37eb2e022a939831636619505ec04a076fa3d24a3bb4f4ae4898c06e6c090/detection

You just need to copy the files jsonSubIr, jsonButton and jsonIrCode from the Android phone, located on “/broadlink/newremote/SharedData/”.

Used this method to compile the program: https://www.youtube.com/watch?v=OZSZHmWSOeM

I hope it helps!

7 Likes

Just gave it a try and a BIG thanks to you. Worked like a charm.

1 Like

Funcionou que é uma beleza… Valeu!

1 Like

any one have idea what this issue?
image

same problem for me under windows 10… have you solved?

Can someone help me to extract a RF code? I can’ run in win10 and I get error also under rasbian.

Traceback (most recent call last):
File “getBroadlinkSharedData.py”, line 39, in
jsonSubIrData = json.loads(jsonSubIr)
File “/home/pi/.local/lib/python2.7/site-packages/simplejson/init.py”, line 518, in loads
return _default_decoder.decode(s)
File “/home/pi/.local/lib/python2.7/site-packages/simplejson/decoder.py”, line 373, in decode
raise JSONDecodeError(“Extra data”, s, end, len(s))
simplejson.errors.JSONDecodeError: Extra data: line 1 column 3 - line 1 column 24 (char 2 - 23)

This is my files:
https://we.tl/t-JVRiXw54x3
It’s only a RF command

I’ve had success using the method described here.

Thankyou it works!

Updated code that supports recent updates of broadlink plugin:

# -*- 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


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'] == choice:
        accessory_name = jsonSubIrData[i]['name']
        print "[+] You selected: ", accessory_name


jsonButton = open("jsonButton").read()
jsonButtonData = json.loads(jsonButton)


for i in range(0, len(jsonButtonData)):
    if jsonButtonData[i]['subIRId'] == choice:
        buttonIDS.append(jsonButtonData[i]['id'])
        buttonNames.append(jsonButtonData[i]['name'])


jsonIrCode = open("jsonIrCode").read()
jsonIrCodeData = json.loads(jsonIrCode)


print "[+] Dumping 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 = code.decode("hex").encode("base64")
            result = "Button Name: " + buttonNames[j] + " | Button ID: " + str(jsonIrCodeData[i]['buttonId']) + " | Code: " + code
            namepart = buttonNames[j].strip().replace(" ","_")
            yamltext = yamltext + "      - name: " + accessory_name.replace(" ","_") + "_" + namepart + "\n"
#             yamltext = yamltext + "        friendly_name: " + accessory_name + " " + buttonNames[j] + "\n"
            yamltext = yamltext + "        command_on: '" + code_b64[:-1] + "'" + "\n"
            groupstext = groupstext + "      - switch." + accessory_name.replace(" ","_") + "_" + namepart + "\n"
            codesFile.writelines(result.encode('utf-8'))
yamlFile.writelines(yamltext.encode('utf-8'))
yamlFile.writelines(groupstext.encode('utf-8'))

1 Like

Is it possible to use this approach for getting the codes from the newer Broadlink app e.g. not the e control app?
I am having problems connecting my Broadlink RM to e control for some reason.
I looked in the Broadlink folder for the Broadlink app on my phone and can see similar files but they are empty. e.g. jsonSubIr, jsonButton and jsonIrCode

1 Like