Saturday, 11 February 2017

How to flash ESPEasy onto the Sonoff Touch for MQTT control

The Sonoff Touch is a nice glass touch panel based on an ESP8285 with 1MB of integrated flash that can be quite easily flashed with a self compiled version of ESP Easy.  You need to compile yourself as the builds available online are all made for the ESP8266 and will not work with the Sonoff Touch.

Thursday, 2 February 2017

How to enable Samba on the HASSBian image

The videos prior to 1st Feb 2017 like Ben's one below all indicate the following instructions for installing Samba but if you use the HASSBian image like I've now done, the path to 'Home Assistant' in the samba.conf file is wrong.


path = /var/opt/homeassistant

path = /home/homeassistant/.homeassistant

The updated instructions follow.

Installing Samba:
sudo apt-get update
sudo apt-get install samba
sudo nano /etc/samba/smb.conf

With nano open, hold down CTRL + K to remove all entries
Paste in the code below
CTRL + X to exit
Type Y then enter to save the updated file

netbios name = RP2
server string = The Pi File Center
workgroup = WORKGROUP
hosts allow =
remote announce =
remote browse sync =

path = /home/pi
comment = No comment
browsable = yes
read only = no
valid users =
writable = yes
guest ok = yes
public = yes
create mask = 0777
directory mask = 0777
force user = root
force create mode = 0777
force directory mode = 0777
hosts allow =

path = /home/homeassistant/.homeassistant
comment = No comment
browsable = yes
read only = no
valid users =
writable = yes
guest ok = yes
public = yes
create mask = 0777
directory mask = 0777
force user = root
force create mode = 0777
force directory mode = 0777
hosts allow =

Creating Samba User:

sudo smbpasswd -a pi
type password, press enter

Restart Samba Service:
sudo service smbd restart

Thanks to Ben for his excellent guides and videos.

Tuesday, 29 November 2016

Enabling the integrated Mosquitto broker on the HASSbian image

The Home Assistant image HASSbian has the Mosquitto MQTT broker integrated into the image but it is not enabled by default. To get it working and persistent on reboot, perform the following:
  1. sudo systemctl enable mosquitto
  2. sudo systemctl start mosquitto
  3. sudo reboot
To test, once your system is back up, type sudo systemctl status mosquitto.service and you should get back the following:

pi@raspberrypi:~ $ sudo systemctl status mosquitto.service
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto)
   Active: active (running) since Tue 2016-11-29 12:54:25 NZDT; 6min ago
  Process: 390 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mosquitto.service
           └─399 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Nov 29 12:54:24 raspberrypi mosquitto[390]: Starting network daemon:: mosquitto.
Nov 29 12:54:25 raspberrypi systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.

Note that by default, the HASSbian version of Mosquitto does not have a username and password set for MQTT unlike the all-in-one installer.

To add a password, follow the instructions on Ben’s video below at the 1:53s mark.

Thursday, 17 November 2016

Adding 4 relays to your Home Assistant Pi with Arduino UNO

For those that want 4 relays cheaply using a clone of the Seeed studio V2.0 relay board available on AliExpress here, this is how it's configured in HA. Simply follow the Arduino instructions to load the Firmata firmware on your board then plug the Arduino board into your Raspberry Pi.

Wednesday, 19 October 2016

Getting HADashboard up and running on Jessie for use with Home Assistant

HADashboard is a very cool dashboard for use with Home Assistant. I’ve tested the installation process on a Raspberry Pi1 version B (yes I know) and although it took nearly a whole day to get working, work it does and by golly, does it look good. More info on GitHub here
  1. First step is to install docker on your Raspberry Pi if you have never done that before:
    curl -sSL | sh
  2. If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like:
    sudo usermod -aG docker pi
  3. Set Docker to auto-start:
    sudo systemctl enable docker
More info here and credit to Alex Ellis

Tuesday, 18 October 2016

My Notepad++ tricks when editing YAML files in Home Assistant

To comment out a whole section in one go:Highlight the text you want to comment out and use CTRL + Q. If you do this at the start of a line, it will only comment that line. CTRL + Q is toggle mode (comment on/off). CTRL + K will allow you to add multiple comments one after the other.

To automatically insert two spaces when you use the TAB key:
  1. In the 'Tab Settings' list, scroll down to 'yaml' and click on it.
  2. Make sure 'Use default value' is unchecked. Set 'Tab size' to 2 and check 'Replace by space'
  3. Then click close and Notepad++ will use spaces instead of tab.
To fix trailing and leading spaces causing YAML errors:
The most common problems with config files is spaces or tabs where they do not belong, here are 2 ways to fix this.
  1. Open the file in Notepad++ then select Edit > Blank Operations > TAB to space,
  2. Then select Edit > Blank Operations > Trim Trailing Space
