recently i bought a broadlink device.
and then i started to connect my remotes to the app so that my wife can control everything.
off course i liked to connect it all to HA as well.
i tried the broadlink learn command. it works but it isnt an easy way.
then i tried the part where you can import the codes from e-control into a txt file.
it bugged me that after that i needed to translate every code from hex to base 64.
so i changed the getBroadlinkSharedData.py a little.
now it also gives output from a yaml file like this:
switches:
kaarsen_aan:
friendly_name: kaarsen aan
command_on: 'JgDoAAABLZQTExQSExMUExMTExMTFBM2EzcTNxQ1FDYTNxQ1EzcUEhQTFDUUExMTEzcTExMTExMT
NxMTEzcTNxMTFDYUNRM3EwAFDwABLEkUAAxNAAEtSRMADE4AAStKFAAMTQABLEoTAAxOAAErShQA
DE0AASxJFQAMTQABLEkUAAxOAAErShMADE8AAStKEwAMTgABLUkSAAxPAAEsSRQADE4AAStKEwAM
TwABK0oTAAxPAAErShMADE0AAS5JEgAMTwABLEkVAAxNAAEsSRMADE8AAStKFAAMTgABLEkUAAxO
AAErShMADQU='
kaarsen_uit:
friendly_name: kaarsen uit
command_on: 'JgDoAAABLZQTExMTExQTExMTExMTFBM2EzcTNxM3EzYTNxM3EzcTExMTEzcUEhM3EzcTExMTExQT
NhMUEzYTFBMTEzcTNhM3EwAFEQABLUoTAAxVAAEuSRMADFUAAS1KEwAMVQABLEkTAAxVAAEsShMA
DFUAASxJFAAMVAABLEoTAAxVAAEtShMADFQAAS5KEwAMVAABLkkUAAxUAAEtShMADFQAAS1KEwAM
VAABLUkTAAxVAAEtSRMADFUAASxKEwAMVAABLUkUAAxUAAEsShMADFUAAS1JEwAMVQABLEoTAAxU
AAEtShMADQU='
kaarsen_Mode:
friendly_name: kaarsen Mode
command_on: 'JgCgAAABL5QUExMTExMUExQSExQTExM3EzcTNxQ2EzcTNxM2FDYTFBMTEzcTNxM3FDYTExMTFBMT
NxQSExQTExMUEzYUNhM3EwAFEQABLkoTAAxUAAEuShMADFQAAS5KEwAMVAABLkoUAAxUAAEuShMA
DFQAAS1KEwAMVAABLUoTAAxUAAEuSRQADFQAAS5JEwAMVQABLkoUAAxTAAEvSRQADQUAAAAAAAAA
AA=='
kaarsen_4h:
friendly_name: kaarsen 4h
command_on: 'JgCIAAABLpQTExMUExMTFBQSExMTFBM3EzYTNxM3EzcTNxM3EzYTFBM3ExMTExMUExMTExMUExMT
FBM2EzcTNxM3EzcTNhM3EwAFEQABLkoTAAxUAAEtSRMADFQAAS1KFAAMUwABLUkUAAxUAAEtShMA
DFQAAS5KEwAMVAABLUoTAAxUAAEsShMADQU='
kaarsen_8h:
friendly_name: kaarsen 8h
command_on: 'JgCYAAABLZQTExMUExMTExMUExMTExM3EzcTNxM2EzcTNxM3EzcTExMTEzcTExMUExMTExMUExMT
NxMTEzcTNhQ2EzcTNxM3EwAFEQABLEoTAAxWAAEsShMADFUAASxKEwAMVgABK0oTAAxWAAEsShMA
DFUAASxKEwAMVgABLEkTAAxWAAEsShMADFYAASxKEwAMVgABLEkTAA0F'
kaarsen_Multi_color:
friendly_name: kaarsen Multi color
command_on: 'JgCQAAABLpQUExMTExMTFBMTExQTExM3EzcTNhM3EzcTNxM3EzcTExQ2EzcTExMTFBMTExMUExMT
ExMUEzcTNhM3EzYVNhM3EwAFEQABLkoTAAxVAAEuShMADFUAAS5JEwAMVQABLkoTAAxVAAEuSBUA
DFUAAS5KFAAMVQABLUoTAAxWAAEuSRMADFYAAS1KFAANBQAAAAAAAAAA'
kaarsen_rood:
friendly_name: kaarsen rood
command_on: 'JgCYAAABLZQUEhQTExMTFBMTExMTFBM2FDYTNxM3EzcTNxM2EzcTFBMTExMTNxMTFBMTExMUExMT
NxM3ExMTNxQ2EzcTNhM3EwAFEgABLkkTAAxVAAEuSRMADFUAAS5JEwAMVgABLEoTAAxWAAEsShMA
DFUAAS1KEwAMVgABLEoTAAxVAAEsShMADFYAASxKEwAMVQABLEoTAA0F'
kaarsen_blauw:
friendly_name: kaarsen blauw
command_on: 'JgBYAAABLZQUExMTExQSFBMTExQTExQ2FDUTNxM3EzcTNxM2EzcTExMUEzYTNxMUEhQTExMTExQT
NhQTExMTNxM3EzYTNxM3EwAFEQABLUkTAAxWAAEsShMADQU='
kaarsen_groen:
friendly_name: kaarsen groen
command_on: 'JgBgAAABLJQUExMTExMTFBMTExMTFBM3EjcTNxM3EzcTNhM3EzcTExM3FBMTNhMUExMTExMUExMT
ExM3FBMTNhM3FDYTNxQ2EwAFEQABLUoTAAxWAAEtShQADFUAAS1JEwANBQAAAAAAAAAA'
kaarsen_blauw:
friendly_name: kaarsen blauw
command_on: 'JgB4AAABLZQUEhMTExQTExMTExQSFBM3EjcUNhM3EzYTNxM3EzcTExM3ExMTExM3ExMTExMUExMT
ExM3EzcTExM3EzYTNxM3EwAFEQABLEoTAAxUAAEsShQADFMAASxKEwAMVAABLEoTAAxUAAEsShMA
DFMAASxKEwANBQ=='
kaarsen_bruin:
friendly_name: kaarsen bruin
command_on: 'JgCQAAABLZQTExMUExMTExMTExQTExM3EzcTNhM3EzcTNxM2EzcTExM3EzcTNxMTExMTExMUExMT
ExMUExMTNxM2EzcTNxM3EwAFEAABLEoTAAxTAAEtShMADFQAAS1JEwAMUwABLUoTAAxTAAEtShQA
DFQAAS1JEwAMUgABLUoTAAxSAAEsShMADFIAASxJEwANBQAAAAAAAAAA'
kaarsen_groen:
friendly_name: kaarsen groen
command_on: 'JgB4AAABLpMUExMTExMTFBMTExMTFBM2EzcTNxM2FDYTNxM3EzcTExMTExQTExM3ExMTExQTExMT
NxM3EzYUExM2FDYTNxM3EwAFDwABLkkUAAxQAAEuSRMADFIAAS5KEwAMUQABLkoTAAxRAAEuShMA
DFEAASxKEwANBQ=='
kaarsen_geel:
friendly_name: kaarsen geel
command_on: 'JgCQAAABLpMUExMTExMTFBMTExMTFBM2EzYUNxM2EzcTNxM2EzcTExMUEzYTFBM2FBMTExMTExMT
NxMTEzcTExM3EzcTNxM2EwAFEAABLUoTAAxTAAEuSRQADFIAAS5KEwAMUgABLUkUAAxPAAEuSRMA
DFAAAS1KEwAMTwABLUoTAAxQAAEtShMADFAAASxKEwANBQAAAAAAAAAA'
kaarsen_paars:
friendly_name: kaarsen paars
command_on: 'JgCYAAABLJQTExMTExMUEhMUExMUEhM3EzYTNxQ2EjcUNhM2FDYTExMTEzcUNhI3ExMTFBMTExMT
NxQSExMTExM3EzcUNRM3EwAFDwABLEoTAAxPAAErShMADFAAAS1JEwAMUAABLUkTAAxQAAEsShMA
DE8AASxKEwAMTwABLUoTAAxPAAEuSRMADFAAAS1JFAAMUAABLkoTAA0F'
kaarsen_roze:
friendly_name: kaarsen roze
command_on: 'JgCIAAABMJMTExQTExMTExMUExMTExQ2EzcTNhQ2EzcUNhM2EzcTExMUExMTNxM3ExMTExMUExMT
NxQ1FBMTExM3EzcTNhM3EwAFEAABLkoUAAxXAAEuSRMADFMAAS9KFAAMUAABLUoTAAxQAAEtShMA
DFAAAS5JEwAMUAABL0kTAAxTAAEtShQADQU='
kaarsen_blauw:
friendly_name: kaarsen blauw
command_on: 'JgCgAAABLZMTExQTExMTFBMTExMTFBM2EzcUNhM3EzYTNxM3EzcUEhM3ExMTNxM3ExMTExQTFBIT
FBM2ExQTExM3EzYTNxM3EwAFDwABLEoTAAxRAAErShQADFMAAStKEwAMUgABLUoTAAxWAAEvShMA
DFMAAS5KEwAMUQABL0kTAAxQAAEuSRMADFYAAS9IEwAMVwABLkoTAAxQAAEtShQADQUAAAAAAAAA
AA=='
kaarsen_blauw:
friendly_name: kaarsen blauw
command_on: 'JgCgAAABLZQTExMTExMTFBMTFBITFBI3EzcTNxM2EzcTNxM2FDYTExM3EzYTFBM2EzcTExMUExMT
ExMTEzcTExMTEzcTNxM2EwAFEQABLkgUAAxXAAEsShMADFwAAS1JEwAMXQABLEoTAAxUAAEuSBMA
DFsAAS1JFAAMWQABLEkTAAxVAAEtSRMADFUAAS1JEwAMUQABLEkTAAxWAAEtShQADQUAAAAAAAAA
AA=='
kaarsen_roze:
friendly_name: kaarsen roze
command_on: 'JgCwAAABLpQTFBMTExQTExMTExQTExM3FDYTNhM3EzcTNxM2EzcTExM3EzcUNhM2FDYTFBMTExMT
FBMTExMUExQSEzcTNxM2EwAFFQABLUoTAAxZAAEuShQADFYAAS9JEwAMVQABLUkTAAxQAAEtSRQA
DFEAASxKEwAMUAABLUkTAAxUAAEuSRMADE8AAS1KEwAMUAABLUoTAAxPAAEsShQADE4AAS1JEwAM
UQABLUkTAA0FAAAAAAAAAAA='
group:
kaarsen:
name: kaarsen
view: yes
entities:
- switch.kaarsen_aan
- switch.kaarsen_uit
- switch.kaarsen_Mode
- switch.kaarsen_4h
- switch.kaarsen_8h
- switch.kaarsen_Multi_color
- switch.kaarsen_rood
- switch.kaarsen_blauw
- switch.kaarsen_groen
- switch.kaarsen_blauw
- switch.kaarsen_bruin
- switch.kaarsen_groen
- switch.kaarsen_geel
- switch.kaarsen_paars
- switch.kaarsen_roze
- switch.kaarsen_blauw
- switch.kaarsen_blauw
- switch.kaarsen_roze
after that all you need to do is check for duplicate names that are not used in HA and you can copy it to your yaml files.
the edited pycode:
# -*- 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].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.encode('utf-8'))
yamlFile.writelines(yamltext.encode('utf-8'))
yamlFile.writelines(groupstext.encode('utf-8'))
there is 1 requirement: you need to give the buttons in e-control a name to get names in the yaml.
off course you could set the names afterwards if you remember the order you have recorded the buttons
hope this helps others.
by the way, the yaml i did put here is from a set of remote candles with a small ir remote.
do have one like this? then you could use this file, just change the names to your wish.
edit: i also let it automaticly create a group fot the remote you import, so that you directly have all switches together in 1 group.