Smart Home with Domoticz + BroadLink + Synology + Amazon Echo

Edit

Overview

I bought an Amazon Echo during my last trip to Boise Idaho in US. It is cool product to respond quickly and works so well in acceptable noisy environment. She is a good buddy for my 5 year-old boy to play with and learn English from.
And I want her do more for more automation stuff at home. All my appliance are traditional ones. I bought them 2 years ago when I moved to the new condo. That’s not a long time passed but I don’t even know how technology changes so fast. Every electrical stuff becomes smart even a socket or a plug. That’s a amazing!
With Alexa, I think I can do more to make my home smarter even with the old style appliances.
The first thing comes into my eys is Broadlink universal remote control. It’s actually a converter for WiFi to IrDa and RF signal. Here is the product link. With the app provided by Broadlink, it can learn any IrDA or RF code of the remote controller and build in software virtual remote controller in the app to control the appliances those it can reach. There are 2 apps in Play Store:

But only using Broadlink remote controller is not perfect. You have to pick up your phone and click several times to open the app and corresponding virtual remote controller. This is not what I want.

To integrate Alexa, there are several solutions from time Googling.

  1. The appliance is born to be smart. And the vendor provides Alexa skills to control the appliance. For example, Philips HUE light, Belkin Wemo and etc.
  2. Integrate Broadlink into Alexa. There are also many solutions for this, including:
    1) Android + Broadlink RM Plugin + Alexa
    2) Domoticz/Home Assistant + HA-Bridge + Alexa
    3) Domoticz + python plugin + controlicz + Alexa
    4) Broadlink native skill + Alexa
  3. Domoticz/Home Assistant + HomeBridge + Siri

Domoticz and Home Assistant are both Home Automation System. There are a lot of people practicing them and post their experience on Internet. (They help me a lot. And this is the time I want to share my experience with others.) And both systems have their own advantages and disadvantages. The reference link 1 is the comparison among 5 popular automation systems.
I choose Domoticz is because it has native support the Synology NAS OS - DSM. Home NAS is in 7*24 hours service. I don’t need to setup extra hardware for the system. With this idea in mind, I practice solution 2)~4) in the item 2. I will consolidate all of them in this post below. The final solution architecture is shown as below:

Domoticz into Synology

This is quite simple. Please see the official website - Domoticz for Synology NAS. Download Domoticz for Synology DSM 6.1 with Python Plugin Beta. Python plugin is very important, don’t miss it. It will be used in after chapters.
The file you download is a .spk file. This is a installable package of Synology DSM. And you can install it by clicking “Manual Install” in “Package Center”. After success, it will shown as below:

Other Dependency

Domoticz’s plugin system depends on Python3
broadlink-http-rest server depends on Python2
HA-Bridge Server depends on Java8
You’d better to have also “git” installed. That will be much easier to clone GitHub projects.
The 4 packages in Synology package center look like below.

Broadlink into Domoticz

Domoticz Broadlink Python Plugin + Controlicz

This part takes the most issues and I spent several nights fixing the issues. I will have the issue list below.
Domoticz Broadlink plugin and broadlink-http-rest are all based on python-broadlink. So first of all, clone the project python-broadlink from GitHub.

Install python-broadlink

In many posts, people suggest to use pip to install the library of python-broadlink. But I found an issue of doing it this way. python-broadlink once was built based on pycrypto, which is out of support. And then the author switch to pyaes. But I think he didn’t resolve the dependency between python-broadlink and pycrypto. If you install python-broadlink on Synology using pip, it will run into issues of compiling pycrypto. Apparently, Synology DSM doesn’t have compilation environment (GCC and etc.).
My suggested steps are:

  • Make sure your python is linked to Python3. (ex. ln -s /usr/local/bin/python3.5 /usr/bin/python)
  • git clone python-broadlink && cd python-broadlink
  • python setup.py install
  • python -m pip install pyaes. Because pip3 cannot be installed into Synology DSM, even it’s installed by python3.5 get-pip.py. The script will also install pip2.

Install Domoticz Python Plugin

Reference link 3 is a Domoticz wiki page provided by the plugin author. The post is mainly worked out based on Windows system, but referring the others chapters, it’s still feasible. The installation steps are:

  • Download plugin files from dropbox.
  • The plugin folder is in/usr/local/domoticz/var/plugins/BroadlinkRM2/. Copy the files to this folderincluding:
    • plugin.py -main file
    • plugin_send.py
    • plugin_http.py
    • plugin_http.sh
      Be noted: the plugin folder is not /usr/local/domoticz/plugins/BroadlinkRM2/, although there is an example folder in that directory. But when I put plugin files in that directory, the plugin won’t be loaded correctly.
  • Stop and Run Domoticz in Package Center of Synology DSM. And do this every time you update the plugin python file.

So far, the installation finished. You should be able to see the Broalink hardware type in the pull-down list in Setup->Hardware.

Create Broadlink Hardware

Following the author’s steps, you should be able to create broadlink hardware in Domoticz web page and discover broadlink devices.
To create the hardware as below:

Import Devices from E-Control App导入易控(e-control)设备

Refer to reference link 3 for detailed description. It’s in User Guide->Inside Domoticz->xxx - import chapter. Author may not work with multi-byte language, such as Chinese. If there are Chinese characters in the imported json* files, the plugin will crash. See issue 3 for solution.
Another point should be noted, when WebStart is triggered, Domoticz will setup a tiny web service running on port 9000 to handle the files uploaded from mobile devices. Make sure you configure the Synology firewall correctly.

Controlicz

This seems to be a new service. I don’t see people mention it when I’m reading through Google results. I happened to see it in Alexa skill page. Using Controlicz, you don’t need to simulate your appliances as Philips HUI light using HA-Bridge. But it has its own pros and cons with Broadlink remote controller. There is a dedicated section comparing Controlicz and HA-Bridge.
To use Controlicz:

  • Register Controlicz using your Alexa’s credential (email and password)
  • Enable skill and say “discover device” to Alexa.
  • All done

