Development 101
The goal of development 101 is to get you familiar with the basics of developing for Home Assistant. Before we start, please make sure you familiarize yourself with the architecture.
To get our code running inside Home Assistant we’re going to create a custom component. The first step is to locate your config folder. You can find the path to your config folder by opening the Home Assistant frontend, click on the . It’s the path after the text “Path to configuration.yaml”.
Inside your configuration directory create a new folder called custom_components
. It might be that one already exists, that’s fine too. This is the folder that Home Assistant will look at when looking for custom code.
The Home Assistant API has two variants: a synchronous and an asynchronous version (asyncio). This development course will focus on the synchronous version.
To verify that everything is working correctly, let’s create a small Hello World component. To do so, create a file called hello_world.py
in your custom components folder. Copy paste the following content to it:
# The domain of your component. Equal to the filename of your component.
DOMAIN = "hello_world"
def setup(hass, config):
"""Setup the hello_world component."""
# States are in the format DOMAIN.OBJECT_ID.
hass.states.set('hello_world.Hello_World', 'Works!')
# Return boolean to indicate that initialization was successfully.
return True