Skip to main content

Home automation: Running Home Assistant with Podman

An introduction to the Home Assistant open source project, what it can do, and a basic setup using a container.
Image
Automating your home with Home Assistant
Image by wiredsmartio from Pixabay

Smart devices surround us and the long list of devices that come ready to connect to the Internet of Things (IoT) is growing longer every day. For example, the popularity of smart light bulbs has risen rapidly over the past few years, and the market is continuing to grow, so much so that it is predicted to be "the fastest-growing smart home device over the next five years." While a few big names in the field dominate the market, there are many smaller competitors joining the fray and offering up cheaper alternatives with even more features. This is great for competition, but it raises one serious concern and a situation that many sysadmins are all too familiar with—an integration nightmare.

[ You might also like: Help with COVID-19 research using Folding@home on Linux ]

The problem is that each manufacturer tends to provide its own in-built and closed source solution to controlling their devices—usually in the form of a mobile app. But what happens when you decide to buy a new device from a different manufacturer than the one you have already integrated into your home automation? Chances are you'll end up having to use multiple apps to control the devices, and let’s not begin talking about how to get them working together in some kind of automated fashion. There are cloud services available to help work around this issue, providing a means for creating applications and automation for controlling devices from various manufacturers. Such services offer a great platform for kickstarting your journey into smart device automation, but these services tend to operate with a paid subscription or on very limited "freemium" models, and you'll find yourself becoming ever more reliant on this cloud-based service.

In 2013 an open source project was started to address these kinds of problems and bring local control of smart devices from the cloud and back into the home. Today the project is going strong, with over 2,500 contributors and new integrations and features rolling out frequently. In this article, I will introduce you to the open source home automation platform called Home Assistant.

Deploying the Home Assistant container

Home Assistant can be deployed using various installation methods, of which the recommended way is to deploy Home Assistant OS, which comes with everything you need. However, we will use the container image for this taster, which will provide us with a quick insight into how Home Assistant works. The following steps assume you already have a container runtime deployed on your system, such as Podman. Home Assistant operates on TCP port 8123, so you need to ensure this port is not already in use on your system.

1. Begin by pulling the container image:

$ podman pull docker.io/homeassistant/home-assistant:stable

2. Setup a configuration directory:

$ mkdir ~/hass_config

3. Deploy the container using Podman:

$ podman run --init -d \
--name homeassistant \
--restart=unless-stopped \
-v /etc/localtime:/etc/localtime:ro \
-v ~/hass_config:/config:Z \
--network=host \
homeassistant/home-assistant:stable

4. Once the container is up and running, open your preferred web browser and head over to http://127.0.0.1:8123/. Create your admin user account by filling in the required fields.

5. If you already have some smart devices connected to your home network, you may find on the next screen that Home Assistant has already discovered them and presents them as integrations to install straight away. We will skip this step and run through how to set up integrations in the next section. Hit Finish to proceed to Home Assistant’s Lovelace GUI and explore around a little to familiarize yourself with the lay of the land.

Note: If you notice some menu items are missing or an error message like the following in your Home Assistant log:

Unable to set up dependencies of default_config. Setup failed for dependencies: automation.

Simply reboot Home Assistant via Configuration -> Server Controls -> Restart.

Integrations and Automation

With your Home Assistant container deployed, let’s get stuck into the configuration. Integrations in Home Assistant give us the ability to interface with external inputs, be they an online API such as a public transport timetable or a physical smart device such as an LED light strip or a smart humidifier. At the time of writing, Home Assistant serves up a collection of 1,765 integrations, and that library is growing rapidly. You will find that many major brands are already supported, and if your home already contains some kind of smart lightbulb, TV, or coffee machine, then there is a strong chance that Home Assistant already has integration for it. If not, and you want to get your hands dirty, the project is open source, hosted on GitHub, and is always looking for contributions!