Online YAML Testers:

Thursday, 6 October 2016

Installing ha-bridge on your Raspberry Pi

EDIT: Updated 13th Feb 2017 to reflect version 4.1.4. Default port is now 80 to keep Google Home happy and service now supports MQTT! Advice on backups also added 7th Feb. Version 4x also supports adding a Home Assistant instance which is great!

Want to control your Vera, Harmony hub or Home Assistant entities with your Amazon echo or Google Home? ha-bridge is the best way to achieve that and installation is actually quite easy and takes less than 5 minutes. Here are the steps.

  1. On your Raspberry Pi, make sure you are in the Pi home folder:
    cd /home/pi/
  2. Then make a habridge folder:
    mkdir habridge
  3. Now change to the folder and download the latest ha-bridge jar file:
    cd habridge
  4. Create a ‘data’ holder inside the habridge folder:
    mkdir data
  5. Now you have to create the systemd service file:
    nano habridge.service
  6. Then copy and paste the following:

    Description=HA Bridge

    ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/habridge/data/habridge.config /home/pi/habridge/ha-bridge-4.1.4.jar


  7. Now, to save the file, hit CTRL-X, then hit Y and RETURN
  8. You need Java 8 JDK to be able to run ha-bridge
    sudo apt-get update && sudo apt-get install oracle-java8-jdk
  9. Then run:
    sudo update-alternatives --config java and select the JDK 8 version (/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java) if asked.
  10. Then run the following to confirm you have the right Java version:
    java -version
  11. Next you need to enable the systemd service so it will automatically start every time you reboot your Raspberry Pi (ignore the Shell script instructions on the ha-bridge ReadMe as newer Debian builds [Jessie] work best with systemd):
    sudo systemctl enable /home/pi/habridge/habridge.service
  12. Now that it is enabled, you have to start it. Since it is enabled, you don’t need the full path to run it:
    sudo systemctl start habridge
  13. The default port for HA Bridge is 80, so open your browser and go to your RPI address, port 80:
N.B If the ha-bridge version is updated, simply edit the WGET line in step 3 to download the correct version and edit the code used in step 6 (habridge.service) to reflect the correct version. If you want, you can have multiple versions downloaded in the habridge folder and simply switch between them by modifying the code in the habridge.service file (the ExecStart line).

  1. Stop ha-bridge either via the GUI or using sudo systemctl stop habridge.service
  2. Change into the ha-bridge directory cd /home/pi/habridge
  3. Edit the service file nano habridge.service
  4. Save the change then run sudo systemctl daemon-reload
  5. Start the service using sudo systemctl start habridge.service
  6. Check the status after a few seconds with sudo systemctl status habridge.service
If you want to control your Home Assistant entities with ha-bridge, there is a great guide here and here on Pete Scargill's blog There is also one on controlling the MiLight bridge here

Immediately after configuring the bridge and all of you devices, I would run a backup at the bottom of the "Bridge Devices" tab and the "Bridge Control" tab. If you do not choose a name, ha-bridge will automatically create one for you.

Bridge Devices is all of the individual actions you've created and if the defaults are left, the backup file will be located in /data and look something like device.db-2017-02-07-20-28-06.bk.

Bridge Control contains the actual bridge configuration like your Harmony Hubs IP, Vera, MQTT etc. The backup is located in /home/pi/habridge/data and looks something likes habridge.config-2017-02-07-20-28-19.cfgbk.

I strongly encourage you to remote in to your Pi using WinSCP and save these backup files locally just in case your Pi's SD card goes duff as mine has on three occasions now. Popping these backups into the appropriate folders after a rebuild certainly makes getting ha-bridge live again much simpler.

Wednesday, 31 August 2016

Using ESPEasy with Home Assistant via MQTT

Preface: I've just started playing around with Home Assistant on a Raspberry Pi and exploring the world of MQTT to control devices on the network. Learning curve is a bit steep but worth the effort as MQTT is very fast.

The hardware and software tools I'm using are as follows:
2 x Sonoff relay units
2 x NodeMCU Boards
ESPEasy firmware (must be version 121 or above as that contains the MQTT 'retain' flag option.
Home Assistant software on Raspberry Pi2
MQTT Test Software:
Android: MQTT Dashboard

IMPORTANT: To ensure ESPEasy MQTT works with Home Assistant, make sure you set the MQTT protocol to OpenHAB MQTT under the config tab.

I have flashed the Sonoff units with ESPEasy (R121) and there is plenty of info online on how to do that. The code to use with the rules section for relay control via the switch is below. It will also report the relay state via the LED if remotely controlled via MQTT.
on relay#state do
  if [relay#state]=0
on button#state do
  if [button#state]=0
Note that the items highlighted refer to devices that have been configured in the devices list below and must match (case sensitive).