ha-badge-add¶
Adds a custom Lovelace badge to an existing frontend module — the badge custom element, customElements.define, optional graphical editor, and window.customBadges picker registration.
Add a custom Lovelace badge to an existing Home Assistant frontend module, conforming to spec/ha/lovelace-badges. Generates the badge custom element (an HTMLElement or LitElement subclass with setConfig, the hass property setter, and render), the customElements.define call (the tag name becomes custom:
- Plugin:
claude-home-assistant - Phase: 3 Design (
design) - Tags:
home-assistant,lovelace,frontend,badge - Source: skills/ha-badge-add/SKILL.md
Use when¶
- you want to add a custom Lovelace badge
- you want to register a custom badge in the badge picker
Don't use when¶
- You need a custom card, not a badge →
ha-lovelace-card-scaffold - You need a tile card feature →
ha-card-features-add - You need a dashboard strategy →
ha-strategy-add - You need the graphical-editor config-changed pattern →
ha-card-editor-add
See also¶
ha-lovelace-card-scaffoldha-card-features-addha-strategy-addha-card-editor-addha-lovelace-solution
Referenced by¶
HA Badge Add¶
Spec: https://github.com/nolte/claude-home-assistant/blob/develop/spec/claude/ha-badge-add/de.md (DE canonical) / en.md.
Why this is a skill, not an agent¶
- Human-visible augmentation surface — the user describes a status display and reads back the badge element, the registration entry, and the conformance report; a skill keeps this on the visible command surface, like the sibling frontend skill
ha-lovelace-card-scaffold. - Mid-flow interactivity — the
badge_typetag-name decision and the "graphical editor yes/no" choice are per-run dialogues the user approves before generation. - Bounded, inline generation — one custom-element module plus its
window.customBadgespush and optional editor fit inline; no isolated agent context is needed. - Counter-dimension considered: the draft→validate loop could be an agent, but the tag-name and editor-depth decisions belong in the user's working context; skill wins.
When this skill activates¶
Use this skill to add one custom badge — the small status widget at the head of a Lovelace view — to an existing frontend module (an integration's www/ folder or a standalone Lovelace module).
When NOT to activate¶
- a custom card (the larger content building block) →
ha-lovelace-card-scaffold/ha/lovelace-card-patterns - a tile card feature →
ha/lovelace-card-features - a dashboard strategy →
ha/lovelace-strategies - the
config-changedgraphical-editor detail pattern →ha/lovelace-card-editor - deploying/importing into a running HA instance → out of scope
Hard rules¶
- One badge, one run. No multi-badge batches.
- Read
ha/lovelace-badgesfirst. Do not generate from memory. - Custom element, no React. Define the badge as a subclass of
HTMLElement(orLitElement) and register it viacustomElements.define("<badge-type>", <BadgeClass>); the tag name becomes the badge typecustom:<badge-type>. Never use React as the rendering framework — custom elements and React are not compatible in HA badges. setConfigcontract. ImplementsetConfig(config); reject an invalid configuration withthrow new Error("...")— HA catches it and renders an error badge.hasssetter. Implement thehassproperty as a setter; the badge updates itself to the latest state on every set. Read the consumed entity fromhass.states[entityId]and render a sensible fallback (e.g.unavailable) when it is missing (seeha/frontend-data-api).- Picker registration. Push an entry into
window.customBadges(window.customBadges = window.customBadges || []; window.customBadges.push({...})) with at least the requiredtypeandname;description/documentationURL/previeware optional (previewdefaults tofalse). - Graphical editor is optional. Add the static
getConfigElement()/getStubConfig()only when an editor is wanted; do not spell out theconfig-changedevent pattern here — that is governed byha/lovelace-card-editor. - Document the wiring. Reference the badge via
type: "custom:<badge-type>"in a view'sbadges:list and add amoduleresource with the badge module URL (typically/local/<badge-name>.js); note the HA restart needed after first creating thewwwfolder. - Name per
ha/naming-conventionsand verify HA internals against the official docs (seeha/upstream-docs-verification). - Honour the layout-antipattern catalogue (
ha/lovelace-layout-antipatterns). Badges do not render inpanelorsidebarviews (A2) — when documenting the wiring, note the target view must support badges (Sections, Masonry), not panel/sidebar.
Inputs¶
| Field | Required | Default | Notes |
|---|---|---|---|
target_dir |
yes | — | repo root; an existing frontend module / www/ directory must exist |
display |
yes | — | the status display the badge expresses, in prose (incl. the consumed entity) |
badge_type |
no | inferred + confirmed | the customElements.define tag name → custom:<badge-type> |
name / description |
no | derived | the badge-picker display name and optional description |
framework |
no | per project default | HTMLElement vs LitElement |
editor |
no | asked | generate getConfigElement / getStubConfig |
If the user is silent on an optional field, use the default but state it explicitly.
Pre-flight (in order — abort on first failure)¶
target_diris an existing frontend module (awww/directory or an existing Lovelace module). If not, point atha-lovelace-card-scaffoldfor greenfield and stop.- Resolve
badge_type(infer + confirm) and check it againstha/naming-conventions. - Read
ha/lovelace-badges. - The badge module /
badge_typeis not already declared. If it is, abort.
Workflow¶
1) Resolve and confirm¶
State target_dir, the resolved badge_type (→ custom:<badge-type>), the display name, the chosen framework, and whether a graphical editor is generated, in one paragraph. Wait for confirmation.
2) Generate¶
- The badge custom element (subclass of
HTMLElement/LitElement) withsetConfig(config)(throwing on invalid config), thehassproperty setter (updating on every set, with anunavailablefallback), and the render. - The
customElements.define("<badge-type>", <BadgeClass>)call and thewindow.customBadgespush (type+namemandatory;descriptionoptional). - When
editoris wanted, the staticgetConfigElement()/getStubConfig()(and an optional<badge-name>-editor.js). - The dashboard wiring note:
type: "custom:<badge-type>"in thebadges:list and themoduleresource URL.
3) Validate and report¶
Validate offline (subclass of HTMLElement/LitElement, no React; customElements.define called; setConfig implemented and throwing on invalid config; hass is a setter; window.customBadges push carries type + name; getConfigElement/getStubConfig implemented or deliberately omitted; dashboard referencing + module resource documented). Emit a CONFORMANT / NEEDS-WORK report keyed to the ha/lovelace-badges acceptance criteria, plus the changed file paths and the quality-scale marker (not part of the HA quality scale).
4) No deploy¶
The skill never deploys to a live HA instance and never writes a live dashboard/resource configuration. Surface the report and stop.
Boundaries¶
- Custom card →
ha-lovelace-card-scaffold/ha/lovelace-card-patterns - Tile card feature →
ha/lovelace-card-features - Dashboard strategy →
ha/lovelace-strategies - Graphical-editor
config-changeddetail →ha/lovelace-card-editor - Deploy to live HA → out of scope