For this example, I will set up the Met.no integration for retrieving weather forecasts in the Nordics. Feel free to use another weather service provider if you wish.

  1. In the Home Assistant GUI, navigate your way to Configuration -> Integrations -> Add Integration. Search for “Meteorologisk institutt (Met.no)” and input the desired name, latitude, and longitude information. These may already be filled out for you by Home Assistant, but if not, then you can retrieve these elsewhere on the Internet and input them yourself.
  2. Hit Submit and then Finish to add the integration to your Home Assistant configuration. Using the navigation pane on the left, click on Overview to go to your Lovelace GUI.
  3. By default, Home Assistant is configured to populate the Lovelace GUI for you automatically, but at some point, you will want to take control and set it up just how you want it. Click the kebab menu icon (three vertical dots) up the top right and select Edit Dashboard -> Take Control.
  4. Click the Add Card button, and for the card type, select Weather Forecast. You will then be presented with the configuration options for this card. In most cases, Home Assistant will have automatically selected the correct entity for you, but you can use the drop-down menu to change the entity if needed. In my case, I gave my Met.no integration the name “Home,” and so the entity is named "weather.home" automatically. I have also set the Secondary Attribute to "Wind speed."
  5. After hitting Save, the card is added to the Lovelace GUI. You can remove cards by clicking the kebab menu icon at the bottom right of the respective card and selecting Delete card. When you are done editing the dashboard, hit the X up the top left to return to view mode.
Image
Forecast card configuration screen
The Forecast Card configuration.

Now that we have added an integration, we can look at setting up an automation. We will create an automation that sends a short weather report to your phone via push notification each morning. For this to work, you will need to install the Home Assistant app onto your mobile device and log in. Once logged in, your phone will begin reporting back to your Home Assistant server. By looking under Configuration -> Entities, you will find a list of the various sensors that your phone is reporting back to Home Assistant. Communication over TCP port 8123 must be allowed between your phone and your Home Assistant container on the local network, so you may need to adjust your firewall rules accordingly.

1. Head over to Configuration -> Automations -> Add Automation -> Start with an empty automation.

2. Name the automation "Morning weather report."

3. Under Triggers, select Sun for the type and ensure Event is set to Sunrise. You can add an offset such as "01:00:00" for one hour after sunrise or "-01:00:00" for one hour before sunrise. You could also just set a fixed time by using the Time type.

4. Under Actions, set the type to Call service and set the Service to "notify.mobile_app_your_phone_model". For Service data, we need to write our configuration in YAML format, and we will use Jinja2 templating to run some conditional statements. You can find more information on templating in Home Assistant.

title: Weather Report
message: >-
  The current temperature is {{state_attr("weather.home", "temperature") }} degrees
  with an expected maximum of {{ state_attr("weather.home","forecast")[0]["temperature"] }} degrees.
  {%if state_attr("weather.home", "forecast")[0]["precipitation"] | float == 0 %}
    There is no rain forecast today
  {% else %}
    You can expect {{ state_attr("weather.home","forecast")[0]["precipitation"] }}mm of rain today
  {% endif %}
  {% if state_attr("weather.home","wind_speed") | float > 20%}
    and it's a little windy outside, so hold on to your hat!
  {% else %}
    and it's not too windy.
  {% endif %}

5. Hit the blue Save button to save the automation. On the Automations page, you can test your shiny, new automation by clicking Execute. You should now have a push notification on your phone with a short weather report from Home Assistant that looks something like this:

Image
Sample weather report
A sample weather report.

[ Need more on Ansible? Take a free technical overview course from Red Hat. Ansible Essentials: Simplicity in Automation Technical Overview. ] 

Wrap up

This is a basic installation, configuration, and deployment of Home Assistant. I set up a new integration on the Lovelace dashboard and gave you a sneak peek at automations. Although I barely scratched the surface of Home Assistant’s abundance of integrations, automations, and configurability, it should at least give you a taste of what's possible. By making full use of Home Assistant’s offerings, you'll discover an almost infinite number of possibilities; you're only really limited by your imagination. If you enjoyed this short introduction, I recommend continuing to play around with the container image to get a feel for what Home Assistant can do for you. If you want to set up a production environment, then check out Home Assistant OS.

Check out these related articles on Enable Sysadmin

Topics:   Linux   Automation  
Author’s photo

Thomas Tuffin

Thomas is a Technical Account Manager for Red Hat. An Aussie expat in Sweden, he is passionate about Open Source software and has a keen interest in emerging technologies such as blockchain. More about me

On Demand: Red Hat Summit 2021 Virtual Experience

Relive our April event with demos, keynotes, and technical sessions from
experts, and sign up to attend breakout sessions June 15–16.

Related Content

OUR BEST CONTENT, DELIVERED TO YOUR INBOX