Skip to content

HomeIntent object

An instantiated HomeIntent object gets passed in to the setup function when setting up components.

Example:

class TimerSettings(BaseModel):
    max_time_days: int = 1

def setup(home_intent: HomeIntent):
    config = home_intent.get_config(TimerSettings)
    home_intent.register(Timer(config), intents)

home_intent.get_config(pydantic.BaseModel)

Home Intent uses pydantic models for handling configuration. The get_config method will parse the config from config.yaml given the pydantic BaseModel object and return it for use.

home_intent.register(Class(), Intents)

The register method expects an instantiated intent class object and an Intents object. This method registers the class and verifies all the slots and sentences are setup correctly. Later in the Home Intent initialization process, the registered intents are used to configure Rhasspy and setup the Intent Handler.

home_intent.get_file(filename, language_dependent=True)

Home Intent uses a custom file loading function that will first check if a file exists in /config otherwise it'll load the file from the default_configs/{lang} folder in the source code.

By default it will load a file from the corresponding language folder, but you can set language_dependent to False, and it will instead just load from default_configs. NOTE: currently overrides in /config are not language dependent.

This method allows users to easily replace parts of components like lists of colors or sounds. This can also be useful when creating custom components, as users can add component code to /config/custom_components and any associated files to /config.

from home_intent import get_file

#### OTHER COMPONENT CODE #####

@intents.dictionary_slots
def color(self):
    color_file = self.home_intent.get_file("home_assistant/colors.txt")
    colors = color_file.read_text().strip().split("\n")
    return {color: color.replace(" ", "") for color in colors}

In the example above, Home Intent will check for the file in /config/home_assistant/colors.txt, then load from the default config location in the source code: default_configs/{lang}/home_assistant/colors.txt.

Conventions

When loading a file related to a component, it's best to put it in a folder that references the component's name. In the example above, files will be loaded from the home_assistant folder in /config or Home Intent's default_configs folder.

home_intent.say(str, satellite_id)

Have Home Intent say something to the user. This method takes in a satellite_id so it is said at the correct location. To get the satellite id where an intent is spoken, a decorator can be added to the intent function above the sentences decorator and the satellite_id will get passed into the function on execution:

    @intents.satellite_id
    @intents.sentences(
        [
            "time = 0..128",
            "set timer [(<time>){hours} hours] [(<time>){minutes} minutes] [(<time>){seconds} seconds]",
        ]
    )
    def set_timer(
        self,
        satellite_id,
        hours: int = None,
        minutes: int = None,
        seconds: int = None,
        timer_partial_time=None,
    ):

home_intent.play_audio_file(filename, satellite_id, language_dependent=False)

This will load a .wav file from the filename using the get_file and play it back using Home Intent. It can take in the language_dependent flag (but defaults to False) to load audio files specific to a language if needed. It can also playback at a specified satellite_id. See the home_intent.say() method above on how to get the satellite_id.