vscode-home-assistant

repository·dev·Indexed 20 days ago

https://github.com/keesschollaart81/vscode-home-assistant

A VS Code extension providing developer tooling for Home Assistant configuration, including schema validation, auto-completion for entity IDs, actions, scenes, and triggers, and Jinja template rendering via the Home Assistant API. It features seamless navigation between included YAML files using 'Go to Definition' and the ability to reload integrations directly from the editor.

Tokens
16.8K
Snippets
47
Records
99
Agent score
71%

What's inside vscode-home-assistant

  1. Validate Configuration and Lovelace schemas

    dev

    The extension provides schema validation and auto-completion for Home Assistant Configuration and Lovelace files.

    Key capabilities include:

    • Schema Validation: Validates properties, values, and enums against Home Assistant's official schemas.
    • Scoped Validation: The extension understands !include behavior, providing context-aware validation based on the file's scope.
    • Deprecation Warnings: Identifies deprecated configuration keys and provides warnings.
    • Schema Documentation: Provides hover documentation for schema properties to explain their usage.
  2. Install and set up the Home Assistant Config Helper

    dev

    To use this extension for managing your Home Assistant configuration in VS Code, follow these steps:

    1. Install the extension: Search for and install keesschollaart.vscode-home-assistant via the VS Code Marketplace.
    2. Open your configuration: Open your local copy of your Home Assistant configuration folder in VS Code.
    3. Configure the connection: You must connect the extension to your Home Assistant server. This is done via the HA Section in the VS Code Settings UI.

    For detailed instructions on connection types (local vs. remote) and using VS Code Remote SSH, refer to the project wiki.

  3. Use auto-completion for Entity IDs, Actions, Scenes, and Triggers

    dev

    Once connected to your Home Assistant server, the extension provides real-time auto-completion for:

    • Entity IDs
    • Actions
    • Scenes
    • Triggers

    This allows you to quickly reference existing entities and services within your YAML configurations without manual lookup.

  4. Manage Home Assistant credentials with AuthManager

    dev

    The AuthManager class provides static methods to securely manage Home Assistant connection credentials (URL and Long-Lived Access Token) using VS Code's SecretStorage. It supports a fallback mechanism to environment variables and legacy settings.json configurations.

    Credential Resolution Order

    When retrieving credentials, the manager follows this priority:

    1. VS Code SecretStorage: The most secure method.
    2. Environment Variables:
      • For Token: HASS_TOKEN or SUPERVISOR_TOKEN.
      • For URL: HASS_SERVER or http://supervisor/core (if SUPERVISOR_TOKEN is present).
    3. Legacy Settings: vscode-home-assistant.longLivedAccessToken and vscode-home-assistant.hostUrl (these are automatically migrated to SecretStorage upon access).

    Key Methods

    • hasCredentials(context): Returns true if both a valid URL and token are available.
    • getTokenWithUI(context): A high-level helper that attempts to resolve credentials through the hierarchy and, if missing, prompts the user via VS Code input boxes to enter the URL and Token.
    import { AuthManager } from './auth/manager';
    
    // Check if credentials exist
    const ready = await AuthManager.hasCredentials(context);
    
    if (!ready) {
      // Prompt user via UI to fill in missing info
      const token = await AuthManager.getTokenWithUI(context);
      if (token) {
        console.log('Authenticated!');
      }
    }
  5. Common configuration for Template entities

    dev

    Most template entities inherit from BaseItem and support the following common configuration keys:

    • availability: A template that determines if the entity is available. If it fails to render or returns True, 1, true, yes, on, enable, or a non-zero number, the entity is available.
    • default_entity_id: Used instead of name for automatic generation of the entity ID (e.g., sensor.my_awesome_sensor).
    • icon: A template for the entity's icon.
    • name: A template for the entity's name.
    • picture: A template for the entity's picture.
    • unique_id: A unique identifier for the entity. When provided, it allows customization of the name, icon, and entity ID via the web interface.
  6. Common properties for all Home Assistant actions

    dev

    Most Home Assistant actions share a set of common configuration keys that allow you to manage their execution behavior within a script or automation sequence:

    • alias: A human-readable name for the action.
    • enabled: A boolean to disable the action without removing it from the configuration.
    • continue_on_error: If set to true, the action sequence will continue even if this specific action encounters an error.
  7. Use Logical conditions (And, Or, Not)

    dev

    You can combine multiple conditions using logical operators. Home Assistant supports both standard and shorthand notations.

    And Condition

    Passes if all embedded conditions are valid.

    • Standard: Use condition: and with a conditions list.
    • Shorthand: Use the and key directly.

    Or Condition

    Passes if any embedded condition is valid.

    • Standard: Use condition: or with a conditions list.
    • Shorthand: Use the or key directly.

    Not Condition

    Passes if all embedded conditions are NOT valid.

    • Standard: Use condition: not with a conditions list.
    • Shorthand: Use the not key directly.
    # Standard And
    condition: and
    conditions:
      - condition: state
        entity_id: light.kitchen
        state: "on"
      - condition: sun
        after: sunset
    
    # Shorthand And
    and:
      - condition: state
        entity_id: light.kitchen
        state: "on"
      - condition: sun
        after: sunset
    
    # Not Shorthand
    not:
      - condition: state
        entity_id: binary_sensor.motion
        state: "on"