Step 12: External

Just because this is a cloud free setup does not mean that you won’t be able to access your system while you are out and about. Problem is, depending on your requirements and budget, there are a plethora of ways to achieve this.

So, lets look at two base options: domain name with a static (or relatively) IP address and the dynamic dns option. After that you can choose between direct firewall access to port 8123 or push through a reverse proxy, don’t worry Home Assistant can help with lots of this.

Ultimately, you want to be able to login to your home Home Assistant system via the mobile app or browser to manage and monitor your home.

  • Domain Name
    • get an awesome domain name with a basic DNS
    • point the domain at your home IP address with an A record
    • prove you can access http://<domain>:8123
  • Dynamic DNS
    • get a duck dns account
    • install duckDNS via the Supervisor:
      • Supervisor -> Add-on Store
    • configure with token and subdomain
      • here you can use the LetsEncrypt option but don’t if you choose to go for the reverse proxy
    • prove you can access http://<subdomain>.duckdns.org:8123

Now the question of the reverse proxy, if you run multiple services/domains you will probably benefit from having a single entry point to proxy all web requests through, otherwise all it will seem is that you are hiding the port number from the web address.

  • No proxy
    • done – nothing else to do!
  • Proxy
    • install Nginx Proxy Manager via the Supervisor:
      • Supervisor -> Add-on Store
    • configure with domain/subdomain
    • add LetEncrypt SSL and email address
    • save and wait for the SSL setup to complete
    • prove you can access: https://<domain> or https://<subdomain>.duckdns.org

Now the mobile app can report back to your own server over a HTTPS connection your phones location, battery level and WiFi connection name – all things you can base automations from!

Next: Step 13: Moremation

Step 11: Automation

So, you finally have all the building blocks for automation: a sensor to activate a switch or set of switches.

The original initial goal of this blog was to setup a cloud free home automation system, this got extended with the ability to control the lights a house without ever manually having to switch them on or off.

This is starting to be achievable! If you only have the one sensor then you will only be able to control one room, but the principles will be exactly the same.

There are example automation scripts that can do this, but lets build our own simple one. Please bear in mind that the setup described will only work with one actor i.e. one person within the home.

First you’ll need to start a new automation script via the big plus button within the automation configuration section.

Configuration -> Automations -> +

Give it a suitable name like “lounge lights” or whatever is appropriate, and set the motion sensor as a trigger event and then add a condition on the sensors luminance to ensure it is dark enough to warrant triggering the lights.

Then add all the light switches/devices that you want to turn off – such as all the ones outside of the room where the motion sensor for the trigger is – and then also add the lights switches/devices that you want to turn on as actions at the bottom of the automation screen.

Another option here is to call the scene.turn_on service and have a scene setup with the lights you want turning on. Unfortunately with this setup you do not want to simply create an all lights off scene and add that too as every-time motion is detected all the lights will turn off then the ones you want on will turn back on, so you want to set it as described to stop potential light flickering or make a collection of scenes – one for each room to control.

There are tons more automations capable and there will be a couple more covered in this stride, but first you will need to be able to access your system via the mobile app out and about for some real fun…

Next: Step 12: External

Step 10: Detail

To wrap up everything that helps enable automation you need to know about three more core functions within Home Assistant:

  • zones
  • areas
  • scenes

You have one zone setup from the beginning which is your Home zone, you can add other zones and areas directly through the Configuration panel.

Configurations -> Zones

Entering or leaving a zone can be used to trigger automations in your home. To take full advantage of this you need a device tracker linked to your user – this will be covered in the next stride.

Configuration -> Areas

Areas can be setup to group entities into an area or most likely a room. That way you can affect entities in a particular area. Devices will need to be configured to know what area it exists within.

Configuration -> Scenes

Finally scenes can put a set of entities into a particular pre-configured state, such as having a night mode scene that turns all lights out and disables motion detection in the bedrooms.

Complete: Stride 2: Lights, Camera, …

Step 9: Dash

Let’s start making your Home Assistant setup looking a bit more friendly. By default you will just have one page showing all the active sensors and integrations not in any particular order.

You can choose to manually manage the front end interface – known as the Lovelace UI – and for the most part you can configure this through the interface itself via the three vertical dots in the top right corner.

