Following on from the previous guide on how to enable remote starting and shutting down of a FreeNAS I’ll be showing you how to view your FreeNAS statistics and messages in Home Assistant. For this guide I’m once again going to be using the FreeNAS API. The FreeNAS dashboard has evolved into a nice little visual hub for viewing important data but as I have Home Assistant open on my desktop a lot more often than the FreeNAS web interface I wanted to import and display that data in my UI. The sensor I’ll be setting up in this guide will give me a report of the following:
The name of my volume
The current status of my volume
The used percentage of my volume
Whether the volume is decrypted
Once you’ve understood the basics you’ll be able to add any of the values available through the FreeNAS API. Based on these values you can also set up notifications such as a push notification if you’re volume were to become unhealthy.
Setting up the FreeNAS sensor in Home Assistant
As I’m not executing any commands, such as shutting the system down, this setup will be using sensors and not rest_command. Any of the following variables can be enabled in using the RESTful integration (just add or remove them under the json_attributes):
status: The current status of the Volume
vol_guid: The volume’s Globally Unique Identifier
name: The volume’s name
used_pct: The percentage of used storage
used_si: The amount of storage currently used
is_decrypted: Whether the volume is decrypted or not
avail_si: Available storage
total_si: The volume’s total storage
To get this API call to work, I’ve once again referenced the username and password in my secret.yaml file. For more on that topic you can check out my previous guide here.
This code will create a new entity with the desired attributes. But, as you might find out, this isn’t very practical. With this entity you won’t be able to embed individual information in your Lovelace UI and you can’t easily use the values in automations. What I did was create a template sensor for each individual value.
Update 13 December 2019: Changed mac_address to mac
Besides my application server running Proxmox VE I have a NAS (Network Attached Storage) containing plenty of media, backups of my photography, and many delicious recipes. My NAS is currently running the FreeNAS operating system and despite it’s many faults, I’ll be sticking to that OS for the foreseeable future. My NAS is far from perfect. In fact, it’s borderline embarrassing. I bought the cheapest case I could find and fitted the absolute minimum of hardware. It isn’t particularly quiet and nothing is dampened so during writes this thing gets loud. Seeing as it sits right next to where I sleep there’s no way of leaving it turned on 24/7. This is where Home Assistant enters the fray. I needed a way of remotely turning my FreeNAS on and off as it sits in a shelf that isn’t easy to reach. And this is what the endresult looks like in my Lovelace UI:
For this to work I’m using the FreeNAS API to trigger a system shutdown from Home Assistant. Turning on the FreeNAS is way easier thanks to Wake on LAN (WOL) integration in Home Assistant. Let me start by showing you how to use the WOL switch to turn on your FreeNAS instantly.
Turning on a FreeNAS using Home Assistant
If you’re considering implementing this I’m going to assume you are technically well versed and understand the basics of Home Assistant and FreeNAS. For the WOL switch to work you need to know the IP (though this is technically only optional) and MAC of your FreeNAS. To find out your MAC simply enter the command ifconfig in your FreeNAS’ shell and look for hwaddr. The IP is solely used for Home Assistant to figure out if your FreeNAS is turned on or not. So if you’re going to use the switch in the UI I’d recommend adding the IP.
Turning off a FreeNAS using Home Assistant is slightly more complex. There’s no reverse WOL or anything similar and no universal way of handling shutdowns so instead I’ve opted to use the FreeNAS API. To make the API call simply create a REST command containing the following details:
As you might have noticed, I’ve used the secret file to store my credentials. I had to use root to get this API call to work. There might be a nicer and safer way of doing this. To do this simply open the secrets.yaml on your Home Assistant server and enter the following on a new line:
In the third Beginner’s Guide I showed you how to enable the Homegraph API to allow the Google Assistant to sync devices with Home Assistant. Today I’ll be showing you a few lines of code that will sync the two platforms every time you reboot your Home Assistant. As a tinkerer’s tool, you will be rebooting very often, so it’s quite handy to use this automation. Just add these lines (no adjustments needed) to your automations.yaml:
- alias: 'Update Google Assistant on start of Home Assistant'
Let’s clear up a few misconceptions: When talking about Google Home (GH) I mean the hardware, the physical speaker that sits in your home, and Google Assistant (GA) is the software that runs on top of that hardware. Many, including Google, use the two synonymously. However this integration will not just connect your smart speaker with Home Assistant. The Google Assistant runs on just about anything and it’s reach is increasing with almost daily. Anything from your phone to watches to security cameras and washing machines run the Google Assistant. It’s just that Google Home was the first device that brought Google Assistant into our homes.
Be warned before you start this guide: This is by far the most complex thing we’ve done so far. There’s a fair bit of coding involved and we’ll be working with more than one different tool. With that said, I’ll try to explain things in the simplest way possible. After all, this is a Beginner’s Guide!
What will be done and what to expect
In this guide we’ll be going through the steps on how to integrate your Home Assistant with the Google Assistant (and thus your Google Home). By the end of this guide you’ll be able to ask your Google Assistant to turn the lights on with a specific colour and manage most of your devices that have been added to your Home Assistant.
There are two main requirements for the Google Assistant and Home Assistant:
The obvious one: You need a smartphone that is compatible with the Google. This can be an iOS or Android device. You do not need a Google Home device for this integration to work, it just makes things more convenient.
The less obvious, but soon will become apparent, one: Your Home Assistant has to open to the internet. You can find out how to do that in my Beginner’s Guide Part 2.
This has already been pointed out in the first Beginner’s Guide but I’ll mention it again: Using an advanced text editor, such as Sublime Text will make editing files so much easier.
This guide was written for Windows users. I don’t have any Apple devices and as such couldn’t test any of the steps.
First up, you’re going to want to download the gactions CLI. This is the command line interface used to test and update your integration. Download the correct version for your OS (in most cases this will be x86_64) and copy the file into a new and empty folder. In the same folder create a text file and rename it project.json (make sure you have File name extensions in explorer enabled, otherwise you will end up with a file called project.json.txt). Open the file with Sublime Text. Update and copy the following code into it (use the URL you previously created with Duck DNS):
Go to the Actions on Google developer console and create a new project. Enter a suitable project name (I went for Home Assistant, how imaginative) and your country. Click on create project. You’ll be greeted with a new window containing many complicated sounding words. Don’t worry, I don’t understand any of it either. We’re only interested in the Actions SDK. Click on Build. Copy the code ($ gactions update…) and paste it into an empty notepad, we’re going to need that.
In the notepad, replace PACKAGE_NAME with project.json and replace the $ with ./ if you’re running Windows. This is what you’re code should look like on a windows machine:
Open the folder we created for the gactions CLI in the File Explorer, hold down shift and right-click anywhere inside the folder. You should see Open PowerShell window here in the right-click menu somewhere. Click on that. Copy and paste the code from your notepad and paste it into the PowerShell window using CRTL+V. Hit the Enter/Return key on your keyboard to run the code.
After running the code you will be prompted to visit a URL. Copy and paste that URL into a browser and allow Assistant CLI to view and manage your Actions on Google. You will receive a long string of code in return for the permission. Copy that code and paste it into the PowerShell window. After a short time a message containing a URL will be returned. Copy the URL in the message.
Open the copied URL in a browser and fill in the required App information. Once again, it isn’t really important what you add but I always like to keep it relevant. Once Google is happy with the information you’ve given, click save. Don’t worry about entering private information, this Action will never be publicly released.
Click on the back arrow and select Account linking. Click Edit. Fill in information (has to be added but isn’t important). Click on Add in the following prompt. Select the following:
Grant type: Implicit
For the Client ID we’re going to create a long, randomly generated and secure string. Use something like the Random Password Generator for this and make sure to select the maximum length. Save this string in a notepad, we’re going to need it later (I recommend you add the description Client ID too)! The Authorization URL is your Home Assistant URL with ]/api/google_assistant/auth added to it:
Add two scopes: One being name, the other one email. Following that, enter some random gibberish in the testing instructions and click save.
Finally, with all the information entered, click on TEST DRAFT.
With everything sorted out, click on the settings cog in the top-left corner and open the Project settings. Here you’ll find your Project ID. Copy it into your notepad (again, give it a description).
This is an optional step but is highly recommended. The Homegraph API will allow you to ask your Google Assistant to “sync my devices”. That command will sync your Home Assistant devices with the Google Assistant each time you add a new one or change an existing one. To enable the Homegraph API, follow these steps:
Restart your Home Assistant from the Web UI and wait for it to restart.
Google Home app
Open the Google Home app on your smartphone and navigate to Home control (you’ll find it in the menu). Click on the big + button to add new devices (in this case the home assistant). The project we have just created will located at the very top of the list and will prefixed by [test]. Add the device and all of your devices set up in Home Assistant will show up!
Now that we’ve got our Home Assistant set up using Hass.io, it’s time to move on to more interesting matters. If you’re anything like me, the first thing you might want to do is control your Home Assistant using a Google Home speaker or the Google Assistant on your phone. And while we’re at it, wouldn’t it also be nice to be able to access the Home Assistant when you’re not at home? Luckily for you, that’s exactly what we’re going to be doing today!
The following steps might want to be avoided by anyone with privacy concerns. Following this guide will open up your Home Assistant to the big, bad internet. It’s more important than ever to set a password for your Home Assistant before going any further (you can find out how to do that in part 1 of the Beginner’s Guide). In this guide I’ll be showing you how to open your Home Assistant to the internet, configure a custom URL (using Duck DNS) with encryption (using Let’s Encrypt) and what ports you have to open on your Router.
Getting an custom Home Assistant URL with Duck DNS
To get things started, sign up to Duck DNS. Duck DNS is a free dynamic DNS. To put things simply, this service will translate your router’s public IP into an easily remembered URL. You could just enter your router’s public IP into your browser to access Home Assistant but there is one main drawback. The main reason you can’t just use the router’s IP is because it changes. Duck DNS will regularly check your the IP and update the settings so you’ll always have access to your Home Assistant.
Adding a new domain to Duck DNS
Once you’ve signed up to Duck DNS you can add a new domain. Just enter your desired URL into the field following http and click on ‘add domain’. In the top half of the window you’ll also see some information like your account and account type. Keep this window open because we’ll need the token later on.
into your browser of choice. Access the add-on store (it’s located under Hass.io in the menu and look for the add-on Duck DNS. Install the Duck DNS add-on and enter the add-ons settings by clicking on its card. The default settings are shown in the screenshot below:
Remember that token we saw on the Duck DNS website? It’s time to copy that and enter it into your Duck DNS settings. Enter the token and domain you registered so you’re settings look like the following (fields that have to be edited have been highlighted in bold):
Unfortunately the Duck DNS add-on can’t take care of quite everything and there are a few lines of code we’re going to have to add to the Home Assistant’s configuration.yaml file. Open the file using your favourite editor and enter the following:
api_password: YOUR PASSWORD
base_url: YOUR DUCK DNS URL
As you can see in my screenshot, I’ve not included the api_password and base_url in my configuration.yaml file and have instead added these to the secrets.yaml file (more about that here).
Port forwarding your Home Assistant
The final step is telling your router what device to look for, when entering the URL into your browser. This is achieved by port forwarding. This step will be a bit different for everyone, because all router interfaces look a bit different. Somewhere in the settings you’ll find the option port forwarding and you’re going to want to enter the following:
Entry port: Single port / 443
Destination port: Single port / 8123
The final step will be to check your configuration in the Home Assistant interface and restart it. You should now be able to access the Home Assistant using the costum .duckdns.org domain you’ve chosen!
In this first part of the Home Assistant Beginner’s Guide guide we’ll be going over the basics: A quick explainer on what Home Assistant and Hass.io are, followed by the hardware requirements and installation of Home Assistant on top of Hass.io. This Home Assistant Beginner’s Guide was written using Home Assistant 0.66.1, although major changes to the installation aren’t expected anytime soon.
Flying cars, robot butlers and automated homes. Sci-fi movies of years gone by predicted we’d have them all by now. My drone can’t fly down to the shops yet and although we have robot vacuums, they won’t be cooking our food anytime soon. One prediction that is becoming a reality though is the automated home. You can tell your Google Home to play a series on your Chromecast enabled TV and your Philips Hue lights can automatically turn on when you get home from work. But what if I want my lights to turn automatically when I play said movie? Or what if I want to add lights from a different brand to my setup? Here’s where the current closed systems fail. To solve this problem, there are commercially available platforms you can buy or you could go down the tinkerers route and build your own. I went for the latter and built my own home automation platform using Home Assistant and Hass.io!
Home Assistant is an open-source home automation platform and is still very much in the early stages of development. As mentioned, it is very much a platform for tinkerers. Whilst some things can be configured using the UI, sooner or later you will be forced to dive into the code. As always, it’s highly recommend to keep back-ups of everything you do. My naïvety led me to perform an update without backing up. My system just broke. There was nothing I could do except for a complete reinstall. I know, typical beginners error. But on the bright side, it did give me a chance to document what I’m doing and create this Home Assistant Beginner’s Guide.
Observe the state of your smart-devices (e.g. check if the lights are on, get the temperature from a thermostat, see what’s playing on a Chromecast).
Control all of your devices from a single interface (e.g. turn the lights on and off, set the temperature on a thermostat via the web based UI).
Make your home adjust to what you’re with automation (e.g. turn on the lights when you get home, message you if you left something turned on when you leave the house).
Additionally Home Assistant is also perfect for everyone with privacy concerns. None of your data is stored in the cloud and you can keep your platform completely disconnected from the internet, if you choose to do so.
Getting Started with Hass.Io and Home Assistant: the Hardware
Hass.io is built to run on a Raspberry Pi, a cheap single-board computer. Whilst there are builds available for older and cheaper models, you’ll find them reaching their limits sooner rather than later. The Raspberry Pi can be bought from just about any electronics store and I highly recommend buying a set including a power supply and a case.
Next up, you’ll need a microSD card. A 32GB is recommended but mine is working fine with just 16GB. Make sure you don’t just go for the cheapest card. Class 10 is recommended for reliabilities sake. Of course you’ll also need a way to read the card on your desktop PC or laptop.
While Hass.io can be operated and accessed using a WiFi connection, I recommend connecting it to your router or switch using an ethernet cable. The connection will be more stable and faster (plus, the setup is easier).
With these three hardware requirements at your disposal, you’re ready to get Hass.io and Home Assistant installed!
Getting Started with Hass.io and Home Assistant: the Software
With the hardware ready you’re going to want to install Etcher and an advanced text editor like Sublime Text (my recommendation). Next, download the latest Hass.io image from here. Just make sure you select the image matching your Raspberry Pi model. Insert the microSD card into your computer and use Etcher to burn the Hass.io image to your card following these steps:
Click on ‘Select image’ and choose the .img.bz2 file you downloaded from github.
Make sure the correct microSD card is selected by clicking on ‘Change’ (if you only have one inserted into your computer, only one possibility should appear).
Click on ‘Flash’ and wait for your image to be burnt on to the microSD card.
Installing Hass.io and Home Assistant
Once the image has been successfully burnt to the microSD card, simply eject the card, insert it into your (unconnected) Raspberry Pi and connect the ethernet and power cable. That’s it! Because Home Assistant is set up to be a headless system, there’s no need to connect a monitor or keyboard to your Raspberry Pi. Everything is controlled from a browser on another computer. Your Home Assistant will quietly be installed on the Raspberry Pi and should be ready in about half an hour.
To access you Home Assistant simply navigate to http://hassio.local:8123 in your browser of choice. Should that not work (a problem I’ve always experienced), you can use your router’s device list to look for an IP:
If you do not know where your router is located: Press the ‘Windows’ and ‘R’ and open cmd. Type in the command ‘ipconfig’ and look for your Default Gateway (192.168.X.Y). That is your router’s IP address.
Enter the router’s IP in your browser and login. Search for a device list in the menu. You should see a device called hassio somewhere in the list. Copy the IP (192.168.X.Y) and paste it into your browser. Add :8123 (that’s the port) to the IP to access your Home Assistant. Your full address should be something like 192.168.X.Y:8123.
Using the Configurator
Once you’ve gained access to your Home Assistant, you’ll be greeted by the UI that can be used to control your smart-devices. This interface will look very familiar to any Android users, as it follows the material design guidelines. You’ll also notice that a few devices will already have been added (such as Chromecast and Google Home devices) and the presence of the the Configurator. As I’ve mentioned, there are some devices that can be set up using the UI. One example I have in my home are Philip Hue lights. Simply click on ‘Configure’ to get started. Should you have any difficulties during the setup you can search for each component on here to get a guided walkthrough.
With your devices added, you’ll be able to manually control the added devices from the UI. At this point you might be thinking there’s no point to using Home Assistant over the devices own app (such as the Hue Android app). Don’t worry, in the upcoming guides I’ll be showing you how to make the most of Home Assistant and why it’s so much more powerful than any other software!
Installing your first add-on
Before we dive in any deeper, you’re going to want to install a specific add-on: The Samba share. This add-on will allow you to access your Home Assistant configuration files from your PC.
To get started select Hass.io from the menu and go to the add-on story.
Look for the Samba share add-on, click on it and hit Install.
Once the add-on is installed click on start. That’s it. Make sure you have Start on boot enabled and I’d also recommend enableing Auto update.
To see your files press Windows + R and enter ‘\\hassio’. By default you’ll be greeted by the folders addons, backup, config and share.
Securing Your Home Assistant
It’s never a good idea to have unprotected devices in your network and doubly so if it’s a device controlling your home. Before we go any further, setting a password is essential. By doing this you’ll also get a first look at the code that powers your Home Assistant. To get started navigate to your Home Assistant in Windows Explorer (\\hassio) and enter the config folder. Follow these steps to set a password:
Open configuration.yaml with Sublime Text and look for # api_password: !secret http_password. Let us dissect this line of code:
The # means this line of code is a comment and will be ignored. By removing the # and space (this is very important) this line will not be ignored anymore.
The api_password is the setting we want to edit, i.e. password protecting your Home Assistant.
Passwords shouldn’t be saved in this file. For added security, you can save password in the secrets.yaml file. !secret http_password will tell your Home Assistant to look for the password in the secrets.yaml file, under the description http_password.
Now that we’ve uncommented (removed the #) the api_password we can open the secrets.yaml file and set a password. Replace welcome with whatever you want your password do be.
Save and close both files.
Open the Home Assistant web UI. Click on Configuration.
I recommend you do this after each time you change any code: Click on Check config. This will go through your files and make sure everything is in order with your code. If you receive any errors, go through the code again and only restart your Home Assistant once you get the Configuration valid! Message!
Scroll down and restart your Home Assistant. Wait for the system to reboot and once you try to access it you should be presented with a password prompt.
Creating a Snapshot
Now that we’ve got things installed and running it’s high-time to create a first snapshot (backup) of the platform. To do this simply click on Hass.io in the left hand menu, select Snapshots and create a Full snapshot.
So there you have it. You’ve successfully installed Hass.io and Home Assistant on your Raspberry Pi and have added a first add-on. The first part of the Home Assistant Beginner’s Guide is complete but we’ve only just scratched the surface. There’s so much more to Home Assistant to what we’ve just done and I’m excited to share all of my discoveries in the coming weeks and months.