You are reading the development docs (2026.12.1-dev.1): features here may not be released yet.
Skip to content

Helper Manager ​

window.lcards.core.helperManager: Lifecycle management for the Home Assistant helper entities LCARdS uses.


Overview ​

LCARdSHelperManager extends BaseService and manages the Home Assistant helpers (input_select, input_boolean, input_number and input_text, plus one template sensor that has to be set up by hand) behind alert mode, alert colour tuning, sound settings and the HA-LCARS theme values. It detects missing helpers, creates them through Home Assistant's helper WebSocket commands, gives typed read/write access by short key, notifies subscribers when a helper changes, and applies changes of input_select.lcards_alert_mode to the theme (the alert-mode auto-switch).

Helpers hold state shared by every browser (one Home Assistant entity per setting). Per-user and per-device settings live in Scoped Settings instead, with the helper value as their globalFallback.


Key Files ​

FileRole
src/core/helpers/lcards-helper-manager.jsService: state listener, value cache, subscriptions, auto-switch, public API
src/core/helpers/lcards-helper-registry.jsHELPER_REGISTRY: every helper with its key, entity ID, domain, category, default and creation parameters; getAllHelpers(), getHelpersByCategory(), getHelperDefinition(), findHelperByEntityId(), getCategories(), generateHelpersYAML()
src/core/helpers/lcards-helper-api.jsHome Assistant calls: createHelper() (<domain>/create), ensureHelper(), updateHelperConfig(), updateHelperEntityId(), deleteHelper(), setHelperValue() (service calls), getHelperValue(), helperExists(), verifyHelperAPIAvailable()

Helper Registry ​

HELPER_REGISTRY defines 49 helpers in three categories. The API takes the key, not the entity ID.

CategoryCountContents
alert_system36alert_mode, alert_mode_auto_switch, alert_message, alert_transition_style, and 32 alert_lab_* colour-tuning numbers per alert colour
ha_lcars_theme7HA-LCARS theme values (lcars_sound, lcars_texture, lcars_elbow_angle, lcars_vertical, lcars_horizontal, lcars_menu_font) and lcars_header, a template sensor with ws_create_params: null (not creatable; skipped by ensureHelper())
sound6sound_enabled, sound_cards_enabled, sound_ui_enabled, sound_alerts_enabled, sound_volume, sound_scheme

The commonly used ones:

KeyEntityDefaultPurpose
alert_modeinput_select.lcards_alert_modegreen_alertCurrent alert state; every option carries the _alert suffix (green_alert, red_alert, yellow_alert, blue_alert, gray_alert, black_alert)
alert_mode_auto_switchinput_boolean.lcards_alert_mode_auto_switchoffApply the stored alert mode when a page loads
alert_messageinput_text.lcards_alert_message""Message text for the alert overlay
alert_transition_styleinput_select.lcards_alert_transition_styleoffTransition used when the alert mode changes
sound_enabledinput_boolean.lcards_sound_enabledoffGlobal sound on/off
sound_volumeinput_number.lcards_sound_volume0.5Master volume, 0-1 in steps of 0.05
sound_schemeinput_select.lcards_sound_schemenoneActive sound scheme; its options are kept in sync with the loaded schemes (updateSelectOptions())

Run window.lcards.core.helperManager.getAllHelpers() for the full list, or see Persistent Helpers. Helpers can be created from the Config Panel (Helpers tab), which calls ensureAllHelpers().


State Tracking ​

