Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (2024)

Welcome to part 3 of the Getting Started with Home Assistant series – Configuration and adding entities.

This series aims to help teach you about the basic configuration and functionality of Home Assistant.

This part follows on directly from where we left off in part 2, so if you have not yet installed and configured Home Assistant then go back and follow that part.

In this part, we are going to learn about the configuration files in Home Assistant, as well as how to add entities to our setup.

Let’s get into it!

Prerequisites

This part of the series assumes you:

  • Installed Home Assistant/Hass.io
  • Have command line/SSH access to your server
  • Are comfortable with editing files using vi/nano
  • (Optional) A compatible device that you want to add to Home Assistant

Terminology Cheat Sheet

Let’s take a look at some terminology that is useful to know for this section of the guide.

Config Directory

This is the location where the main configuration files are stored for Home Assistant. The location is dependant on which method you used for installation, if you used Hass.io then it is simple “/config/” and if you followed our installation guide for virtual environment, then it will be in “/home/homeassistant/.homeassistant/”. If you are unsure, open Lovelace and go to Developer Tools then Info and look where it says “Path to configuration.yaml” which will give you the path.

YAML Files

YAML stands for “YAML ain’t Markup Language” and is the “language” of choice for all the configuration files within Home Assistant. There isn’t too much you need to know here, apart from indentation and spacing is key for YAML, so just make sure to double check all spacing and indentation has been adhered too. Do not use tabs, use spaces when indenting.

Text Editor

Since we using command line/SSH we will be using a command line based text editor. You can use whichever you feel most comfortable with if you are more advanced, and while my personal preference is vi/vim, I’m going to use nano for the purposes of this guide because I feel its easiest for beginners to use. If you are a beginner, it’s the one I’d suggest you go with.

Configuration Files

First of all, let’s locate our configuration files so that we can see what we are working with and familiarise ourselves with the config directory.

Go ahead and change directory then list all the files in your config directory:

cd /your-config-directory/ls -lah#Hassiocd /config/ls -lah#Virtual Environmentcd /home/homeassistant/.homeassistant/ls -lah

From here on I will just refer to it as the config directory.

You should have something like this:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (1)

You will notice you have several .yaml files:

  • configuration.yaml – this is the main config file for Home Assistant (I will refer to it as config file from now on) and is where you add all your entities and platforms as well as several other things. It also refers to the other yaml files by “including” them within this one.
  • automation.yaml – where you would enter any automations you want to create, this is where lovelace also writes any that you created in Lovelace
  • customize.yaml – again there is where any entity customizations would be entered and also where Lovelace saves anything you entered in the Customization section.
  • groups.yaml – groups is something we haven’t yet come across. Groups allows you to group multiple entities together to act as a single entity. For example, if you have 4 light entities called “light.livingroom_X” (X being 1 to 4) then you could group them together into a single entity called “light.livingroom”. This is much nicer to control.
  • scripts.yaml – As above, where you enter any scripts you want to have and where lovelace writes any scripts you create in the UI.
  • secrets.yaml – This is a location that allows you to enter any passwords or other “secrets” here so that all sensitive information is kept in a single file and out of the main config file. It means you can share your configuration file with others without worrying about having to go through and redact your main configuration. Note this is a plain text file and can obviously be read by anyone so do not treat this as a “secure” file.

We are only going to be looking at the main config file in this part, but everything you will learn here you can put into practice with all the other files, since they all use YAML.

Lets take a look at the main config file:

nano configuration.yaml
Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (2)

Even though it’s pretty empty at the moment, let’s break it down.

At the top we have:

default_config:

This line tells Home Assistant to load a default set of integrations/components which can be found here. Basically its the recommended setup from Home Assistant so I would leave this in unless you have a specific reason to disable it.

Then we have:

tts: - platform: google_translate

This section enables the text-to-speech (tts) integration/component, then enables the Google Translate platform. This does not require any other options so we do not need to put anything else here.

Finally we have the last section which is:

group: !include groups.yamlautomation: !include automations.yamlscript: !include scripts.yaml

Remember earlier I mentioned the other yaml files and how they are included via the main configuration? That’s what this section does, it reads those other files and includes the contents directly here. You could add the content from those files directly here, but that could make this file rather large and unwieldy so this is a nice way to organise everything.

Adding entities

At this point, you might be asking “That’s all well and good, but how do I actually know what to write in this file!?” – that’s a fair question and one I will try to answer now.

Now we’ve looked at the structure of the config file, let’s try and answer the two main questions:

  1. How do I know what to write in this config file?
  2. How do I actually add my entities to the config file?

