Broadlink e-control to yaml

if you have followed the instructions for broadlinkswitch you have a dir where you have a file called getBroadlinkSharedData.py
just save the file i created with the same name and run it like keith said.
so you need to have the e control files in the same directory.

Yes, i read it… but i dont know how to run PY script :slight_smile: i just google it.

Thanks Rene.

io get error what i miss?

C:\python\br>py getBroalinkSharedData.py
File “getBroalinkSharedData.py”, line 32
print “ID:”, jsonSubIrData[i][‘id’], “| Name:”, jsonSubIrData[i][‘name’]
^
SyntaxError: Missing parentheses in call to ‘print’

you probably tried to run it in python 3 and it is written for python 2.

so your command would be:

python2 getBroadlinkSharedData.py 

You’re missing a “d” :wink:

probably he saved it without the d also, because the code is running :wink:
i made a typo before :wink:

rewritten code for python 3 for those who prefer to use python 3 and not python 2

# -*- 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: ")

accessory_name = jsonSubIrData[int(choice)-1]['name']
print ("[+] You selected: ", accessory_name)

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: " + str(buttonNames[j]) + " | Button ID: " + str(jsonIrCodeData[i]['buttonId']) + " | Code: " + str(code)
            namepart = buttonNames[j].replace(" ","_")
            yamltext = yamltext + "      " + accessory_name + "_" + namepart + ":\n"
            yamltext = yamltext + "        friendly_name: " + accessory_name + " " + buttonNames[j] + "\n"
            yamltext = yamltext + "        command_on: '" + str(code_b64[:-1]) + "'" + "\n"
            groupstext = groupstext + "      - switch." + accessory_name + "_" + namepart + "\n"
            codesFile.writelines(result)
yamlFile.writelines(yamltext)
yamlFile.writelines(groupstext)
1 Like

i just google it and install via pip now that working :slight_smile:

1 Like

I think you need to install simplejson, something like sudo apt-get install simplejson, you may want to google that as i’m doing this off the top of my head :slight_smile:

i just tried to add some more remotes.

some things to think about:

  1. dont use spaces in the names from the econtrol remote, or replace them in the yaml afterwards with _
  2. Capitals are somehow not allowed in the naming from the entities, so dont use them in econtrol either.
  3. if you delete remotes from econtrol, the python3 version will have trouble finding some remotes. python2 works fine.

if there is enough reason for it i will try to change the code some more to take these problems out, automaticly.

Work with pip install simplejson via Scripts folder :slight_smile:

How do i know what is the command to on / off tv?
i get like this

switches:
  Audio_:
    friendly_name: Audio 
    command_on: 'JgBOACETExMTMhMyExMTMhMTEzITExMyEzIUAAEpIRMTExMyEzITExMyExMTMhMTEzITMhQAASkh

ExMTEzITMhMTEzITExMyExMTMhMyFAAIBQ==’
Audio_:
friendly_name: Audio
command_on: ‘JgBOACETEyUTExMdEyUTExMTEyUTExMdEyUUAAEpIRMTJRMTEx0TJRMTExMTJRMTEx0TJRQAASkh
ExMlExMTHRMlExMTExMlExMTHRMlFAAIBQ==’

also what is worng here? im on this more then 1H Thanks!

in the picture you show a invalid yaml.

you need to look at your spaces.

switches (beneath mac) needs to have 2 spaces more then mac.
reciever needs needs 2 more
friendlyname needs 2 more then tv_phillips. (not 1)

so every time 2 more spaces.

Hi Rene,

I hope you don’t mind my very simple question, I have no programming experience at all. I have two Broadlink RM Pro which control 7 devices, both IR and RF. I want to use home assistant with Alexa to control them. Before I purchase a RP3+ I decided to try out HA on a windows 10 PC. I have installed python 3, simplejson and downloaded the eControl scripts. I have copied my shared data from the eControl app to the same folder and I have created the getBroadlinkSharedData.py for python 3. I ran the getBroadlinkSharedData.py i get a list of the remotes I have created and it asks me to select one. I select one of the ID’s and it appears to create a tXT and YAML file but none of them contain any code. Can you help me where I am going wrong?

C:\Users\julie\AppData\Roaming.homeassistant\Broadlink-e-control-db-dump-master>getBroadlinkSharedData.py
ID: 13 | Name: Soundbar
ID: 14 | Name: TV-lights
ID: 16 | Name: power-remote
ID: 19 | Name: TV
ID: 21 | Name: Android TV
ID: 22 | Name: Sky Q
ID: 23 | Name: An RF Switch
Select accessory ID: 4
[+] You selected: TV
[+] Dumping HEX codes to TV.txt
[+] Dumping yaml to TV.yaml

This is the YAML file I get

switches:

group:
TV:
name: TV
view: yes
entities:

The text file is empty.

Thank you

i havent used that code for a long time so i dont know what is wrong.
i see you selected ID 4 and the valid IDs shown are 13,14,16,19,21,22,23
but it selected TV on ID 19

so i am a bit puzzled.
at the moment i cant look at it, but please remind me tommorow and i will take a look what could be wrong.

Thanks,

I did wonder about the numbering, if I enter the listed number it doesn’t work. If i use 1 for the top one I get the empty files. I’ll clear the data on the broadlink app and try adding just one remote and see if I get index 1.

If I can’t sort it I’ll post back here tomorrow.

Paul

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.