When you first select ‘Configure UI’ it will warn you that entities would be automatically placed as they are discovered and integrated, but once you manually start to control the UI you will have to add new entities and elements when and where you want them.

You’ll want to take a moment to think about how you want to interact with your home automation system and even how you want to layout your interface. Do you want a panel per floor of the house or per room? Do you want an overview page that summarises the status of the house? Do you want all that and more?

It is recommended to have a bit of a play to work out how you want to laydown the UI elements. Lovelace UI breaks items into ‘tabs’ which can have ‘badges’ and ‘cards’.

You can add as many tabs as you like and tabs can have multiple badges and cards within, you can even place cards inside of other cards such as the horizontal and vertical stack cards. You can also include custom cards that you have installed through HACS.

Conditional cards are really handy to show cards only when certain conditions are true or false. For example, you can setup your Chromecast to only show when powered or playing:

card:
   entity: media_player.cc
   type: media-control
conditions:
  - entity: media_player.cc
    state_not: 'off'
  - entity: media_player.cc
    state_not: unavailable
type: conditional 

The above card will show the control card for the ‘media_player.cc’ entity but only when it is not ‘off’ or ‘unavailable’.

The Android IP Webcam that was previously added to the Home Assistant can be directly viewed through a Picture Entity card and the sensors and switches managed through an entities card:

entities:
  - entity: sensor.cam_1_battery_level
    name: Cam Battery
  - entity: sensor.cam_1_battery_temperature
    name: Cam Temperature
  - entity: switch.cam_1_torch
    name: Cam Torch
  - entity: switch.cam_1_video_recording
    name: Cam Video Recording
type: entities 

The above entities card will show the battery and temperature levels and provide toggle switches for the torch and option to video record.

You can also use Glance cards to have a quick overview of a selection of entities. Remember all these elements can be used within horizontal and vertical stack cards for ultimate layout control.

entities:
  - entity: binary_sensor.motion_sensor_1_sensor
    name: Motion
  - entity: sun.sun
  - entity: sensor.moon
  - entity: sensor.phone_battery
    name: Phone
  - entity: sensor.tablet_battery
    name: Tablet
title: Overview
type: glance

All of the above code views of the Lovelace UI layout cards are just for demonstration purposes as these are all cards available directly through the interface configuration and can be added visually with drop down selections and manually edited if wished.

Don’t forget to add a card for controlling the dimmer switch and cards to view the temperature and/or luminance of the sensor.

Next: Step 10: Detail via Footstep 4: Floor

Step 8: Entities

Let’s have a look at what devices can be controlled and connected to Home Assistant with the Z-Wave integration. First you need a Z-Wave hub/controller, in this case an AEON Labs ZW090 Z-Stick Gen5 EU is connected directly via USB into the Raspberry Pi running the Home Assistant software.

To enable Z-Wave within the Home Assistant you’ll need to go to the Integrations section and configure the device.

Configuration -> Integrations

To complete the configuration you’ll need the:

  • usb_path: most likely /dev/ttyACM0
  • network_key: if you want to make use of Z-Wave Plus and the extra security it can provide. Due to the extra bandwidth and battery requirement this is only recommended for certain devices such as locks.

You can generate the network key following the steps included at Home Assistants own documentation they also have a great getting started section with links to many useful resources.

Now Z-Wave compatible devices can be added, managed and removed via the newly enabled Z-Wave configuration panel.

Configuration -> Z-Wave

With this guides initial goal of automatic lighting focus will be given on motion sensors and switches. in this case the following specifics will be utilised:

  • Fibaro FGMS001-ZW5 Motion Sensor – a motion, temperature and luminance sensor
  • Everspring AD142 Plug-in Dimmer Module – a dimmer based pass-through plug socket

These devices have simple pairing functions and can be added via the Z-Wave Configuration panel, with some devices you need to ensure your are registered to receive the sensors outputs through the ‘group associations’. Home Assistant should do this for you automatically, but your experience could differ depending on the controller and devices.

Next: Step 9: Dash via Footstep 3: Rename

Step 7: Senses

Home automation relies on ‘senses’ to be able to understand the situation and apply your rules to. Home Assistant achieves this through Integrations. Devices have entities which need integrating to Home Assistant in order to take advantage of them.