First things first, we need to find out if our device/entity is compatible. Head over to the integrations page here. You can see that at the time of writing this there are 1485 integrations currently which is amazing. You will see everything is organised into categories on the left hand side:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (3)

Use the categories or the search to find your entity or device.

This section of the guide becomes difficult because everyone has access to different devices so its hard to cover all basis. However having said that, let’s take a look at an integration that pretty much everyone should be able to do – a simple internet speed test.

Go to the “system monitor section” and click on the entry for speedtest.net, or simply search for speedtest.net (click either entry):

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (4)

This page gives us all the information we need to add a speedtest.net sensor to our config file.

So lets add our first sensor!

Open your config file and add the speedtest.net integration by specifying a new integration:

speedtestdotnet:

This tells Home Assistant that we want to load the speedtest.net integration.

Directly underneath that and indented with two spaces, we add the options for that integration. Specifically we are going to add which conditions we want to monitor:

speedtestdotnet: monitored_conditions: - ping - upload - download

Notice how after each colon we specify, we indent to start a new sub-section:

speedtestdotnet: //No indentation because its a new parent section monitored_conditions: // 2 space indentation because monitor_conditions "belongs" to the speedtestdotnet - ping // Another 2 space indentation (4 total) because these 3 options belong to "monitored_conditions" - upload - download

Hopefully that makes sense.

Let’s add some more options, we want to schedule a speedtest every 5 minutes (I wouldn’t actually recommend this for production), from the integration page we can see that there is an option for “scan_interval” which allows us to specify at what time the test should run. Add the scan_interval option so that your config looks like:

speedtestdotnet: monitored_conditions: - ping - upload - download scan_interval: minutes: 5

Notice how scan_interval has a 2 space indentation to indicate it “belongs” to “speedtestdotnet” and not “monitored_conditions”?

The full configuration will look similar to this:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (5)

Notice how nano (or vi) has different colours? Because the text editor is yaml aware and automatically changes colour depending on the section.

Save the file (press ctrl + x and hit enter if using nano) and then go into Lovelace. Go to Configuration then server control. Press check config which should say “Configuration is valid” then press restart under server management. Once Home Assistant restarts, go to Developer Tools then states.

You should see you now have 3 new sensors:

  • sensor.speedtest_ping
  • sensor.speedtest_upload
  • sensor.speedtest_download
Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (6)

The state is currently unknown, we will need to wait up to 5 minutes for the test to run. At which point the states will change to:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (7)

Well done, we’ve just added our first sensor to Home Assistant!

Let’s take a look at another practical example and add a device tracker using a simple ICMP ping. Once again using the integrations page, find the ping component.

This time we can see that the ping component can be used as a binary sensor or as presence detection. Binary Sensors are extremely simple and only have 2 states, “on” or “off” (hence the binary part). This is incredibly useful for many reasons, but we are actually going to use the presence detection platform because we want to associate a device with a person.

Go ahead and add the following to your config file:

device_tracker: - platform: ping hosts: your_phone: 192.168.1.100

Note the indentation as we discussed above.

Your full config should now look like this:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (8)

Save the config and restart home assistant like we did before.

Once again go back to Developer Tools then states. You will see that I now have entry for “device_tracker.lewis_phone” with a state of “home”:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (9)

If I disable the Wifi to simulate my device leaving the house the state changes to “not_home” after a few minutes:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (10)

What about if we want to add multiple devices? Easy!

Back in the config file, simply define another device using this:

device_tracker: - platform: ping hosts: your_phone: 192.168.1.100 tests_phone: 192.168.1.101

Full config:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (11)

Again save and restart Home Assistant. Checking states we now see our second entity show up:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (12)

Remember in part 2 we briefly looked at “persons” and we added a second person using Lovelace? We can now associate these devices with those users.

Again in Developer Tools then states you should have 2 people entities with the following states of unknown:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (13)

The state is unknown because Home Assistant had no way of tracking these people…until now!

Go to Configuration then persons. Click on the first person and now we can click the drop down to add a device:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (14)

Do the same for both users.

Go back to States and now our person state matches the device_tracker state:

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (15)

And now we have a simple device tracker for our setup which will greatly assist our automations!

Final Words

Hopefully now you understand the following:

  • Where the Home Assistant configuration files are located
  • How the config files work
  • How to add entities/integrations to Home Assistant

In the next part of the series, we are going to take a look at how to create some more advanced automations using templates so look out for that one when it drops!

