How to set up Home Assistant with a Raspberry Pi and build a smart home

How to set up Home Assistant with a Raspberry Pi and build a smart home

Do you own smart home devices, but still feel like your home is dumb? Being able to turn your lights on and off from your phone is fun for a while, but that’s home control, not home automation.




Home automation isn’t about being able to use your phone to turn out the lights. It’s about your lights turning on and off by themselves, without the need for you to interact with them at all. They know when it’s getting dark, they know when you’re in bed, they even know if anyone is at home.

If this sounds like a home of the future, it isn’t. You can have all of that and more by running the right software and creating the right automations. And the best part is that it doesn’t need to cost you an arm and a leg; you can run it all from a cheap single board computer such as a Raspberry Pi.

If you want your home to become truly smart, then read on to learn how to set up Home Assistant on a Raspberry Pi, and how to create your first home automation.



What is Home Assistant?

Home Assistant is home automation software that allows you to integrate and control smart home devices that wouldn’t normally work together. Instead of being tied down to restrictive ecosystems or requiring a small army of different smart hubs to control all your smart home devices, you can integrate a huge number of different devices into Home Assistant and control and automate them all from one place.

The Home Assistant software is free, and the equipment you can use to run Home Assistant doesn’t need to cost a huge amount either. One of the most cost-effective options is to run it on a Raspberry Pi. We have a comprehensive guide to everything you need right here.

Installing Home Assistant on a Raspberry Pi

The first thing you’ll need to do is write the Home Assistant OS (HAOS) image to your microSD card. You can then run Home Assistant on your Raspberry Pi directly from that microSD card. The simplest way to write the image is to use the free Raspberry Pi Imager software which is available for Windows, macOS, and Linux.

  1. Download and install Raspberry Pi Imager for macOS, Windows, or Ubuntu. If you’re running a different Linux distribution, you may be able to find a relevant software package available.
  2. Launch Raspberry Pi Imager.
  3. Plug your microSD card into a card reader and insert it into your computer or use the dedicated microSD port on your computer if you have one.
  4. Click Choose OS.
  5. Select Other specific-purpose OS > Home assistants and home automation > Home Assistant.
  6. If you’re installing on a Raspberry Pi 4, select Home Assistant OS (RPi 4/400).
  7. If you’re installing on a Raspberry Pi 3 B or a Raspberry Pi 3 B+, select Home Assistant OS (RPi 3).
  8. Click Choose Storage.
  9. Select your microSD card.
  10. Click Write and the Home Assistant OS will be written to the card.
  11. Eject the SD card and insert it into your Raspberry Pi. The microSD slot is at the opposite end to the USB and Ethernet ports.

You’re now ready to start up Home Assistant.

Starting Home Assistant for the first time

Once your SD is written and installed in your Raspberry Pi, you’re ready to start Home Assistant. The initial configuration can take some time; when everything is set up, booting Home Assistant usually takes a minute or so.

  1. Plug your Ethernet cable into the Ethernet port of your Raspberry Pi.
  2. Plug the other end of the cable into an Ethernet port of your router.
  3. Connect the power supply and power the Raspberry Pi on.
  4. You’ll need to wait for the initial stages of set up to complete. After a few minutes, visit http://homeassistant.local:8123/ on any device that is connected to the same network as your Raspberry Pi.
  5. You should see a splash screen that reads Preparing Home Assistant.
  6. You’re likely to be stuck on this page for some time. It’s supposed to take around 20 minutes for Home Assistant to initialise, but it can take longer.

Home Assistant initial configuration splash screen

If you’re concerned that nothing is happening, click the blue dot just below Preparing Home Assistant. This will allow you to see the currently running processes and confirm that the set-up is in progress.

Eventually, you should see the screen where you can set up your Home Assistant account.

Setting up your account

You’ll need to set up your account with your name, as well as a username and password for your account. Using a strong password is highly advised. It also makes sense to use at least your real first name as this will be the default name used for presence detection.

Home Assistant account creation screen with fields for name, username, password, and password confirmation

On the next screen, you can give your installation a name, set your location and time zone, and your preferences for units of measurement. An accurate location is important, especially for automations that use local times or events, such as sunrise and sunset.

Finally, you can decide whether to share anonymised analytics data with Home Assistant. By default, you’re opted out of all sharing.

Now that the admin is out of the way, you’re ready to start adding devices to Home Assistant.

Adding smart devices to Home Assistant