A quick example: Android IP Webcam (available through the Play Store) can be integrated into Home Assistant through the ‘configuration.yaml’ file. In this case there is an old Android phone with a static IP on the local Wi-Fi network running the IP Webcam software.

android_ip_webcam:
  - host: 192.168.10.100
    port: 8080
    name: 'Cam 1'
    sensors:
      - battery_level
      - battery_temp
    switches:
      - torch
      - video_recording 

Add the above configuration and restart Home Assistant to enable two sensors and two switches. The Home Assistant integration documentation shows all the available sensors.

Generally speaking integration devices are going to either connect directly to the host running Home Assistant or wirelessly. When you work out what kind of home automations you want to achieve you can then work out what solutions are going to be best. In this series the simple idea of automating the light switches to not need to manually ever switch a light on or off is the initial goal.

There is loads of choice when it comes to wireless devices that you can connect for home automation. If you are trying to do this in a complete cloud free way it can be tricky, so many systems come with their own cloud account to allow you to remotely manage. This is unnecessary with Home Assistant as this acts as the ‘cloud’ for your home automation giving you one interface to control everything. So you just need to have the devices connect to Home Assistant and then only allow access to Home Assistant externally via a web browser and/or the mobile app. This external and mobile access will be covered in a mini-stride soon, it can also enable your phone as a location tracker for automation.

For this guide and setup it was decided upon utilising Z-Wave wireless mesh technology over Wi-Fi to completely eliminate the potential for cloud based connected devices, ensuring the system will still operate and be locally controllable without Internet connectivity. This requires a Z-Wave hub or controller to manage the mesh network that the devices form.

Next: Step 8: Entities

Step 6: Components

Home Assistant accepts add-ons and custom components to expand the functionality and provide complete customisation by being able to write a new component if one does not exist already.

Custom components are uploaded to a folder within the ‘config’ directory of the Home Assistant installation and add integrations, custom cards and themes. There is a system available to make this process easier called the Home Assistant Community Store or HACS for short, which allows you to install community made components in a couple of clicks.

Before we get to HACS lets look at the built in Add-On store available via the Supervisor, from here you can install updates, take snapshots of the system and install items that expand Home Assistant itself, such as dns services, reverse proxy, smb and ftp access and many more.

Some add-ons can open ports and access to your system and depending on your specific setup on how in-secure this can make you. Thankfully Home Assistant make this very clear with badges detailing the requirements and security level of the add-on. This even covers items such as the ftp and smb as they allow access to the ‘config’ folder’, but you can simply stop the service, ensure that it is not set to run at startup of Home Assistant and only run it when you need to use it.

HACS itself needs to be added via the manual method and requires a GitHub access token, but has well documented the process on their site hacs.xyz, but the run down is:

  1. download HACS from github
  2. upload the contents of hacs.zip to the custom_configuration folder within your ‘config’ folder
  3. restart Home Assistant
    Configuration -> Server Controls -> Server management -> Restart
  4. add HACS from the Integration panel
    Configuration -> Integrations
  5. enter your GitHub access token
  6. access HACS
    HACS

As mentioned, HACS allows you to add integrations, plugins and themes with just a few clicks and prompts you if a restart of Home Assistant is needed to complete the install of the new component to take advantage of.

Next: Step 7: Senses

Step 5: Sun & Moon

Now it is time for some simple automation. Lets say something like changing the theme based on whether the sun is above or below the horizon.

Home Assistant makes use of Devices and Entities. For example, a device might be a Multi Sensor, so it will have multiple entities, one for each sensor. Most motion sensors include a temperature and luminescence or humidity etc.

This automation will trigger whenever Home Assistant starts (or restarts) and on the state of the Sun (a built-in sensor).

 - alias: change theme
   trigger:
   - event: start
     platform: homeassistant
   - entity_id: sun.sun
     platform: state
     to: above_horizon
   - entity_id: sun.sun
     platform: state
     to: below_horizon
   action:
   - data_template:
       name: >
         {% if states.sun.sun.state == "above_horizon" %}
           oxfordblue
         {% else %}
           darkorange
         {% endif %}
     service_template: frontend.set_theme 

