Skip to content

10000-ft View

  1. The core of HA is the event bus.
  2. The next part is the state machine which stores entity state.
    • Entities are things like devices, people, uptime, etc.
    • Whenever state changes on an entity, a state_changed event is fired.
  3. The next part is the service registry which allows components to register services on the event bus.
    • Services are called by firing events on the event bus.
    • The service registry executes events and fires completion events.
  4. The last part is the timer, which fires time changed events every second.

Extending Home Assistant

Home Assistant can be extended into two ways: integrations and add-ons.

  • Integrations allow you to integrate functionality into HA's core, enabling deep integration into HA. In fact, much of HA's internal functionality is implemented through integrations.
  • Add-ons are run in separate Docker containers and communicate via API.

Integrations

Integrations are how new devices and services are added to Home Assistant and how much of HA's core functionality is defined and implemented.

Here are a few examples:

As we've introduced many new terms, let's spend a few moments talking about commonly used terms and concepts.


Common Terms and Concepts

Devices are specific, real-world physical objects or devices, such as light switches, sensors, and fans, that we may want to integrate with Home Assistant.

Integrations are how new functionality is added to HA core (i.e. new devices).

Domains are how integrations are uniquely namespaced within HA. By convention, domain names correspond to IoT device categories, (i.e. light, switch sensor, fan, etc.).

Entities are how devices are described and implemented in Home Assistant.

  • An entity describes the information needed to document the current state of a device.
  • HA defines a number of core entity integrations (i.e. LightEntity, SwitchEntity, SensorEntity, FanEntity, etc.) which can be extended by your integration.
  • Note: A device may require more than one entity to accurately model its state. For example, a dimmer light switch may require both a LightEntity and SwitchEntity to track its on/off state and the current brightness of the light.

Services are how entities allow integrations to modify their internal state.

Platforms are how custom entities are defined and implemented in integrations. - Platforms are created by subclassing a core entity.

Components are classes that introduce new logic into HA. - Typically, components are where the internal "glue code" of an integration is implemented.


How Are Integrations Implemented?

Integrations announce their existence by interacting with the HA core registries to register devices, entities, and services.

Integrations: - maintain entity state - listen for and trigger events - offer services

Entities

Entities are things like lights, motion detectors, people, uptime.

HA provides Entity Components which describe basic assumptions on how a device works.

Entities architecture: - https://developers.home-assistant.io/docs/architecture/devices-and-services - https://developers.home-assistant.io/docs/core/entity/

Examples - Sensor: - https://github.com/home-assistant/example-custom-config/tree/master/custom_components/example_sensor/ - Light: - https://github.com/home-assistant/example-custom-config/tree/master/custom_components/example_light/


References


Development Environment Setup

Home Assistant Core is developed using Visual Studio Code and devcontainers.

Pasted image 20230330183531.png

Pasted image 20230330183447.png

Pasted image 20230330183635.png

devcontainer.json
"mounts": [
    // Custom configuration directory
    "source=${localEnv:HOME}/path/to/config,target=${containerWorkspaceFolder}/config,type=bind",
    // Custom component
    "source=${localEnv:HOME}/path/to/custom_repo/custom_components/component_name,target=${containerWorkspaceFolder}/config/custom_components/component_name,type=bind",
    //Custom library
    //"source=${localEnv:HOME}/path/to/custom_repo/custom_libraries/library_name,target=${containerWorkspaceFolder}/config/custom_libraries/library_name,type=bind",
  ]

Writing A Timelapse Plugin

Requirements

  • Must integrate with ESPHome
  • Must integrate with built-in camera integration
  • Must allow configurable encoder (i.e. ffmpeg, gstreamer, etc.)
  • Must allow configurable image storage folder
  • Must allow creation of daily/weekly snapshots

References


References


Last update: 2023-03-30