Be noted: Controlicz asks for:

  • Domoticz service should be exposed to external access. That means you need to map port and DDNS. Because I’m using Synology, that’s not a problem to me.
  • Controlicz asks Domoticz running on HTTPS protocol. That means you have to enable the Domoticz HTTPS port and corresponding Firewall configurations.

Issue List

So far, if you are lucky enough to succeed in all above steps, you can say “Turn on the TV” to Alexa. The TV should respond to you quickly and correctly. If unfortunately it doesn’t, don’t worry. Check the issue list to see if it helps.

Import Error “broadlink”

You have installed python-broadlink already, and you can import it from Python REPL command line. Why is the error still reported? The direct cause is the PYTHONPATH is incorrect. But when I check the code in plugin.py, I see the process of PYTHONPATH as here:

if sys.platform.startswith('linux'):
# linux specific code here
# doesn't work even if set dist-packages => site-packages
sys.path.append(os.path.dirname(os.__file__) + '/dist-packages')
elif sys.platform.startswith('darwin'):
# mac
sys.path.append(os.path.dirname(os.__file__) + '/site-packages')
elif sys.platform.startswith('win32'):
# win specific
sys.path.append(os.path.dirname(os.__file__) + '\site-packages')

The path to broadlink library is /usr/local/lib/python3.5/site-packages/broadlink-0.5-py3.5.egg/broadlink/. Even when I correct the “dist-package” to “site-packages” in above code snippet, it still cannot work. However, the solution is quite simple. Just copy broadlink to the plugins folder.

cp -r /usr/local/lib/python3.5/site-packages/broadlink-0.5-py3.5.egg/broadlink/ /usr/local/domoticz/var/plugins/BroadlinkRM2/

Error Connecting to Broadlink device

There are 2 GitHub issue link for reference:

# broadlink/__init__.py
160 def encrypt_pyaes(self, payload):
161 aes = pyaes.AESModeOfOperationCBC(self.key, iv = bytes(self.iv))
162 return "".join([aes.encrypt(bytes(payload[i:i+16])) for i in range(0, len(payload), 16)]) # <==== Error is here

bytes in python3 returns class bytes, whereas in python2, it returns plain string. See here for experiments:

Python2
>>> type(bytes([1,2,3]))
<type 'str'>

Python3
>>> type(bytes([1,2,3]))
<class 'bytes'>
>>> "".join([bytes([1,2]),bytes([2,3])]) <==== You cannot cat 2 bytes class objects as string
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected str instance, bytes found
>>> b''.join([bytes([1,2]),bytes([2,3])]) <==== This is the good way
b'\x01\x02\x02\x03'

The correct way to concatenating is to use binary string。

Chinese characters in Domoticz imported files

In Python3, if a file has Chinese character, you cannot read files and decode strings as below:

with open('jsonFile') as f:
textStr = f.read() <=== Python3 will complain about the codec error here.
textStr.decode('utf8')

The correct way is:

with open('jsonFile', encoding='utf8'):
textStr = f.read() <=== Everything here has already been unicode.

Update all lines of opening the imported json* files. And one more thing you need to pay attention to, which is for ConfigParser. You can update the encoding as below for them.

config = configparser.ConfigParser()
config.read(path, encoding='utf8')

Try it, it should do with no problems, aren’t you?

Domoticz + broadlink-http-rest + HA-Bridge

With HA-Bridge, you don’t need Domoticz Python plugin. You can create dummy hardware in Domoticz web page as below picture.

Install HA-Bridge

The whole idea of HA-Bridge is to simulate any device as Philips HUE light, which has native support in Alexa. And HA-Bridge can import all Domoticz devices easily. The cons is it can only support open/close and dim settings like you are operating a HUE light.
HA-Bridge is a jar package works with Java 8. And we need to run it in Synology background as a service. Refer to the post here -Run as a service on Synology for running it as a service.
The command line is nohup java -jar -Dserver.port=8085 /ha-bridge-4.5.6.jar &. Put it in Synology Scheduled Tasks, and then you don’t need to worry about the reboot.

Install broadlink-http-rest

Clone the project from GitHub - broadlink-http-rest. Just as HA-Bridge, it also needs to be in background as service. Otherwise, it will quite as soon as SSH connection is cut.The command line is nohup python broadlink-http-rest/server.py &. Be noted, make sure you are using “nohup”, otherwise it will still quite as SSH is disconnected even if you specify the “&”

Firewall & Scheduled Tasks

Configure the firewall:

  • 8085: HA-Bridge server
  • 8080: broadlink-http-rest server
  • 8443: Domoticz HTTPS service
  • 9000: Domoticz Broadlink web service

Also the scheduled tasks:

Broadlink into Domoticz

The steps are:

  • In Setup->Hardware, create a Dummy Hardware
  • In the same page and in the created item, click “Create Virtual Sensors”
  • In Switches tab, find the virtual sensor you just created, click Edit and configure “On Action” and “Off Action”.

Domoticz into HA-Bridge

Please refer to reference link 2. From the chapter of Configuring HA bridge, it starts to describe how to configure HA-Bridge to import devices from Domoticz web service.

HA-Bridge vs. Controlicz

General Smart Home

Controlicz can integrate all type of devices into Alexa. For example, if Alexa doesn’t have native support of this smart home device, you can build up a Domoticz server in your home and integrate it into Alexa by Controlicz. According to the description in Controlicz official site, it doesn’t only support on/off switches, but also other normal appliance like TV, AC and etc. And Domoticz apparently support a lot more devices than Alexa does.

Broadlink Integration

