Categories
Connected Farm

Home Assistant for Farming, Install Guide with Remote MySensor Gateways

Updated (28/12/21)

I have been using Home Assistant running on a Raspberry Pi 3 as a home, garden and farm automation server since 2019, the amount of automations running has increased and the Pi 3 is starting to struggle. In this post I will document my upgrade to the Raspberry Pi 4 but this time I will not be using the official install method as I need to add VPN functionality to connect to remote sensor gateways on different farm blocks.

Instead of running the complete Home Assistant OS, I’m installing it on Raspberry PI OS this is so I can install the full WireGuard VPN on the same machine. I tried the WireGuard addon for Home Assistant but it had some routing issues.

Raspberry Pi OS install.

First download the Raspberry Pi OS Lite from: https://www.raspberrypi.org/software/operating-systems/#raspberry-pi-os-32-bit and write to an SD card using imager software on your PC such as BalenaEtcher https://www.balena.io/etcher/.

Next remove the SD card from the PC and then re-insert, (don’t click on format if prompted by windows). To enable SSH create a new text file with notepad, in the new file put in one space and nothing more, call the file ssh and save and close it.

If WiFi is needed, then you need to create a second file called wpa_supplicant.conf and paste in the contents below adjusting for the country code, your WiFi name and password. If using Ethernet you can skip.

  country=IE
  ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
  update_config=1

  network={
      ssid="NETWORK-NAME"
      psk="NETWORK-PASSWORD"
  }Code language: JavaScript (javascript)

Windows may add .txt to the end of the file names and hide it, which will need to be removed. So click view at the top of the folder window and tick the box for file name extensions. Then right click on each file and rename without the .txt, ignore any warning about changing file name extensions.

With file name extension view on and the files renamed correctly they should look like below. The icons have changed from the Notepad icon to a blank page icon.

Next place both files in the root directory of the boot SD card. The SD card can now be removed from the PC and inserted into the Raspberry Pi. The Raspberry Pi can now be booted up for the first time, there is no need for a keyboard mouse or monitor as we will be using Putty to access the OS and a web browser to access Home Assistant.

Install Putty from https://www.putty.org/ on your PC if you don’t already have it. You will now need the IP address of your Raspberry Pi, which you may be able to find through your router by checking for connected clients, but I like an app called Fing available as a phone app and on PC https://www.fing.com/, the free versions are more than enough.

Once you have Putty installed and the IP address entered click open. You should be prompted for a login, the username is pi and password is raspberry.

Next we run a script included with the OS to change some system settings:

sudo raspi-config

Go into System Options and set a new password and change the hostname to HomeAssistant. Next go to Advanced options and expand filesystem to make use of the entire SD card. Then Finish and reboot.

Home Assistant Installation. (Updated 28/12/2021)

Next we need to install Home Assistant, enter each command one line at a time, some of them may take some time to complete.

sudo -i

apt-get install -y software-properties-common apparmor-utils apt-transport-https ca-certificates curl dbus jq network-manager

systemctl disable ModemManager

systemctl stop ModemManager

curl -fsSL get.docker.com | sh

sudo usermod -aG docker pi

wget https://github.com/home-assistant/os-agent/releases/download/1.2.2/os-agent_1.2.2_linux_armv7.deb

dpkg -i os-agent_1.2.2_linux_armv7.deb

apt install udisks2

apt --fix-broken install

wget https://github.com/home-assistant/supervised-installer/releases/latest/download/homeassistant-supervised.deb

sudo dpkg -i homeassistant-supervised.deb

exitCode language: PHP (php)

You should now be able to access the Home Assistant interface from a web browser using http://YourRaspberryPiIP:8123/ Don’t worry if it doesn’t work straight away as it could take a while for the install to complete, but within a few min you should be able to see the below screen.

How to set up and use Home Assistant to power your smart home

Remote Access setup.

Home Assistant will require remote access and if like me you don’t have a static IP then there is an Addon named DuckDNS which will help here. I found this article which I think has the best setup to allow remote acccess while retaining local access using the NGINX addon also. https://help.konnected.io/support/solutions/articles/32000023964-set-up-hass-io-with-secure-remote-access-using-duckdns-and-nginx-proxy

Both Addons can be installed from the addon store from the Supervisor.

First setup a new account with https://www.duckdns.org/ chose your domain name and copy the token from your new account.

Configure the DuckDNS addon from the Supervisor Dashboard and under the configuration TAB, change accept terms to true, add your token and domain name.

Next setup NGNIX with your domain name, other settings can remain default.

Finally you will need to setup port forwarding on your router, how to do this will vary with different makes/models of router. On some routers it may be called port mapping. It is also a good idea to either set a static IP on the Raspberry Pi or static reservation on the router to ensure the Pi always has the same IP address.

If you forwarded port 443 to 443 then you should be able to access your Home Assistant from https:\\YourDomainName@duckdns.org, if you’ve chosen a more obscure public port then it will be https:\\YourDomainName@duckdns.org:portnumber

VPN Configuration

Now Home Assistant should be up and running and accessible from the internet, next we will configure a VPN for the remote nodes, for this we will need to login again using Putty to get back to the OS command line. The following command will install the VPN

curl -L https://install.pivpn.io | bashCode language: JavaScript (javascript)

Follow the on screen instructions, chose WireGuard as the VPN, and DNS entry is your DuckDns.org domain name as setup earlier, other options can be left default. You will also need to forward the UDP port configured during this setup.

After install is complete we can configure clients using the following command.

sudo pivpn add

name the client MySensors

The contents of the client configuration files can be copied from /home/pi/configs and copied to the VPN client devices which will be configured in the next post.

cd /home/pi/configs

nano MySensors.conf

Any questions on this or any other post please feel free to ask in the comments section.

Facebook Comments