broadlink integration into Domoticz
- 1 Broadlink RM2
- 2 Installation
- 3 Configuration
- 4 User Guide
- 5 Technical information
This is the integration of the broadlink python project into Domoticz. Python module for controlling Broadlink RM2/3 (Pro) remote controls.
Main goal is to have broadlink device integrated into Domoticz, with no necessity to have any other gateway. You can learn, test and send learned code, all done from Domoticz GUI interface.Now, you can also Import code learned by e-Controll app or other Domoticz server. GUI Remote control available (like Kodi) and full customizable.
For Windows users
Download Setup.exe  ( setup.exe /? for more options )
Run it as Administrator-- if something goes wrong screen will become "Red"
The download link provide to you all sources & necessary files.
pip3 install broadlink --> mandatory
pip3 install pycrypto --> no more mandatory, pyaes will be used instead
download plugin.py 
download plugin_send.py 
download plugin_http.py 
download plugin_http.sh 
See technical area on what is necessary.
Once all is ok, restart Domoticz
Python version 3.x required & Domoticz version 3.8xxx or greater.
go to Domoticz / Setup / Hardware and select Broadlink RM2 with Kodi Remote
for the configuration, lets focus on specific parameters to this plugin, for others, see Domoticz documentation.
- Name: Hardware name to give
- IP Address : IP address of your Broadlink RM2 device. Need to be static
- Mac : mac address of Broadlink device
- Folder to store ini files: full path where ini files will be created
- Get temperature device : if you want to see/follow the temperature provided by the built-in sensor
- Generate import Device : this will create device to manage import from e-control app or similar ini file
- Port for HTTP server : this is the port used to create mini Web server to help uploading files, default to 9000
- Debug : False or True, this will put lots of informations into Domoticz log, use it for testing only. On production put it to False.
First Time Users
If you don't know the IP address of your device, a built-in discovery process can help you. For that, just create the new Hardware with all values by default for IP address and mac e.g. 127.0.0.1 & 0000000000.
Go to switches tab, you can see one new device created e.g. 'My br' - Discover
Switch On the device will initiate the discovery process. If nothing is found the device will stay on Off, verify your network connection. When found one or more Broadlink device, this will be indicated on the Domoticz device status:
If you go to the log Tab, you will see detailed information :
2017-03-26 18:33:34.215 User: Admin initiated a switch command (672/My br - Discover/On)
2017-03-26 18:33:34.241 (My br) Calling message handler 'onCommand'.
2017-03-26 18:33:34.241 (My br) onCommand called for Unit 1: Parameter 'On', Level: 0 , Connected : False
2017-03-26 18:33:34.241 (My br) All plugin system is on pause for 5s...
2017-03-26 18:33:39.242 (My br) Found 1 broadlink devices
2017-03-26 18:33:39.277 (My br) Device 1 Host address = '192.168.Y.XX', 80
2017-03-26 18:33:39.278 (My br) Device 1 MAC address = b3330ddd260b
2017-03-26 18:33:39.278 (My br - Discover) Updating device from 0:'Off' to have values 1:'Found : 1 device'.
2017-03-26 18:33:39.377 (My br) Update 1:'Found : 1 device' (My br - Discover)
Take note of the IP address and mac, so you can entered them into the configuration page and click on Update (Not Add)
NOTA: you need to remove by yourself this Discover device, otherwise the general ones would not be created.
In Domoticz, if you go to Switches, you will found 1 or more devices created and at your disposal.
- xxx- command
- Learn: select this option will put the device in learning mode during 5 seconds. you need to be close it and press the button on your remote IR or RF. Once learned, xxx - command will be put On and status to Learn in case of success. Learned Code will remain in memory.
- Test : select this option to send code in memory.
- Save : select this option to save the code into ini file and create a switch/push on device automatically linked to the ini file. in case of success, device will be put Off. if it remain On this mean something is wrong with the save process ( disk space etc ...). when you see this error Error: (IR/RF Salon) File exist : C:\\BroadlinkRM2\BroadlinkRM2-xx-yy.ini, this probably mean that some learned device has been deleted from Domoticz, just continue to click on Save until free Unit number is found.
- Reset: to clear memory and put Off
Every time when you save a learned code, a device is created. Go to Setup / Devices / Not Used to find them
- xxx - HwID-Unit
if you don't want to use this device (you want to use command line feature only) just delete it otherwise click on blank arrow (green background) to activate it.
The new device can be found on Switches tab. It's a push On button, when click on it, this will send the code stored in the corresponding ini file.
NOTA: if you delete all Push on Button devices created by the Broadlink plugin and delete all corresponding ini files, just go to Hardware Configuration page and click on Update, this will re-initialize the Unit number e.g. = 3
- xxx - Remote
To activate the remote you need to put the device 'On'. If 'On' is not possible, check to see if you have created the corresponding ini file. Once the device is on, just click on the Remote to see it --> Kodi like remote. For button definition see Technical section.
- xxx - import
this selector switch provide all necessary tools to import code and create device(s) automatically into Domoticz.
- WebStart : execute mini Web server on port selected on the configuration page. you can in this way upload in easy way from the Android device which host e-control app
- Generate : this one will read all json* files transfered and generate necessary ini files for import.
- Import : execute the import process, will read all ini files found on the ../import folder and create devices.
- Clear : clean the ../import folder by erasing all *.ini & json* files
The import feature provide possibility to import learned code from the Broadlink e-control app installed on Android device but also from any other Domoticz installation. This can be in this way used as a restore solution in case you need to re-install Domoticz from scratch.
- import from e-control app:
First you need to open the e-control app and on the left side menu choose "Share" and then "Share to other phones in WLAN". This should generate the files that we will use for import and that you need to transfert into ../import Domoticz directory.
When you browse your device, under "/broadlink/newremote/SharedData/" You need to get the following files:
and transfert them in the ../import folder. This can be done by using the mini web server.
Open a Web browser on the Android device. Enter your Domoticz IP address with port number put on the configuration page: e.g. http://192.168.1.20:9000. Go to import if not already, and transfert the 3 required files.
NOTA: there is no security put on this web server, this the reason why it will kill "itself" after 10 minutes.
Transfert finished, just select "Generate" and the plugin will read the json* files and create corresponding ini files on the ../import directory plus a text file: simulate.txt which contains all codes extracted from json* files.
If you're OK, select "Import" and the plugin will parse all ini files found under ../import folder and create the devices into Domoticz.
- import from Domoticz:
the simplest way to test if this work is to take an already existing ini file and just copy it into import directory. The ini file used during import had same structure as the one generated by the learning/save process.
In Domoticz, if you go to Temperatures, you will found 1 device created and at your disposal. You need to have put True to "Get temperature device" in Option
Data are refreshed every 2 minutes and you will have the same graph feature as for other sensor. If you want to stop temperature data retrieval, just put False to "Get temperature device" in Option and click on Update.
plugin_send.py provide command line feature that you can use with your scripts. This mean that this can be put on the on/off action of any Domoticz devices and also used to create your custom devices in an easy way. The fastest way to test the command line feature is to put the Debug mode on, click on existing generated device, copy and paste the command line you can see in the Domoticz log:
2017-03-26 22:41:52.539 (My br) Code Sent....
2017-03-26 22:41:52.539 (My br) Command line : "C:\Program Files (x86)\Domoticz\plugins\BroadlinkRM2\plugin_send.py" C:\\BroadlinkRM2\BroadlinkRM2-18-3.ini
(see Technical information)
For windows users, a plugin_send.cmd file is provided and can be used to create action on Selector Switch:
- Win 10 x64
- Python v 3.5.3 x86
- Domoticz Beta min: V3.8007
- Broadlink RM2 device
- broadlink v 0.5.0 -> 
- pycrypto v 2.6.1 no more needed to connect to the device, if not istalled, pyaes will be used instead
All python modules installed by using : pip install <module name>
Junction - Windows:
- link/junction need to be created for c:\program files(x86)\Domoticz to avoid space problem when call cmd file
Linux specific: example on debian (thanks to deennoo)
domoticz looks lib at
this mean once
sudo pip3 install Crypto and sudo pip3 install broadlink and sudo pip3 install pyaes
pip3 is use to install lib on Python 3(install pip3: sudo apt-get install python3-pip )
is done, you have to copy lib on the good dir :
sudo cp -r /usr/local/lib/python3.4/dist-packages/Crypto/ /usr/lib/python3.4/ and sudo cp -r /usr/local/lib/python3.4/dist-packages/broadlink /usr/lib/python3.4/
sudo cp -r /usr/local/lib/python3.4/dist-packages/broadlink-0.5-py3.4.egg/broadlink /usr/lib/python3.4/ sudo cp -r /usr/local/lib/python3.4/dist-packages/pyaes /usr/lib/python3.4/
Then restart domoticz
sudo service domoticz restart
if you have similar error :
2017-10-25 12:35:20.104 Error: (BroadlinkRM2) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/broadlink/:/usr/local/lib/python35.zip:/usr/local/lib/python3.5/:/usr/local/lib/python3.5/plat-linux:/usr/local/lib/python3.5/lib-dynload'. 2017-10-25 12:35:20.104 Error: (BroadlinkRM2) Module Import failed, exception: 'ImportError' 2017-10-25 12:35:20.104 Error: (BroadlinkRM2) Module Import failed: ' Name: broadlink'
this mean copy has not been done on the right directory. In our example, this one should be part of : '/home/pi/domoticz/plugins/broadlink/:/usr/local/lib/python35.zip:/usr/local/lib/python3.5/:/usr/local/lib/python3.5/plat-linux:/usr/local/lib/python3.5/lib-dynload'
Files need to be located under plugins/BroadlinkRM2 folder
python program to send learned code from command line. One parameter required: full path of ini file
cmd file to execute plugin_send.py. One parameter required: full path of ini file (windows version)
python program for simple web server for file upload. 3 param required : <<" 0.0.0.0 ">> <<Port number>> <<ROOT Folder (usually ini folder)>>
cmd file to execute plugin_http.py (windows version)
script file for other OS (need to be adapted to your OS/env.)
main python program to manage broadlink RM2 device into Domoticz
NOTA: the cmd/script to execute plugin_http.py need to be done in the way to not block Domoticz plugin system. This is the case for the windows version provided, for other OS this should be something like that : nohup python /path/to/plugin/plugin_http.py $1 $2 $3 &
A learned code is stored on a ini file, located under directory you specify on parameter "Folder to store ini files:". This file is also used by the plugin_send.py python program to send stored data, this provide to you command line possibility. You can see the command line necessary to send a code by enabling Debug mode, push on Domoticz device associated and go to Domoticz log tab.
for example in windows:
2017-03-26 17:50:57.016 User: Admin initiated a switch command (671/IR/RF Salon - 17-7/On)
2017-03-26 17:50:57.024 (IR/RF Salon) Calling message handler 'onCommand'.
2017-03-26 17:50:57.024 (IR/RF Salon) onCommand called for Unit 7: Parameter 'On', Level: 0 , Connected : True
2017-03-26 17:50:57.024 (IR/RF Salon) Generate on Command for learned code stored on unit :7
2017-03-26 17:50:57.025 (IR/RF Salon) Code loaded : b21634000a1d0b0001290b1d0b1d1e0a1e0a0b1d1e0a1e0a1e0a0b1d1e0a1e0a0b1d0b1d0b1d1e0a0b1d0b1d0b1d0b1d1e0a1f0a0a1d1e0a00000000
2017-03-26 17:50:57.060 (IR/RF Salon) Connected to Broadlink device.
2017-03-26 17:50:57.061 (IR/RF Salon) b'\xb2\x164\x00\n\x1d\x0b\x00\x01)\x0b\x1d\x0b\x1d\x1e\n\x1e\n\x0b\x1d\x1e\n\x1e\n\x1e\n\x0b\x1d\x1e\n\x1e\n\x0b\x1d\x0b\x1d\x0b\x1d\x1e\n\x0b\x1d\x0b\x1d\x0b\x1d\x0b\x1d\x1e\n\x1f\n\n\x1d\x1e\n\x00\x00\x00\x00'
2017-03-26 17:50:57.998 (IR/RF Salon) Code Sent....
2017-03-26 17:50:57.999 (IR/RF Salon) Command line : "C:\Program Files (x86)\Domoticz\plugins\BroadlinkRM2\plugin_send.py" C:\\BroadlinkRM2\BroadlinkRM2-17-7.ini
NOTA : The same structure is shared by the Import process and the ini file is located under <<"Folder to store ini files"/import>> folder. Name will be : IMP-xxx.ini for Generated ini files.
- ini file structure :
pluginkey = BroadlinkRM2
hardwareid = 17
unit = 7
pluginname = IR/RF Salon
pluginfolder = C:\Program Files (x86)\Domoticz\plugins\BroadlinkRM2\
host = 192.168.X.YY
mac = b330aaac260b
7 = b21634000a1d0b0001290b1d0b1d1e0a1e0a0b1d1e0a1e0a1e0a0b1d1e0a1e0a0b1d0b1d0b1d1e0a0b1d0b1d0b1d0b1d1e0a1f0a0a1d1e0a00000000
Default section : information come from plugin system. Customname contains Domoticz name that you had give to the device.
Device section : Ip address & mac Address of Broadlink device
LearnedCode : hex data
- ini file naming convention :
pluginkey - hardwareid - unit
- ini file for Remote customization
Only one section named [Custom], under command param we need to put the unit generated by learning/importing
command = 4,70,72,74,86 etc ....
the order is important and will determine button affectation: first is for 'Home', second for 'Up', third for 'Information' ...
ini file name need to be : plugin_remote_<<hardwareid>>.ini where <<hardwareid>> egal the hardwareid Domoticz provided to the plugin.
ini file location is : <<parameter "Folder to store ini files">>/remote
- ini files management:
this is a manual process. plugin system will only create new one linked to the new Device created. if you remove it and don't want anymore to use the learned code, you need to delete ini file manually.
For the same, could be nice to include the folder where your ini files are stored in your backup process.
Come from the Broadlink application. These three files should be located under <<parameter "Folder to store ini files">>/import (import directory is created automatically during onstart call). Can be deleted manually or by using the Clear selection from the Import selector switch. Used to generate ini files for import.
NOTA: Clear will also erase all *.ini files found under <<parameter "Folder to store ini files">>/import.
A simple web server is provided and allow file upload. Three parameters are required when execute it :
-- Bind to : default to 0.0.0.0 this mean can be accessible from every IP address
-- Port number : default to 9000; Port used to run the server. connection need to be done in this way : http://IPAdress:PortNumber
-- ROOT folder : default to <<parameter "Folder to store ini files">>. This is the ROOT dir for the Web server.
It can be run outside Domoticz. As there is no security implemented (login / password ) the procees will kill itself after 10 minutes
this code : learnedCommand=str(ir_packet.hex()) is pecific to python 3.5 or >, not work on 3.4
replaced by : learnedCommand=str(codecs.encode(ir_packet, 'hex_codec')) ( & import codecs ) to have it running in 3.x