Usually we put HA on PC or Raspberry Pi. It’s OK but a 24-hours-running rpi or PC may bring some extra costs and inconvenient. While, actually most homes have a router for varieties of wireless devices. The router keeps running for 365*24 hours. If installing HA on a router, we could save not only cost for some extra equipments but the space occupied by these equipments.
Requirements for router:
- The OS running on your router have to be OpenWrt or some other Linux-like systems
OpenWrt is OK. Following installation is on OpenWrt. I didn’t test other Linux-like systems. But following steps may help you install HA on your own system. In fact, if you can install “python3(>=3.5), gcc, libssl, libffi, libsodium” in your system, very likely it’s OK.
- Enough flash and RAM space
From my example, necessary tools and libraries require at least 180MB flash space, HomeAssistant itself requires at least 190MB flash space. Totally 400MB flash space may be enough ( more components require more space ). Note that you can move the HomeAssistant to a SD card or some other external storage devices connected to the router.
When HA is running, it takes at least 120MB RAM space. So make sure your router has more than 120MB RAM space left.
The router I use for this demo is GL-S1300 from gl-inet. It has Quad-core ARM CPU, 512MB RAM and 8GB EMMC flash. Fully meets our needs.
1. Configuring the python3 environment
opkg update opkg install python3
After python3 installation finished, using command
python3 --version to confirm that the version is greater than 3.5. Then install python3-pip. The OpenWrt official pip is low version, so install latest python3-pip like this:
curl https://bootstrap.pypa.io/get-pip.py > get-pip.py python3 get-pip.py
2. Configuring necessary tools and libraries
- Install compile tool “GCC”
opkg install gcc
- Install some necessary libraries
opkg install libopenssl libffi libsodium python3-dev
- Configuring some libraries headers
(Some libraries in OpenWrt didn’t have headers, installation would report error like “Cannot find xxx.h”. So we copy these headers manually. All these required headers are provided here https://github.com/gl-inet/home-assistant-on-openwrt.)
Copy libopenssl headers and create soft-link “libffi.so”
mkdir -p /usr/include/ffi cp ffi.h /usr/include/ffi/ cp ffitarget.h /usr/include/ffi/ ln -s /usr/lib/libffi.so.6.0.1 /usr/lib/libffi.so
Copy libopenssl headers and create soft-link “libcrypto.so libssl.so”
cp -r openssl/ /usr/include/python3.6/ ln -s libcrypto.so.1.0.0 libcrypto.so ln -s libssl.so.1.0.0 libssl.so
Copy libsodium headers and create soft-link “libsodium.so”
cp sodium.h /usr/include/python3.6/ cp -r sodium/ /usr/include/python3.6/ ln -s /usr/lib/libsodium.so.23.1.0 /usr/lib/libsodium.so
3. Install python module
HomeAssistant would install all the necessary python modules automatically.
But some python module will report errors when installed in this way. We have to install them manually.
SODIUM_INSTALL=system pip3 install pynacl
curl https://files.pythonhosted.org/packages/07/ca/bc827c5e55918ad223d59d299fff92f3563476c3b00d0a9157d9c0217449/cryptography-2.6.1.tar.gz > cryptography-2.6.1.tar.gz tar -xzvf cryptography-2.6.1.tar.gz cd cryptography-2.6.1 LDFLAGS=-pthread python3 setup.py install
4. Install HomeAssistant
Now all the necessary tools and libraries are ready, we can install the HA.
python3 -m pip install homeassistant
5. configuring the HA
Following steps is the same as in PC or RPi. Waiting for it finished.
Notice that the HA will bind the httpd to wan ip defaultly. It causes you cannot visit the web in router’s lan port.
Add this to the configurarion.yaml to modify the http to lan port
http: server_host: 192.168.8.1 server_port: 8123
Restart HA and visit the web at 192.168.8.1:8123
I write a one-click installation script for GL-S1300 which use OpenWrt 15.05.
Other openwrt versions or Linux-like OS can refer to this. Details on https://github.com/gl-inet/home-assistant-on-openwrt.
We would provide some GL-S1300 samples for anyone want to test HA on OpenWrt.