To integrate Broadlink, these 2 have their own pros and cons.
Broadlink is a universal remote controller. So every devices on Broadlink is a push button device. Each one only has one action, which is being triggered. This is even weaker than the on/off switch, which at lease has 2 actions - on or off.
For example, there is a button on Fan’s remote controller. Pushing it once, it will turn on the fan and twice will turn off it. Through Controlicz, you have to say “Turn on the Fan” to Alexa to turn on the fan and you have to say the same sentence to close it. Is it weird?
If you are using HA-Bridge, you can say “Turn on …” to turn on and “Turn off …” to turn off. Is it better?
The biggest benefit of using Controlicz to integrate Domoticz is it can import all devices pre-defined in E-Control app. It can fully make use of the E-Control’s GUI. You don’t need to add virtual sensors one by one manually.

Broadlink Native Skill + IHC

After bunch of work above, I happened to see there is a native support broadlink Alexa skill called “broadlink”. It should work with the latest version of IHC app. The bad news is both the skill and the app have very low review scores.

  • IHC playstore 2.2 stars
  • Alexa Broadlink Skill 2.3 stars

According to the official examples, it can only support TV. And as my own experiments, when I added a TV and an AC, Alexa can only discover the TV and no AC.

Reference Links

  1. 5 open source home automation tools
  2. Alex - Domoticz
  3. Domoticz Wiki Plugins/BroadlinkRM2
  4. #原创新人# 群晖安装broadlink-http-rest代替RMBridge_生活记录_什么值得买
