Continuation from Part I

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 seven and eight 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.

  1. Change the password of the default user pi from ‘raspberry’
    • Passwd

  2. 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

  3. Edit config.txt to enable PiFace (platform: rpi_pfio)
    • Sudo nano /boot/config.txt
      • Uncomment
        • dtparam=spi=on

  4. 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

  5. Use hasbian-config to install additional packages
    • sudo hassbian-config install mosquito
         
      (MQTT broker)
    • sudo hassbian-config install samba
         
      (Adds home share for the raspberry Pi)

  6. 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

  7. With samba, you can use Notepad++ to edit configuration YAML files on PC

  8. Install MySQL and MySQL Client from switched instructions
    • sudo apt-get install libmysqlclient-dev
    • sudo apt-get install python-dev python3-dev
    • sudo apt-get install mysql-server
         
      (Create root password when prompted)
    • 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;
    • sudo su -s /bin/bash homeassistant
         
      (Enter the virtual environment)
    • source /srv/homeassistant/bin/activate
    • pip3 install --upgrade mysqlclient
    • exit

  9. 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

        (XXX is your password)

  10. Install Docker from their repository per TaperCrimp instructions
    • curl -sSL https://get.docker.com | sh

  11. Rebuild the Docker instance of smartthings-mqtt-bridge
    • docker build -t smartthings-mqtt-bridge -f Dockerfile-rpi