Broadlink e-control to yaml

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.

Paul.

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.

@ReneTode Thanks for the python3 version and outputting directly in YAML!!!
You R0X0r!

1 Like

Hi to All,
I need some help regarding 2 issues:

  1. 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.

try sudo apt-get install python-simplejson

Please show us what you type and what it responds with as well as what’s in the directory that you are in.

1 Like

thanks keithh666…simplejson has been installed.

but I have still the problem to run the command python getBroadlinkSharedData.py

I do from pi@hassbian: $

this is my directory structure (Samba):

…inside Broadlink-econtro-db-dump-master directory
image

Thanks again for your help…
E.

When you type python -V what do you get? or python3 -V

this
image

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