%23%20Smart%20Home%20with%20Domoticz%20+%20BroadLink%20+%20Synology%20+%20Amazon%20Echo%0A@%28myblog%29%5Bsynology%2C%20broadlink%2C%20domoticz%2C%20IoT%5D%0A%0A%23%23Overview%0AI%20bought%20an%20Amazon%20Echo%20during%20my%20last%20trip%20to%20Boise%20Idaho%20in%20US.%20It%20is%20cool%20product%20to%20respond%20quickly%20and%20works%20so%20well%20in%20acceptable%20noisy%20environment.%20She%20is%20a%20good%20buddy%20for%20my%205%20year-old%20boy%20to%20play%20with%20and%20learn%20English%20from.%0AAnd%20I%20want%20her%20do%20more%20for%20more%20automation%20stuff%20at%20home.%20All%20my%20appliance%20are%20traditional%20ones.%20I%20bought%20them%202%20years%20ago%20when%20I%20moved%20to%20the%20new%20condo.%20That%27s%20not%20a%20long%20time%20passed%20but%20I%20don%27t%20even%20know%20how%20technology%20changes%20so%20fast.%20Every%20electrical%20stuff%20becomes%20smart%20even%20a%20socket%20or%20a%20plug.%20That%27s%20a%20amazing%21%0AWith%20Alexa%2C%20I%20think%20I%20can%20do%20more%20to%20make%20my%20home%20smarter%20even%20with%20the%20old%20style%20appliances.%0AThe%20first%20thing%20comes%20into%20my%20eys%20is%20Broadlink%20universal%20remote%20control.%20It%27s%20actually%20a%20converter%20for%20WiFi%20to%20IrDa%20and%20RF%20signal.%20Here%20is%20the%20product%20%5Blink%5D%28https%3A//detail.tmall.com/item.htm%3Fspm%3Da230r.1.14.8.ebb2eb2Gs49Vt%26id%3D43623542607%26cm_id%3D140105335569ed55e27b%26abbucket%3D13%26skuId%3D77095242268%29.%20With%20the%20app%20provided%20by%20Broadlink%2C%20it%20can%20learn%20any%20IrDA%20or%20RF%20code%20of%20the%20remote%20controller%20and%20build%20in%20software%20virtual%20remote%20controller%20in%20the%20app%20to%20control%20the%20appliances%20those%20it%20can%20reach.%20There%20are%202%20apps%20in%20Play%20Store%3A%0A-%20%5Be-control%5D%28https%3A//play.google.com/store/apps/details%3Fid%3Dcom.broadlink.rmt%29%20%0A-%20%5BIHC%5D%28https%3A//play.google.com/store/apps/details%3Fid%3Dcn.com.broadlink.econtrol.plus%29%0A%0ABut%20only%20using%20Broadlink%20remote%20controller%20is%20not%20perfect.%20You%20have%20to%20pick%20up%20your%20phone%20and%20click%20several%20times%20to%20open%20the%20app%20and%20corresponding%20virtual%20remote%20controller.%20This%20is%20not%20what%20I%20want.%0A%0ATo%20integrate%20Alexa%2C%20there%20are%20several%20solutions%20from%20time%20Googling.%0A1.%20The%20appliance%20is%20born%20to%20be%20smart.%20And%20the%20vendor%20provides%20Alexa%20skills%20to%20control%20the%20appliance.%20For%20example%2C%20Philips%20HUE%20light%2C%20Belkin%20Wemo%20and%20etc.%0A2.%20Integrate%20Broadlink%20into%20Alexa.%20There%20are%20also%20many%20solutions%20for%20this%2C%20including%3A%0A%091%29%20Android%20+%20%5BBroadlink%20RM%20Plugin%5D%28https%3A//play.google.com/store/apps/details%3Fid%3Dus.originally.tasker%29%20+%20Alexa%0A%092%29%20Domoticz/Home%20Assistant%20+%20%20%5BHA-Bridge%5D%28https%3A//github.com/bwssytems/ha-bridge%29%20+%20Alexa%0A%093%29%20Domoticz%20+%20python%20plugin%20+%20controlicz%20+%20Alexa%0A%094%29%20Broadlink%20native%20skill%20+%20Alexa%20%0A3.%20Domoticz/Home%20Assistant%20+%20HomeBridge%20+%20Siri%0A%0ADomoticz%20and%20Home%20Assistant%20are%20both%20Home%20Automation%20System.%20There%20are%20a%20lot%20of%20people%20practicing%20them%20and%20post%20their%20experience%20on%20Internet.%20%28They%20help%20me%20a%20lot.%20And%20this%20is%20the%20time%20I%20want%20to%20share%20my%20experience%20with%20others.%29%20And%20both%20systems%20have%20their%20own%20advantages%20and%20disadvantages.%20The%20reference%20link%201%20is%20the%20comparison%20among%205%20popular%20automation%20systems.%0AI%20choose%20Domoticz%20is%20because%20it%20has%20native%20support%20the%20Synology%20NAS%20OS%20-%20DSM.%20Home%20NAS%20is%20in%207*24%20hours%20service.%20I%20don%27t%20need%20to%20setup%20extra%20hardware%20for%20the%20system.%20With%20this%20idea%20in%20mind%2C%20I%20practice%20solution%202%29%7E4%29%20in%20the%20item%202.%20I%20will%20consolidate%20all%20of%20them%20in%20this%20post%20below.%20The%20final%20solution%20architecture%20is%20shown%20as%20below%3A%0A%0A%21%5BAlt%20text%5D%28./1501339487875.png%29%0A%0A%23%23%20Domoticz%20into%20Synology%0AThis%20is%20quite%20simple.%20Please%20see%20the%20official%20website%20-%20%5BDomoticz%20for%20Synology%20NAS%5D%28http%3A//www.jadahl.com/%29.%20Download%20%5BDomoticz%20for%20Synology%20DSM%206.1%20with%20Python%20Plugin%20Beta%5D%28http%3A//www.jadahl.com/domoticz_beta_6.1_python/%29.%20Python%20plugin%20is%20very%20important%2C%20don%27t%20miss%20it.%20It%20will%20be%20used%20in%20after%20chapters.%0AThe%20file%20you%20download%20is%20a%20.spk%20file.%20This%20is%20a%20installable%20package%20of%20Synology%20DSM.%20And%20you%20can%20install%20it%20by%20clicking%20%22Manual%20Install%22%20in%20%22Package%20Center%22.%20After%20success%2C%20it%20will%20shown%20as%20below%3A%0A%0A%21%5BAlt%20text%5D%28./1501340457645.png%29%0A%0A%23%23%20Other%20Dependency%0ADomoticz%27s%20plugin%20system%20depends%20on%20Python3%0Abroadlink-http-rest%20server%20depends%20on%20Python2%0A%5BHA-Bridge%20Server%5D%28https%3A//github.com/bwssytems/ha-bridge%29%20depends%20on%20Java8%0AYou%27d%20better%20to%20have%20also%20%22git%22%20installed.%20That%20will%20be%20much%20easier%20to%20clone%20GitHub%20projects.%0AThe%204%20packages%20in%20Synology%20package%20center%20look%20like%20below.%0A%21%5BAlt%20text%5D%28./1501340796886.png%29%21%5BAlt%20text%5D%28./1501340823935.png%29%21%5BAlt%20text%5D%28./1501340847466.png%29%0A%0A%23%23%20Broadlink%20into%20Domoticz%0A%0A%23%23%23%20Domoticz%20Broadlink%20Python%20Plugin%20+%20Controlicz%0AThis%20part%20takes%20the%20most%20issues%20and%20I%20spent%20several%20nights%20fixing%20the%20issues.%20I%20will%20have%20the%20issue%20list%20below.%0ADomoticz%20Broadlink%20plugin%20and%20%5Bbroadlink-http-rest%5D%28https%3A//github.com/radinsky/broadlink-http-rest%29%20are%20all%20based%20on%20%5Bpython-broadlink%5D%28https%3A//github.com/mjg59/python-broadlink%29.%20So%20first%20of%20all%2C%20clone%20the%20project%20python-broadlink%20from%20GitHub.%0A%0A%23%23%23%23%20Install%20python-broadlink%0AIn%20many%20posts%2C%20people%20suggest%20to%20use%20pip%20to%20install%20the%20library%20of%20python-broadlink.%20But%20I%20found%20an%20issue%20of%20doing%20it%20this%20way.%20python-broadlink%20once%20was%20built%20based%20on%20pycrypto%2C%20which%20is%20out%20of%20support.%20And%20then%20the%20author%20switch%20to%20pyaes.%20But%20I%20think%20he%20didn%27t%20resolve%20the%20dependency%20between%20python-broadlink%20and%20pycrypto.%20If%20you%20install%20python-broadlink%20on%20Synology%20using%20pip%2C%20it%20will%20run%20into%20issues%20of%20compiling%20pycrypto.%20Apparently%2C%20Synology%20DSM%20doesn%27t%20have%20compilation%20environment%20%28GCC%20and%20etc.%29.%0AMy%20suggested%20steps%20are%3A%0A-%20Make%20sure%20your%20python%20is%20linked%20to%20Python3.%20%28ex.%20ln%20-s%20/usr/local/bin/python3.5%20/usr/bin/python%29%0A-%20git%20clone%20python-broadlink%20%26%26%20cd%20python-broadlink%0A-%20%60python%20setup.py%20install%60%0A-%20%60python%20-m%20pip%20install%20pyaes%60.%20Because%20pip3%20cannot%20be%20installed%20into%20Synology%20DSM%2C%20even%20it%27s%20installed%20by%20%60python3.5%20get-pip.py%60.%20The%20script%20will%20also%20install%20pip2.%0A%0A%23%23%23%23%20Install%20Domoticz%20Python%20Plugin%0AReference%20link%203%20is%20a%20Domoticz%20wiki%20page%20provided%20by%20the%20plugin%20author.%20The%20post%20is%20mainly%20worked%20out%20based%20on%20Windows%20system%2C%20but%20referring%20the%20others%20chapters%2C%20it%27s%20still%20feasible.%20The%20installation%20steps%20are%3A%0A-%20Download%20%5Bplugin%20files%5D%28https%3A//www.dropbox.com/sh/htyghey9e402u4y/AACeb1cXqaPd9gBVl5TL3H36a%3Fdl%3D0%29%20from%20dropbox.%0A-%20The%20plugin%20folder%20is%20in%60/usr/local/domoticz/var/plugins/BroadlinkRM2/%60.%20Copy%20the%20files%20to%20this%20folderincluding%3A%0A%09-%20plugin.py%20-main%20file%0A%09-%20plugin_send.py%0A%09-%20plugin_http.py%0A%09-%20plugin_http.sh%0A%09Be%20noted%3A%20the%20plugin%20folder%20is%20not%20%60/usr/local/domoticz/plugins/BroadlinkRM2/%60%2C%20although%20there%20is%20an%20example%20folder%20in%20that%20directory.%20But%20when%20I%20put%20plugin%20files%20in%20that%20directory%2C%20the%20plugin%20won%27t%20be%20loaded%20correctly.%0A-%20Stop%20and%20Run%20Domoticz%20in%20Package%20Center%20of%20Synology%20DSM.%20And%20do%20this%20every%20time%20you%20update%20the%20plugin%20python%20file.%0A%0ASo%20far%2C%20the%20installation%20finished.%20You%20should%20be%20able%20to%20see%20the%20Broalink%20hardware%20type%20in%20the%20pull-down%20list%20in%20Setup-%3EHardware.%0A%21%5BAlt%20text%5D%28./1500861858610.png%29%0A%0A%23%23%23%23%20Create%20Broadlink%20Hardware%0AFollowing%20the%20author%27s%20steps%2C%20you%20should%20be%20able%20to%20create%20broadlink%20hardware%20in%20Domoticz%20web%20page%20and%20discover%20broadlink%20devices.%0ATo%20create%20the%20hardware%20as%20below%3A%0A%21%5BAlt%20text%5D%28./1501368649742.png%29%0AIP%20address%20can%20be%20127.0.0.1%20and%20MAC%20address%20can%20be%20all%20zero.%20The%20plugin%20can%20trigger%20a%20discovery%20process%20to%20get%20the%20real%20IP%20address%20and%20MAC%20address.%20Refer%20to%20reference%20link%203%20for%20detailed%20description.%20But%20it%20won%27t%20be%20such%20smooth%20as%20you%20imagine.%20Refer%20to%20the%20issue%20list%20below.%0A%0A%23%23%23%23%20Import%20Devices%20from%20E-Control%20App%u5BFC%u5165%u6613%u63A7%28e-control%29%u8BBE%u5907%0ARefer%20to%20reference%20link%203%20for%20detailed%20description.%20It%27s%20in%20User%20Guide-%3EInside%20Domoticz-%3Exxx%20-%20import%20chapter.%20Author%20may%20not%20work%20with%20multi-byte%20language%2C%20such%20as%20Chinese.%20If%20there%20are%20Chinese%20characters%20in%20the%20imported%20json*%20files%2C%20the%20plugin%20will%20crash.%20See%20issue%203%20for%20solution.%0AAnother%20point%20should%20be%20noted%2C%20when%20WebStart%20is%20triggered%2C%20Domoticz%20will%20setup%20a%20tiny%20web%20service%20running%20on%20port%209000%20to%20handle%20the%20files%20uploaded%20from%20mobile%20devices.%20Make%20sure%20you%20configure%20the%20Synology%20firewall%20correctly.%0A%0A%23%23%23%20Controlicz%0AThis%20seems%20to%20be%20a%20new%20service.%20I%20don%27t%20see%20people%20mention%20it%20when%20I%27m%20reading%20through%20Google%20results.%20I%20happened%20to%20see%20it%20in%20Alexa%20skill%20page.%20Using%20Controlicz%2C%20you%20don%27t%20need%20to%20simulate%20your%20appliances%20as%20Philips%20HUI%20light%20using%20HA-Bridge.%20But%20it%20has%20its%20own%20pros%20and%20cons%20with%20Broadlink%20remote%20controller.%20There%20is%20a%20dedicated%20section%20comparing%20Controlicz%20and%20HA-Bridge.%0ATo%20use%20Controlicz%3A%0A-%20Register%20%5BControlicz%5D%28https%3A//www.controlicz.com/%29%20using%20your%20Alexa%27s%20credential%20%28email%20and%20password%29%0A-%20Enable%20skill%20and%20say%20%22discover%20device%22%20to%20Alexa.%0A-%20All%20done%0A%0A%3EBe%20noted%3A%20Controlicz%20asks%20for%3A%0A%3E-%20Domoticz%20service%20should%20be%20exposed%20to%20external%20access.%20That%20means%20you%20need%20to%20map%20port%20and%20DDNS.%20Because%20I%27m%20using%20Synology%2C%20that%27s%20not%20a%20problem%20to%20me.%0A%3E-%20Controlicz%20asks%20Domoticz%20running%20on%20HTTPS%20protocol.%20That%20means%20you%20have%20to%20enable%20the%20Domoticz%20HTTPS%20port%20and%20corresponding%20Firewall%20configurations.%0A%0A%23%23%23%20Issue%20List%0ASo%20far%2C%20if%20you%20are%20lucky%20enough%20to%20succeed%20in%20all%20above%20steps%2C%20you%20can%20say%20%22Turn%20on%20the%20TV%22%20to%20Alexa.%20The%20TV%20should%20respond%20to%20you%20quickly%20and%20correctly.%20If%20unfortunately%20it%20doesn%27t%2C%20don%27t%20worry.%20Check%20the%20issue%20list%20to%20see%20if%20it%20helps.%0A%0A%23%23%23%23%20Import%20Error%20%22broadlink%22%0AYou%20have%20installed%20python-broadlink%20already%2C%20and%20you%20can%20import%20it%20from%20Python%20REPL%20command%20line.%20Why%20is%20the%20error%20still%20reported%3F%20The%20direct%20cause%20is%20the%20PYTHONPATH%20is%20incorrect.%20But%20when%20I%20check%20the%20code%20in%20plugin.py%2C%20I%20see%20the%20process%20of%20PYTHONPATH%20as%20here%3A%0A%60%60%60%0Aif%20sys.platform.startswith%28%27linux%27%29%3A%0A%20%20%20%20%23%20linux%20specific%20code%20here%0A%20%20%20%20%23%20doesn%27t%20work%20even%20if%20set%20dist-packages%20%3D%3E%20site-packages%0A%20%20%20%20sys.path.append%28os.path.dirname%28os.__file__%29%20+%20%27/dist-packages%27%29%0Aelif%20sys.platform.startswith%28%27darwin%27%29%3A%0A%20%20%20%20%23%20mac%0A%20%20%20%20sys.path.append%28os.path.dirname%28os.__file__%29%20+%20%27/site-packages%27%29%0Aelif%20sys.platform.startswith%28%27win32%27%29%3A%0A%20%20%20%20%23%20%20win%20specific%0A%20%20%20%20sys.path.append%28os.path.dirname%28os.__file__%29%20+%20%27%5Csite-packages%27%29%0A%60%60%60%0AThe%20path%20to%20broadlink%20library%20is%20%60/usr/local/lib/python3.5/site-packages/broadlink-0.5-py3.5.egg/broadlink/%60.%20Even%20when%20I%20correct%20the%20%22dist-package%22%20to%20%22site-packages%22%20in%20above%20code%20snippet%2C%20it%20still%20cannot%20work.%20However%2C%20the%20solution%20is%20quite%20simple.%20Just%20copy%20broadlink%20to%20the%20plugins%20folder.%0A%3Ecp%20-r%20/usr/local/lib/python3.5/site-packages/broadlink-0.5-py3.5.egg/broadlink/%20/usr/local/domoticz/var/plugins/BroadlinkRM2/%0A%0A%23%23%23%23%20Error%20Connecting%20to%20Broadlink%20device%0AThere%20are%202%20GitHub%20issue%20link%20for%20reference%3A%0A-%20%5BError%20Connecting%20to%20Broadlink%20device%20%23107%5D%28https%3A//github.com/mjg59/python-broadlink/issues/107%29%0A-%20%5Blpad%20fix%20broken%3F%20%2397%5D%28https%3A//github.com/mjg59/python-broadlink/issues/97%29%0AIt%20may%20help%20you%2C%20but%20it%20is%20not%20the%20answer%20to%20my%20issue.%0AThe%20root%20cause%20is%20bytes%20function%20is%20different%20in%20Python2%20and%20Python3.%20The%20error%20happens%20here%3A%0A%60%60%60%0A%23%20broadlink/__init__.py%0A160%20%20%20def%20encrypt_pyaes%28self%2C%20payload%29%3A%0A161%20%20%20%20%20aes%20%3D%20pyaes.AESModeOfOperationCBC%28self.key%2C%20iv%20%3D%20bytes%28self.iv%29%29%0A162%20%20%20%20%20return%20%22%22.join%28%5Baes.encrypt%28bytes%28payload%5Bi%3Ai+16%5D%29%29%20for%20i%20in%20range%280%2C%20len%28payload%29%2C%2016%29%5D%29%20%23%20%3C%3D%3D%3D%3D%20Error%20is%20here%0A%60%60%60%0Abytes%20in%20python3%20returns%20class%20bytes%2C%20whereas%20in%20python2%2C%20it%20returns%20plain%20string.%20See%20here%20for%20experiments%3A%20%0A%60%60%60%0APython2%0A%3E%3E%3E%20type%28bytes%28%5B1%2C2%2C3%5D%29%29%0A%3Ctype%20%27str%27%3E%0A%0APython3%0A%3E%3E%3E%20type%28bytes%28%5B1%2C2%2C3%5D%29%29%0A%3Cclass%20%27bytes%27%3E%0A%3E%3E%3E%20%22%22.join%28%5Bbytes%28%5B1%2C2%5D%29%2Cbytes%28%5B2%2C3%5D%29%5D%29%20%20%3C%3D%3D%3D%3D%20You%20cannot%20cat%202%20bytes%20class%20objects%20as%20string%0ATraceback%20%28most%20recent%20call%20last%29%3A%0A%20%20File%20%22%3Cstdin%3E%22%2C%20line%201%2C%20in%20%3Cmodule%3E%0ATypeError%3A%20sequence%20item%200%3A%20expected%20str%20instance%2C%20bytes%20found%0A%3E%3E%3E%20b%27%27.join%28%5Bbytes%28%5B1%2C2%5D%29%2Cbytes%28%5B2%2C3%5D%29%5D%29%20%3C%3D%3D%3D%3D%20This%20is%20the%20good%20way%0Ab%27%5Cx01%5Cx02%5Cx02%5Cx03%27%0A%60%60%60%0AThe%20correct%20way%20to%20concatenating%20is%20to%20use%20binary%20string%u3002%0A%0A%23%23%23%23%20Chinese%20characters%20in%20Domoticz%20imported%20files%0AIn%20Python3%2C%20if%20a%20file%20has%20Chinese%20character%2C%20you%20cannot%20read%20files%20and%20decode%20strings%20as%20below%3A%0A%60%60%60%0Awith%20open%28%27jsonFile%27%29%20as%20f%3A%0A%09textStr%20%3D%20f.read%28%29%20%3C%3D%3D%3D%20Python3%20will%20complain%20about%20the%20codec%20error%20here.%0A%09textStr.decode%28%27utf8%27%29%0A%60%60%60%0AThe%20correct%20way%20is%3A%0A%60%60%60%0Awith%20open%28%27jsonFile%27%2C%20encoding%3D%27utf8%27%29%3A%0A%09textStr%20%3D%20f.read%28%29%20%3C%3D%3D%3D%20Everything%20here%20has%20already%20been%20unicode.%0A%60%60%60%0AUpdate%20all%20lines%20of%20opening%20the%20imported%20json*%20files.%20And%20one%20more%20thing%20you%20need%20to%20pay%20attention%20to%2C%20which%20is%20for%20ConfigParser.%20You%20can%20update%20the%20encoding%20as%20below%20for%20them.%0A%60%60%60%0Aconfig%20%3D%20configparser.ConfigParser%28%29%0Aconfig.read%28path%2C%20encoding%3D%27utf8%27%29%0A%60%60%60%0ATry%20it%2C%20it%20should%20do%20with%20no%20problems%2C%20aren%27t%20you%3F%0A%0A%23%23%23%20Domoticz%20+%20broadlink-http-rest%20+%20HA-Bridge%0AWith%20HA-Bridge%2C%20you%20don%27t%20need%20Domoticz%20Python%20plugin.%20You%20can%20create%20dummy%20hardware%20in%20Domoticz%20web%20page%20as%20below%20picture.%0A%21%5BAlt%20text%5D%28./1501376022176.png%29%0A%0A%23%23%23%23%20Install%20HA-Bridge%0AThe%20whole%20idea%20of%20HA-Bridge%20is%20to%20simulate%20any%20device%20as%20Philips%20HUE%20light%2C%20which%20has%20native%20support%20in%20Alexa.%20And%20HA-Bridge%20can%20import%20all%20Domoticz%20devices%20easily.%20The%20cons%20is%20it%20can%20only%20support%20open/close%20and%20dim%20settings%20like%20you%20are%20operating%20a%20HUE%20light.%0AHA-Bridge%20is%20a%20jar%20package%20works%20with%20Java%208.%20And%20we%20need%20to%20run%20it%20in%20Synology%20background%20as%20a%20service.%20Refer%20to%20the%20post%20here%20-%5BRun%20as%20a%20service%20on%20Synology%5D%28https%3A//github.com/bwssytems/ha-bridge/issues/310%29%20for%20running%20it%20as%20a%20service.%0AThe%20command%20line%20is%20%60nohup%20java%20-jar%20-Dserver.port%3D8085%20/ha-bridge-4.5.6.jar%20%26%60.%20Put%20it%20in%20Synology%20Scheduled%20Tasks%2C%20and%20then%20you%20don%27t%20need%20to%20worry%20about%20the%20reboot.%0A%0A%23%23%23%23%20Install%20broadlink-http-rest%0AClone%20the%20project%20from%20GitHub%20-%20%5Bbroadlink-http-rest%5D%28https%3A//github.com/radinsky/broadlink-http-rest%29.%20Just%20as%20HA-Bridge%2C%20it%20also%20needs%20to%20be%20in%20background%20as%20service.%20Otherwise%2C%20it%20will%20quite%20as%20soon%20as%20SSH%20connection%20is%20cut.The%20command%20line%20is%20%60nohup%20python%20broadlink-http-rest/server.py%20%26%60.%20Be%20noted%2C%20make%20sure%20you%20are%20using%20%22nohup%22%2C%20otherwise%20it%20will%20still%20quite%20as%20SSH%20is%20disconnected%20even%20if%20you%20specify%20the%20%22%26%22%0A%0A%23%23%23%23%20Firewall%20%26%20Scheduled%20Tasks%0AConfigure%20the%20firewall%3A%0A%21%5BAlt%20text%5D%28./1501376973009.png%29%0A-%208085%3A%20HA-Bridge%20server%0A-%208080%3A%20broadlink-http-rest%20server%0A-%208443%3A%20Domoticz%20HTTPS%20service%0A-%209000%3A%20Domoticz%20Broadlink%20web%20service%0A%0AAlso%20the%20scheduled%20tasks%3A%0A%21%5BAlt%20text%5D%28./1501377068095.png%29%0A%0A%23%23%23%23%20Broadlink%20into%20Domoticz%0AThe%20steps%20are%3A%0A-%20In%20Setup-%3EHardware%2C%20create%20a%20Dummy%20Hardware%0A-%20In%20the%20same%20page%20and%20in%20the%20created%20item%2C%20click%20%22Create%20Virtual%20Sensors%22%0A-%20In%20Switches%20tab%2C%20find%20the%20virtual%20sensor%20you%20just%20created%2C%20%20click%20Edit%20and%20configure%20%22On%20Action%22%20and%20%22Off%20Action%22.%0A%21%5BAlt%20text%5D%28./1501376159204.png%29%0AHere%20the%20on/off%20action%20is%20to%20use%20broadlink-http-rest%20service%20to%20send%20broadlink%20commands%20for%20controlling%20the%20appliances.%20Before%20sending%20the%20commands%2C%20you%20have%20to%20also%20use%20broadlink-http-rest%20service%20to%20let%20broadlink%20to%20learn%20the%20code.%20For%20example%2C%20type%20http%3A//192.168.1.2%3A8080/learnCommand/open-ac%20in%20your%20browser%2C%20broadlink%20RM%20will%20enter%20learning%20mode.%20The%20orange%20light%20will%20be%20turned%20on.%20Then%20you%20need%20to%20push%20the%20button%20on%20the%20AC%20remote%20controller%20to%20let%20broadlink%20RM%20learn%20the%20IrDA%20or%20RF%20codes.%20You%20can%20use%20any%20names%20for%20this%20command%20instead%20of%20%22open-ac%22.%20As%20soon%20as%20the%20broadlink%20learns%20the%20code%2C%20you%20can%20put%20the%20address%20of%20%20http%3A//192.168.1.2%3A8080/sendCommand/open-ac%20to%20test%20your%20command.%20If%20it%20works%2C%20you%20can%20put%20it%20into%20your%20virtual%20sensor%20configuration%20page.%0A%23%23%23%23%20Domoticz%20into%20HA-Bridge%0APlease%20refer%20to%20reference%20link%202.%20From%20the%20chapter%20of%20Configuring%20HA%20bridge%2C%20it%20starts%20to%20describe%20how%20to%20configure%20HA-Bridge%20to%20import%20devices%20from%20Domoticz%20web%20service.%20%0A%21%5BAlt%20text%5D%28./1501401044317.png%29%0AAfter%20adding%20device%20from%20any%20device%20source%20like%20Domoticz.%0A%21%5BAlt%20text%5D%28./1501403754697.png%29%0ANow%20you%20can%20discover%20the%20devices%20by%20Alexa%20and%20also%20turn%20on/off%20them.%0A%0A%23%23%23%23%20HA-Bridge%20vs.%20Controlicz%0A%23%23%23%23%23%20General%20Smart%20Home%0AControlicz%20can%20integrate%20all%20type%20of%20devices%20into%20Alexa.%20For%20example%2C%20if%20Alexa%20doesn%27t%20have%20native%20support%20of%20this%20smart%20home%20device%2C%20you%20can%20build%20up%20a%20Domoticz%20server%20in%20your%20home%20and%20integrate%20it%20into%20Alexa%20by%20Controlicz.%20According%20to%20the%20description%20in%20Controlicz%20official%20site%2C%20it%20doesn%27t%20only%20support%20on/off%20switches%2C%20but%20also%20other%20normal%20appliance%20like%20TV%2C%20AC%20and%20etc.%20And%20Domoticz%20apparently%20support%20a%20lot%20more%20devices%20than%20Alexa%20does.%0A%21%5BAlt%20text%5D%28./1501404140819.png%29%0AHA-Bridge%20is%20simulating%20HUE%20light.%20To%20Alexa%2C%20these%20HA-Bridge%20based%20device%20is%20a%20HUE%20light.%20So%20it%20can%20only%20support%20on/off%20and%20dim%203%20actions.%0AFrom%20this%20point%20of%20view%2C%20these%202%20should%20not%20be%20put%20together%20for%20comparison.%20Controlicz%20is%20much%20stronger%20than%20HA-Bridge.%0A%0A%23%23%23%23%23%20%20Broadlink%20Integration%0ATo%20integrate%20Broadlink%2C%20these%202%20have%20their%20own%20pros%20and%20cons.%0ABroadlink%20is%20a%20universal%20remote%20controller.%20So%20every%20devices%20on%20Broadlink%20is%20a%20push%20button%20device.%20Each%20one%20only%20has%20one%20action%2C%20which%20is%20being%20triggered.%20This%20is%20even%20weaker%20than%20the%20on/off%20switch%2C%20which%20at%20lease%20has%202%20actions%20-%20on%20or%20off.%0AFor%20example%2C%20there%20is%20a%20button%20on%20Fan%27s%20remote%20controller.%20Pushing%20it%20once%2C%20it%20will%20turn%20on%20the%20fan%20and%20twice%20will%20turn%20off%20it.%20Through%20Controlicz%2C%20you%20have%20to%20say%20%22Turn%20on%20the%20Fan%22%20to%20Alexa%20to%20turn%20on%20the%20fan%20and%20you%20have%20to%20say%20the%20same%20sentence%20to%20close%20it.%20Is%20it%20weird%3F%0AIf%20you%20are%20using%20HA-Bridge%2C%20you%20can%20say%20%22Turn%20on%20...%22%20to%20turn%20on%20and%20%22Turn%20off%20...%22%20to%20turn%20off.%20Is%20it%20better%3F%0AThe%20biggest%20benefit%20of%20using%20Controlicz%20to%20integrate%20Domoticz%20is%20it%20can%20import%20all%20devices%20pre-defined%20in%20E-Control%20app.%20It%20can%20fully%20make%20use%20of%20the%20E-Control%27s%20GUI.%20You%20don%27t%20need%20to%20add%20virtual%20sensors%20one%20by%20one%20manually.%0A%0A%23%23%23%20Broadlink%20Native%20Skill%20+%20IHC%0AAfter%20bunch%20of%20work%20above%2C%20I%20happened%20to%20see%20there%20is%20a%20native%20support%20broadlink%20Alexa%20skill%20called%20%22broadlink%22.%20It%20should%20work%20with%20the%20latest%20version%20of%20IHC%20app.%20The%20bad%20news%20is%20both%20the%20skill%20and%20the%20app%20have%20very%20low%20review%20scores.%0A-%20IHC%20playstore%202.2%20stars%0A-%20Alexa%20Broadlink%20Skill%202.3%20stars%0A%0AAccording%20to%20the%20official%20examples%2C%20it%20can%20only%20support%20TV.%20And%20as%20my%20own%20experiments%2C%20when%20I%20added%20a%20TV%20and%20an%20AC%2C%20Alexa%20can%20only%20discover%20the%20TV%20and%20no%20AC.%0A%0A%0A%23%23%20Reference%20Links%0A1.%20%5B5%20open%20source%20home%20automation%20tools%5D%28https%3A//opensource.com/life/16/3/5-open-source-home-automation-tools%29%0A2.%20%5BAlex%20-%20Domoticz%5D%28https%3A//www.domoticz.com/wiki/Alexa%29%0A3.%20%5BDomoticz%20Wiki%20Plugins/BroadlinkRM2%5D%28http%3A//www.domoticz.com/wiki/Plugins/BroadlinkRM2.html%23First_Time_Users%29%0A4.%20%5B%23%u539F%u521B%u65B0%u4EBA%23%20%u7FA4%u6656%u5B89%u88C5broadlink-http-rest%u4EE3%u66FFRMBridge_%u751F%u6D3B%u8BB0%u5F55_%u4EC0%u4E48%u503C%u5F97%u4E70%5D%28https%3A//post.smzdm.com/p/551024/%29