On the first updateHass() with a HASS (_autoSwitchInitialized guards it), the manager:

  1. Listens once per helper entity through the page's one shared state subscription (_setupStateListeners(), src/core/state-change-hub.js), which data sources and the rules engine share too. One subscription per helper (and per data source) multiplied the event traffic per tab enough to overflow Home Assistant's pending-message queue (#405, #408); since 2026-11-18 the shared one is filtered to the listeners' entities on the server (see Data Source System; tests/core/state-change-hub.test.js).
  2. Sets up the alert-mode auto-switch (_setupAlertModeAutoSwitch()).

Each change event updates _valueCache with the new state string and calls the key's subscribers with (newValue, oldValue). Later updateHass() calls refresh the cache from hass.states (_updateValueCache()).

Besides the core's distribution, LCARdSNativeCard's hass setter forwards every real HASS to helperManager.ingestHass() (which calls updateHass()), so the manager is fed on any page with an LCARdS card. Every card forwards the same object, so updateHass() returns at once for the HASS it already holds (once the auto-switch is set up); only the first pass of each new object refreshes the cache (src/core/helpers/lcards-helper-manager.js:85-88).

Values are entity state strings as Home Assistant reports them: 'on' / 'off' for booleans, '0.5' for numbers.


Alert-Mode Auto-Switch ​

This is the link between the alert_mode helper and the Theme System; what setAlertMode() then does is in Alert Mode Integration:

  • On change: a subscriber on alert_mode calls window.lcards.setAlertMode(newMode) for every change of the helper, whatever alert_mode_auto_switch says. It skips the call when themeManager.getAlertMode() already equals the new mode (the change came from setAlertMode() itself syncing the helper), and pushes the current HASS to the core first.
  • Auto-switch turned on: when alert_mode_auto_switch goes from off to on, the current alert_mode is applied.
  • On page load: if alert_mode_auto_switch is on and alert_mode holds one of the six LCARdS modes, it is applied with { skipTransition: true }. Home Assistant can report a transient state while it restores the helper, so the check is retried after 100 ms, 750 ms and 2500 ms and then on every later updateHass() until it succeeds or becomes moot (auto-switch off, or a real change event arrived).

Targeted alerts from the lcards.set_alert_mode action do not go through the helper: IntegrationService calls setAlertMode(mode, { skipHelperSync: true }) on the targeted browsers only.


Value API ​

javascript
const hm = window.lcards.core.helperManager;

// Read: the cache, else hass.states, else the registry default (synchronous)
const mode = hm.getHelperValue('alert_mode');   // 'green_alert'

// Write: a service call (select_option, set_value, turn_on / turn_off)
await hm.setHelperValue('alert_mode', 'red_alert');

// Subscribe to changes
const unsub = hm.subscribeToHelper('alert_mode', (newValue, oldValue) => {
  console.log('Alert mode changed to', newValue);
});
unsub();   // removes just this callback
MethodReturnsDescription
getHelperValue(key)anyCached value; otherwise read live from hass.states (not cached), else the registry default_value; null for an unknown key
setHelperValue(key, value)Promise<void>Calls the domain's service; input_number values are clamped to the entity's own min / max; the cache is updated at once (booleans as 'on' / 'off'). Throws for an unknown key or without HASS
helperExists(key)booleanThe entity is in hass.states
subscribeToHelper(key, cb)() => voidAdd a (newValue, oldValue) callback; returns its unsubscribe function
unsubscribeFromHelper(key)voidRemove every callback for the key, including the manager's own auto-switch subscriber on alert_mode; prefer the returned function
resolveHelperBindings(config, bindings)ObjectCopy of config with { configKey: helperKey } bindings replaced by helper values

Creating Helpers ​

MethodReturnsDescription
getMissingHelpers()Object[]Synchronous: the registry definitions whose entity is not in hass.states (all of them without HASS)
ensureHelper(key)Promise<{ exists, created, entity_id, skipped? }>Create one helper if missing (<domain>/create, then rename the entity ID if Home Assistant chose another), then write its default_value after 300 ms. Helpers with ws_create_params: null return skipped: true
ensureAllHelpers()Promise<{ total, existing, created, failed, errors }>ensureHelper() for every registry entry; failures are collected, not thrown
resetCategoryToDefaults(category?)Promise<{ success, failed, skipped }>Write the default to every existing helper of a category (or all), skipping helpers without a default and those marked excludeFromBulkReset
updateSelectOptions(key, options, preferredValue?)Promise<{ optionsUpdated, restored }>Replace an input_select's options persistently (input_select/update), falling back to the input_select.set_options service (not persistent) when that fails, for example for non-admins; then restore the selected value
generateYAML(category?)stringYAML for the helpers, for manual setup
getHelpersByCategory(category) / getAllHelpers()Object[]Registry definitions

Creating and updating helpers uses Home Assistant's admin-only helper commands, so it works for admins only.


Console Access ​

javascript
window.lcards.debug.singleton('helperManager')
// → { type: 'HelperManager', subscriptionsCount: 2, stateListeners: 1, watchedHelpers: 49,
//      cachedValues: 48, autoSwitchInitialized: true }
javascript
const hm = window.lcards.core.helperManager

hm.getHelperValue('alert_mode')                     // current value of a helper
await hm.setHelperValue('alert_mode', 'red_alert')  // update a helper
hm.subscribeToHelper('alert_mode', cb)              // listen for changes
hm.getMissingHelpers()                              // definitions not yet created
await hm.ensureAllHelpers()                         // create the missing ones

stateListeners is 1 once the shared state subscription exists (0 before); watchedHelpers is the number of helper entity IDs it watches.


See Also ​

Released under the MIT License. | About