After you’ve finished setting up your account, you’ll see a screen listing all the devices that Home Assistant has discovered on your home network.

Home Assistant devices discovered during installation, including printers, smart TVs, and light bulbs

  1. Click any of the integrations to set them up before you plunge into the main Home Assistant web interface.
  2. If you prefer, you can just click Finish to complete your set-up and add your integrations later.
  3. If you don’t add any integrations during the set-up process, you can find them by clicking Settings > Devices & Services.
  4. Under the Integrations tab, the integrations for any devices that have been discovered on your network will appear, with a Configure button on each.
  5. Click Configure and follow the instructions to set up that integration.
  6. For the Hue integration for example, all of your Hue lights should now be discovered. You can give each one a specific name, and set which area of your home its located in. This is useful for controlling multiple lights at once by telling Home Assistant to turn off the bedroom lights, for example.
  7. When you’ve done so, the devices will be added to the Overview page.

By default, the Overview dashboard shows most of the entities that are created when you enable an integration; you can choose to take control of your dashboard and edit what entities appear and how they are laid out.

Home Assistant Overview dashboard showing thermostats, robot vacuums, air quality, and energy distribution

You can create multiple dashboards for different uses. If your home has a lot of smart lighting, for example, you might create a dashboard purely to display and control the state of your lights.

In the Integrations tab of Devices & Services page, you can also click Add Integration to search for additional integrations. Some of these allow you to connect other smart home kit, but others allow you to connect to services such as Plex or Coinbase, or can provide useful information for home automation, such as local weather.

Home Assistant Integrations page showing discovered integrations such as Philips Hue and Sonos

You can also download and install the Home Assistant mobile app. This allows you to access Home Assistant from your phone, but also means that your phone now becomes a device tracker. With the relevant location permissions, you can now use your phone to help Home Assistant determine whether you’re home or not.

Once you’ve configured some integrations and have some smart home devices connected to Home Assistant, you’re ready to step into the world that is the heart of Home Assistant and build your first automation.

Creating your first Home Assistant automation

Home Assistant was first created because its founder, Paulus Schoutsen, wanted to set up an automation for his newly purchased Philips Hue lights. He wanted to be able to make the lights turn on automatically when the sun set.

Since this is the automation that ultimately led to the Home Assistant software used by hundreds of thousands of people around the world, it’s a perfect way to show how to create an automation in Home Assistant. This specific automation requires you to have Philips Hue bulbs and for you to have configured the Hue integration which pairs your Philips Hue Bridge with Home Assistant. If you don’t have any Hue lights, however, you can make the Action of the automation anything you wish, such as sending a notification or turning on a smart plug.

  1. Click Settings > Automations & Scenes.
  2. In the bottom right-hand corner, click Create Automation.
  3. Select Create New Automation.
  4. Click the Add Trigger button.
  5. From the Trigger options, select Sun.
  6. Under Event select Sunset.
  7. The Trigger should now read When the sun sets.
  8. Click Add Action.
  9. Select Call Service. This is the action that allows you to send a command to one of your connected integrations.
  10. Under Service start typing the word light. When it appears, select Light: Turn on from the options.
  11. Under Targets select Choose entity.
  12. Select the light that you want to turn on.
  13. You can repeat these steps to add as many different lights as you wish.
  14. Alternatively, to turn on all the lights in a specific room, select Choose area. You will need to have allocated lights to specific areas of your home when you set up the Hue integration.
  15. Ensure the bulbs you want to control have power; you’ll need to turn them off in Home Assistant or the Hue app rather than by the light switch.
  16. Wait for sunset, and the lights you selected should magically turn on.
  17. You can make this automation more powerful by adding conditions; click the Add Condition button to do so.
  18. Select Zone as the condition.
  19. Under Entity with location select a device tracker, such as the phone on which you installed the Home Assistant app.
  20. Under Zone, select Home.
  21. Now if you’re away from the Home zone at sunset, the lights won’t come on.

You can add more and more complexity to your automations with multiple triggers, conditions, and actions. Whilst it’s possible to build a huge number of automations directly within the UI, for the more complex automations you may need to create or edit the automation in YAML which is the syntax used to configure Home Assistant. You can also install the Node Red add-on, which allows you to build complex automations using a visual flow-based editor.

Now you’ve got your first automation up and running, the limit is really just your own imagination. If you need inspiration, check out the Home Assistant forums to see the types of automations that other Home Assistant users are creating. All you need is the right smart home gear and can build the automations you want and start to make your home truly smart.