Skip to content

Lifecycles ​

This page maps every flow inside Linked Lovelace, from the moment the bundle loads in your browser through to writing rendered dashboards back to Home Assistant. Each section pairs a short description with a Mermaid diagram so you can follow the exact sequence of classes and methods involved.

The cast of characters referenced throughout:

PieceFileRole
GlobalLinkedLovelacesrc/instance.tsSingleton holding hass + the API client
LinkedLovelaceApisrc/linked-lovelace-api.tsThin wrapper over Home Assistant WebSocket calls
HassControllersrc/controllers/hass.tsOrchestrates discovery, dry-run, and updates
LinkedLovelaceControllersrc/v2/linkedLovelace.tsRenders a dashboard config with templates
TemplateControllersrc/controllers/template.tsRegistry of card templates + render entry
EtaTemplateControllersrc/controllers/eta.tsRegistry of Eta partials
TemplateEnginesrc/v2/template-engine.tsEta.js engine singleton

1. Bundle Load and Initialization ​

The entry module imports all five cards (each self-registers in window.customCards) and calls initialize(), which waits until Home Assistant's home-assistant element exists before logging the version. The GlobalLinkedLovelace singleton is created lazily the first time any card needs the API.

2. Shared Lit Card Lifecycle ​

Every card is a LitElement and follows the same reactive cycle. setConfig validates and stores config; firstUpdated yields a frame then forces a repaint; shouldUpdate gates re-renders via hasConfigOrEntityChanged.

3. Template Engine Rendering ​

TemplateEngine wraps a single Eta instance configured with varName: 'context' and autoEscape: false. Rendering takes a card serialized to JSON, runs it through Eta with a context object, then parses the result back into a card.

4. Partials: Discovery and Loading ​

Partials live on custom:linked-lovelace-partials cards. During discovery each partial is resolved: a url partial is fetched with fetch (its text becomes template), while an inline partial is used directly. loadPartials then registers every partial that has template text into the Eta engine, sorted by priority with the lowest first, so they can be pulled in with <%~ include('key') %>.

5. Discovery and Refresh ​

HassController.refresh() rebuilds a fresh LinkedLovelaceController, lists all dashboards (prepending overview), fetches every config in parallel, then walks every card in each view, both the cards placed directly in the view and the cards inside sections, collecting templates (ll_key) and partials. Finally it loads partials and registers templates into the engine.

6. Context Resolution (updateCardTemplate) ​

updateCardTemplate is the recursive heart of rendering. When a card has ll_template, context is merged from three layers, the template is rendered through Eta, ll_keys remap selected context values onto the card, and nested ll_context arrays/objects recurse. When a card has no template, the function instead walks sections, cards, card, and any nested objects so deeply-placed templates still render.

7. Full Dashboard Sync (Main User Flow) ​

Triggered from the Status card. Load Data backs up every current config, runs refresh(), then a dry-run (updateAll(true)) that renders configs in memory and diffs them against the backups to build an HTML preview. Only when the user confirms Update All does it write each changed dashboard back via setDashboardConfig (lovelace/config/save).

During rendering, each view card is first stripped of any custom:linked-lovelace-key-chip wrapper. A card that carries both an ll_key and show_key_chips: true is re-wrapped after its template renders, so that definition stays visibly badged on the dashboard.

Per-dashboard updates

The same flow powers the per-dashboard Update button. It calls overwriteDashboard(key), which runs update(key, dryRun=false) for a single dashboard instead of looping over all changed ones.

8. Starter and Demo Install ​

The Starter card's Create Demo Dashboard button calls _install(), which tries to create the dashboard (ignoring "already exists" errors), then saves a fully self-contained demo config built by buildDemoDashboardConfig().

9. Editor Flows ​

Template editor (linked-lovelace-template-editor): after firstUpdated runs a refresh() to discover templates, it renders one button per template. Clicking a button copies the template's body into the card config and fires a config-changed event so Lovelace persists it. The Status card has no visual editor, because it takes no options; Lovelace shows its YAML editor instead.

API Surface ​

The diagrams above bottom out in these Home Assistant WebSocket calls, all wrapped by LinkedLovelaceApi (src/linked-lovelace-api.ts):

MethodWebSocket typeUsed by
getDashboards()lovelace/dashboards/listDiscovery, sync, starter
getDashboardConfig(url)lovelace/configDiscovery, backup, render
setDashboardConfig(url, config)lovelace/config/saveLive update
createDashboard(url, title, sidebar)lovelace/dashboards/createStarter install
toggleDashboardAsTemplate(url, isTemplate)lovelace/config (+ save)Template dashboards

Released under the MIT License.