Home Assistant Nabu Casa Cloud Integration
hass-nabucasa is the official Python library that powers the Nabu Casa Cloud integration within Home Assistant Core. It provides functionality for remote access, voice assistant integrations (Alexa, Google Assistant), and other cloud services for Home Assistant instances. The current version is 2.2.0, requiring Python >=3.14. Its release cadence is tightly coupled with Home Assistant Core releases, generally receiving frequent updates.
Warnings
- gotcha `hass-nabucasa` is an internal dependency of Home Assistant Core, not intended for direct standalone scripting by end-users. Attempting to import and use it outside a fully functional Home Assistant environment is generally unsupported and will likely lead to errors or unexpected behavior.
- breaking This library is tightly coupled with Home Assistant Core versions. Installing or upgrading `hass-nabucasa` independently of `homeassistant` can introduce breaking changes, compatibility issues, or lead to a non-functional cloud integration. Always ensure `hass-nabucasa` matches the expected version for your Home Assistant release, which typically means letting Home Assistant manage its dependencies.
- gotcha All configuration, including Nabu Casa Cloud subscription management and authentication for integrations like Alexa or Google Assistant, is handled entirely within Home Assistant's `cloud:` configuration. Direct programmatic access to cloud credentials or services via `hass-nabucasa`'s API is not exposed for external use.
Install
-
pip install hass-nabucasa
Imports
- Cloud
from hass_nabucasa import Cloud
- Alexa
from hass_nabucasa import Alexa
- GoogleAssistant
from hass_nabucasa import GoogleAssistant
Quickstart
import os
import asyncio
from unittest.mock import MagicMock
from hass_nabucasa import Cloud
# WARNING: This library is an internal dependency of Home Assistant Core.
# It is NOT designed for direct standalone use by end-user applications.
# The code below is HIGHLY conceptual and uses mocks to illustrate basic instantiation.
# It will NOT connect to Nabu Casa Cloud or provide any meaningful functionality
# outside of a fully operational Home Assistant environment.
# All configuration, authentication, and service interactions are managed by Home Assistant itself.
async def main():
print("--- Conceptual hass-nabucasa usage demonstration ---")
# In a real Home Assistant setup, 'hass' is the Home Assistant instance object.
# We're mocking it here to make the code 'runnable' without a full HA environment.
hass_mock = MagicMock()
hass_mock.config.time_zone = 'UTC'
hass_mock.config.latitude = 0.0
hass_mock.config.longitude = 0.0
hass_mock.config.internal_url = 'http://localhost:8123'
hass_mock.config.external_url = os.environ.get('HA_EXTERNAL_URL', 'http://localhost:8123')
hass_mock.data = {}
hass_mock.loop = asyncio.get_running_loop()
hass_mock.bus.async_listen = MagicMock()
hass_mock.helpers.network.get_url = MagicMock(return_value=hass_mock.config.internal_url)
hass_mock.helpers.aiohttp_client.async_get_clientsession = MagicMock()
hass_mock.components.websocket_api.async_register_command = MagicMock()
hass_mock.data.setdefault = MagicMock()
print("Attempting to instantiate hass_nabucasa.Cloud with a mocked Home Assistant instance...")
try:
# Instantiating the Cloud class requires a 'hass' (Home Assistant) object.
cloud_instance = Cloud(hass_mock)
print(f"Successfully created a conceptual Cloud instance: {cloud_instance}")
print("Remember: This instance is non-functional without a full HA context.")
print("To use Nabu Casa Cloud, configure the 'cloud:' component in Home Assistant.")
except Exception as e:
print(f"Failed to instantiate Cloud: {e}")
print("This often happens if essential Home Assistant dependencies/context are missing.")
if __name__ == "__main__":
asyncio.run(main())