10000-ft View¶
- The core of HA is the event bus.
- 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.
- 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.
- 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:
-
Lights are defined as
LightEntity
components provided by thelight
integration- Github Link:
/components/light/__init__.py
- Github Link:
-
Switches are defined as
SwitchEntity
components provided by theswitch
integration- Github Link:
/components/switch/__init__.py
- Github Link:
-
Light switches are defined in the
LightSwitch
platform provided by theswitch
integration- Github Link:
/components/switch/light.py
- Github Link:
-
Philips Hue devices are accessed through the
HueBridge
component provided by thehue
integration- Github Links:
/components/hue/__init__.py
,/components/hue/bridge.py
- Github Links:
-
Philips Hue lights are defined in the
HueLight
platform provided by thehue
integration- Github Link:
/components/hue/light.py
- Github Link:
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
andSwitchEntity
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¶
- Architecture Overview:
- Integrations Tutorial:
- Integration Repository:
- Integration Examples Repository:
- Add-Ons Tutorial:
- Add-Ons Repository:
- TBD
Development Environment Setup¶
Home Assistant Core is developed using Visual Studio Code and devcontainers.
- Follow instructions here: Developing with Visual Studio Code + devcontainer
- Mount custom_components to devcontainer
"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¶
- https://nkmakes.github.io/2020/09/01/Homeassistant-hassio-timelapses-easy-guide/
- https://frigi.ch/2021/01/timelapse-in-home-assistant/
- https://www.wictorwilen.se/blog/announcing-ring-timelapse/
References¶
- Ring Timelapse
-
Motivation:
-
ESPHome
- Main Codebase: https://github.com/esphome/esphome
- Dashboard: https://github.com/esphome/esphome/tree/dev/esphome/dashboard
- Home Assistant Add-On Repository: https://github.com/esphome/hassio
- Local Home Assistant Links
- Where the ESPHome Configuration Card shows up