Getting Started with Home Assistant - Part 3 - Configuration/Adding entities (2024)

FAQs

How do I clean up entities in Home Assistant? ›

For cleaning an entity up from the database, the service purge_entities is the solution. I called it from the UI and the states were gone from the DB. The entity remained visible in the UI, e.g. in /developer-tools/state, but only until I restarted Home assistant. Afterwards it was completely gone.

What is the difference between devices and entities in Home Assistant? ›

Devices are a logical grouping for one or more entities. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service.

How can I check my Home Assistant configuration? ›

You can verify that your changes are acceptable by running a configuration check. Do this by navigating to Developer Tools > YAML and then clicking on the Check configuration button. When it's valid, it will show the text “Configuration valid!”.

Where are Home Assistant configuration files? ›

Homeassistant creates a configuration file by default under the path of the executing user (created homeassistant) at the ~/. homeassistant path. . storage directory contains a lot of user-related information, including user login information (username/password, encrypted in auth_provider.

What is entity ID Home Assistant? ›

The entity registry is a registry where Home Assistant keeps track of entities. Any entity that is added to Home Assistant which specifies the unique_id attribute will be registered in the registry. Being registered has the advantage that the same entity will always get the same entity ID.

How do I add things to my Home Assistant? ›

From the sidebar, select Settings > Devices & Services. At this screen you will be able to set up integrations with Home Assistant. You might notice a Discovered section. This section contains integrations that were found on your network and can easily be added with a few clicks.

How do I create a Boolean entity in Home Assistant? ›

Configuration. The preferred way to configure input boolean helpers is via the user interface, in which they are known as Toggle Helpers. To add one, go to Settings > Devices & Services > Helpers and click the add button; next choose the Toggle option.

How do I remove stale entities from home assistant? ›

If they are, look at the icon in the entity's rightmost column. If it's a red dot with an exclamation mark, click it and the resulting popup should offer a Delete button. They are listed in Settings>Devices>Entities, but the icon is of a lined-through pencil, indicating read-only.

How do I delete obsolete entities in home assistant? ›

Restart home assistant. Then go to Configuration / Entities and find and delete the orphaned entities.

How do you clear entities? ›

To clear entities in Minecraft, you can use the /kill command. Here's how you can do it: Open the chat box in Minecraft. Type the following command: /kill @e This command will eliminate all entities in your world, except for the player character.

What does HACS stand for Home Assistant? ›

Home Assistant Community Store. HACS gives you a powerful UI to handle downloads of all your custom needs. DOWNLOADCONFIGUREPUBLISH.

Can I control Home Assistant remotely? ›

To enable remote control

In Home Assistant, go to Settings > Home Assistant Cloud. Make sure you are logged in to Home Assistant Cloud. If you only just logged in for the first time, you might see a message “Remote control is being prepared. We will notify you when it's ready.".

What is Home Assistant coded in? ›

Home Assistant Core is a Python program, in simple words. It can be run on various operating systems and provide the ability to track, control and automate your devices.

How to configure HACS integrations? ›

Configuration options
  1. First go to the "Settings" in the Home Assistant UI, then "Devices & Services" and the "Integrations" tab in the Home Assistant UI.
  2. Then click on the entry for HACS.
  3. On the card click on "Configure"

How do I add a MQTT entity to Home Assistant? ›

MQTT
  1. Browse to your Home Assistant instance.
  2. Go to Settings > Devices & Services.
  3. In the bottom right corner, select the Add Integration button.
  4. From the list, select MQTT.
  5. Follow the instructions on screen to complete the setup.

How do I rename entities for device in Home Assistant? ›

Go to Devices, pick a device. Click the pencil icon next to the device. Enter a new name, click Update. It will ask you if you want to rename all of the entity IDs, click “Rename” to do so.

How do I disable unused entities in Home Assistant? ›

All unused entities can be deleted. If they are orphaned, an delete button appears on each entity. Also, when looking at the table/list of entities you can filter on those and multi select them, deleting them at bulk.

Top Articles
Latest Posts
Article information

Author: Aron Pacocha

Last Updated:

Views: 5884

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Aron Pacocha

Birthday: 1999-08-12

Address: 3808 Moen Corner, Gorczanyport, FL 67364-2074

Phone: +393457723392

Job: Retail Consultant

Hobby: Jewelry making, Cooking, Gaming, Reading, Juggling, Cabaret, Origami

Introduction: My name is Aron Pacocha, I am a happy, tasty, innocent, proud, talented, courageous, magnificent person who loves writing and wants to share my knowledge and understanding with you.