Software Design
As their website states: Home Assistant is an open-source home automation platform running on Python 3. Track and control all devices at home and automate control. Perfect to run on a Raspberry Pi.
Because I was going to run my Raspberry Pi headless, I installed PuTTY on my Windows 10 machine for SSH.
One of the first things I noticed was that my keyboard number pad didn’t work in PuTTY. It turns out that in the Raspberry Pi the default keyboard is “gb” and I needed to change it to “us”. This was done by editing the /etc/default/keyboard file to change XBBLAYOUT=”us”.
I also found the right mouse button, which is used for pasting text, to be overly sensitive. I changed the PuTTY configuration for the “Action of mouse buttons:” to “Windows…” from “Compromise…” so that a right mouse click now displays a context menu instead of just pasting what’s in the buffer.
There a currently three ways to install Home Assistant on a Raspberry Pi: from a complete turnkey installation, Hass.io to an All-in-One installer on top of Raspbian to a customized operating system, HASSbian.
I decided to go with HASSbian because it still allowed some access to the OS, and then used the standard instructions for a wired network. HASSbian provided support for most of what I needed but not SmartThings which required additional steps for installation and configuration. Also, since Home Assistant is written Python 3, you have access to all the source files at /srv/homeassistant/lib/python3.4/site-packages/homeassistant in case you need to edit them.
These are the steps I did to update and configure HASSbian after the initial installation. Steps nine and ten are for changing the database that is used for the recorder to MySQL, which has much better performance. Steps nine through fourteen are for adding SmartThings support.
- Change the password of the default user pi from ‘raspberry’
- Passwd
- Passwd
- Change swappiness to 10 in 98-rpi.conf since swap on SD Card
- Sudo nano /etc/sysctl.d/ 98-rpi.conf
- Add
- vm.swappiness = 10
- vm.swappiness = 10
- Edit config.txt to enable PiFace (platform: rpi_pfio)
- Sudo nano /boot/config.txt
- Uncomment
- dtparam=spi=on
- dtparam=spi=on
- Uncomment
- Sudo nano /boot/config.txt
- Install raspi-gpio for checking rpi_gpio pins
- sudo apt-get install raspi-gpio
- sudo raspi-gpio get xx (xx - GPIO pin)
- Edit Home Assistant configuration file to use PushBullet
- cd /home/homeassistant/.homeassistant
- sudo nano configuration.yaml
- Add
notify:
platform: pushbullet
api_key: 'YOUR_KEY'
name: pushbullet
- Add
- Use hasbian-config to install additional packages
- sudo hassbian-config install mosquitto
(MQTT broker) - sudo hassbian-config install samba
(Adds home share for the raspberry Pi)
- sudo hassbian-config install mosquitto
- Edit smb.conf to add additional shares
- sudo nano /etc/samba/smb.conf
- Add
[home]
path = /home/pi
writeable = yes
guest ok = yes
create mask = 0644
directory mask = 0755
force user = pi
- Add
- sudo systemctl restart smbd.service
- sudo nano /etc/samba/smb.conf
- With samba, you can use Notepad++ to edit configuration YAML files on PC
- Install MySQL and MySQL Client from switched instructions
- sudo apt-get install libmysqlclient-dev
Or if using the MariaDB: - sudo apt-get install libmariadbclient-dev
- sudo apt-get install python-dev python3-dev
- sudo apt-get install mysql-server
(Create root password when prompted) - sudo mysql -u root -p
(Enter root password) - CREATE DATABASE hass_db;
- CREATE USER 'hassuser'@'localhost' IDENTIFIED BY 'XXX';
(XXX is your password) - GRANT ALL PRIVILEGES ON *.* TO 'hassuser'@'localhost';
- FLUSH PRIVILEGES;
- QUIT;
- sudo su -s /bin/bash homeassistant
(Enter the virtual environment) - source /srv/homeassistant/bin/activate
- pip3 install --upgrade mysqlclient
- exit
- sudo apt-get install libmysqlclient-dev
- Edit Home Assistant configuration file to use MySQL
- cd /home/homeassistant/.homeassistant
- sudo nano configuration.yaml
- Add
recorder:
db_url: mysql://hassuser:XXX@127.0.0.1/hass_db?charset=utf8(XXX is your password)
- Add
- Install Docker from their repository per TaperCrimp instructions
- curl -sSL https://get.docker.com | sh
- curl -sSL https://get.docker.com | sh
- Rebuild the Docker instance of smartthings-mqtt-bridge (all one line)
- sudo docker build -t smartthings-mqtt-bridge -f Dockerfile-rpi \
- sudo docker build -t smartthings-mqtt-bridge -f Dockerfile-rpi \