Let’s step through the elements of the automation script:

  1. alias – provide the automation a friendly name
  2. trigger – set what causes the automation to activate, in this case there are three:
    1. when your Home Assistant starts or restarts
    2. when the Sun is above the horizon
    3. when the Sun is below the horizon
  3. action – what to do when the automation is triggered, in this case an if statement checking the state of the sun to select the appropriate theme name

Unfortunately, this automation uses an action statement that is currently not understood by the Configuration Automation editor. Therefore, you need to use the Configurator to edit the ‘automation.yaml’ file directly.

To enable the Moon integration (Sun comes as default), you can simply add the following YAML to your ‘configuration.yaml’ file via the Configurator:

sensor:
  - platform: moon

This sensor will return one of the following values:

  • new_moon
  • waxing_crescent
  • first_quarter
  • waxing_gibbous
  • full_moon
  • waning_gibbous
  • last_quarter
  • waning_crescent

This means you could edit the original script to change the theme based on the current phase of the moon or of course any automation.

Complete: Stride 1: Getting Running

Step 4: Looks

Home Assistant doesn’t come out of the box with any themes, which is a shame – but there are loads available from the community.

In this part of the guide we are going to use the manual process of editing the frontend.yaml file to add a selection of themes, but later will show you how to enable HACS the Home Assistant Community Store. Although it is called a store there is no charge for adding any of the integrations, plugins or themes.

Home Assistant has a built in File editor (aka Configurator) which allows you to manually change any of the YAML files affecting the operation of Home Assistant. Most of these sections are configurable through the core Configuration panel, but some are still being migrated.

Accessing the File Editor is easy:

Supervisor -> File editor -> Open Web UI

You can also enable the ‘Show in Sidebar’ option which will give you a direct link to the Web UI of the Configurator. Especially useful at the beginning as you’ll often flick back and forth between that and the Server Controls in Configuration to restart the system and enable the changes. This is why using the built-in Configuration panel is preferred as it allows for many automatic changes without restarting.

Unfortunately, frontend theme configuration is still done directly through the YAML files (or HACS), but will use this opportunity to demonstrate how to use the File editor.

Configurator Home Page

The above screen shot of the File editor shows the core sections:

  1. File selector
  2. File name being edited
  3. File contents
  4. Save and close file
  5. New file

For this setup we are going to add some themes, so by using the file selector (1) you can choose ‘configuration.yaml’ which is the main configuration file.

We are going to add an include statement that allows us to offload the frontend configuration into another file so that the main file doesn’t get difficult to read.

frontend: !include frontend.yaml

Adding this to the ‘configuration.yaml’ file tells Home Assistant to look for and use a file called ‘frontend.yaml’

Therefore, after saving (4) and then using the new file (5) option you can create a ‘frontend.yaml’ file and add the themes into it (3).

Obviously you can write your own theme and there is some detail about how in Home Assistant documentation, but another option is to use someone elses frontend.yaml.

Due to manually editing the ‘frontend.yaml’ you’ll need to restart Home Assistant for it to re-read the configuration files.

Configuration -> Server Controls -> Server management -> Restart

Then select via the user profile what theme you want to use or get Home Assistant to set it for you depending on a sensor value, such as the Sun…

Next: Step 5: Sun & Moon via Footstep 2: Config

Step 3: Using

This isn’t so much of a step as it is an overview of the core interface that will be used for the rest of this guide.

Home Assistant has several sections or ‘panels’ visible to you depending on the type of account you are logged in with.

The first account that was created in Step 2 was an Administrator account which means you have access to everything. This is good and bad!

Great that you can tweak and play around with it all, but bad because you can break things. Thankfully, if you chose the same option of Home Assistant, a deletion of the database and restart usually gets you back up and running.

The initial panels available to you are:

  • Overview – the main front end user interface for operating and monitoring your home automation
  • Map – a view of device trackers and locations
  • Logbook – a diary of events and state changes
  • History – a series of bar and chart graphs
  • Developer Tools – behind the scenes tweaking
  • Supervisor – installation and host manager
  • Configuration – where you setup all the smart devices and entities along with scenes and automations
  • Notifications – user messages
  • User Profile – user account details and options

The Supervisor allows you to extend the functionality of Home Assistant with Add-Ons such as the Configurator to edit the YAML files directly.

Next: Step 4: Looks via Footstep 1: YAML