Animation System
How an
animations:entry or a rule animation becomes an anime.js v4 animation: who fires each trigger, where scopes live, and which files to read. Reference: Animation Manager (scopes, registration, playback, API). User docs: Animations, Triggers, Preset reference.
Quick start
A card-level animation (here on its own entity's change) and a rule animation that targets cards by tag:
type: custom:lcards-button
entity: light.bedroom
preset: lozenge
tags:
- bedroom_widgets
text:
name:
show: true
tap_action:
action: toggle
animations:
- trigger: on_entity_change
entity: light.bedroom
to_state: "on"
preset: glow
duration: 500
rules:
- id: bedroom_on_pulse
when:
entity: light.bedroom
state: "on"
apply:
animations:
- tag: bedroom_widgets
preset: pulse
loop: trueThe rule's pulse runs while the rule matches and stops when it stops matching; the on_entity_change glow plays once per change to on. To loop while a state holds without a rule, use while on the card's own animation (Entity change triggers).
Architecture
- One manager.
LCARdSCorecreates the onlyAnimationManager; cards and MSD cards share it. Each animated element (a card, a card segment, an MSD overlay) gets a scope: an anime.jscreateScope(), aTriggerManager, and the instances it started. - Registration. A card's scope is registered by
LCARdSActionHandler.setupActions()(it callsonOverlayRendered(id, element, { animations }), also for cards without animations so rules can animate them). The slider and data grid callonOverlayRendered()themselves; MSD does it per overlay fromPipelineCore. A re-render of the same id rebuilds the scope and carries running animations over. See Registration flow. - Rules reach cards by id.
_registerOverlayForRules()stores the card's animation scope id asanimationScopein the overlay registry, so a rule animation aimed at a card'sidor tag finds the scope whatever the card calls it (Scopes). - No registry of instances. The old
AnimationRegistrycache (window.lcards.core.animationRegistry) was removed in 2026.11; playback always goes throughplayAnimation().
Trigger types
The list of triggers and what each one does for a user is on the Triggers page (with Entity Change Triggers for on_entity_change). Which code fires each trigger, with file and line, is in Animation Manager: Trigger types. In short: AnimationManager fires on_load and on_show, the card's LCARdSActionHandler the tap, hold and hover triggers, TriggerManager on_entity_change, a data source subscription on_datasource_change, and the Rules Engine the internal on_rule.
Rule-based or entity change
| Rule animation | on_entity_change | |
|---|---|---|
| Configured in | rules[].apply.animations | The card's animations: |
| Targets | Any registered element (id, tag:, type:, pattern) | The card (or segment) it is on |
| Conditions | Full rule when (all / any / not, numeric, time, data sources) | from_state, to_state, attribute, while |
| Stops | When the rule stops matching (looping ones) | while ending (with loop: true) |
| Across cards | Yes | No |
Playback features
- Presets and easing. An entry's
presetnames a registered preset (registerAnimationPreset()insrc/core/animation/presets.js; the built-ins are insrc/core/packs/animations/presets/and are registered byregisterBuiltinAnimationPresets()during pack loading).easeis resolved byresolveEasing()insrc/utils/lcards-anim-helpers.js. Code that calls anime.js follows the project'sanimejsskill (v4 API:animate(),createTimeline(),inOutQuad). map_rangevalues.duration,delayand params can bemap_rangedescriptors on an entity (resolveAnimParams.js). A looping animation whosedurationis mapped gets a live speed binding: when that entity changes, the running instance'sspeedis adjusted without a restart.- Targets.
target/targetsselect elements inside the scope (or through the MSD overlay's targeting API);target: backgroundanimates the card's background effect handles (effect: Nfor one layer). - Segments. Button component segments get scopes of their own (
{cardId}:segment:{segmentId},registerSegmentAnimations(),playSegmentAnimation()). - Reduced motion. Under
prefers-reduced-motion: reducean animation is settled instead of played: a finite one jumps to its end frame, a looping one is reverted. Switching the setting on settles running animations.essential_motion: trueexempts an entry. - Stopping.
stopAnimations(id, trigger?, def?)reverts instances (anime.jsrevert()restores the captured styles and attributes);destroyOverlayScope(id)runs on disconnect.
Details and line references: Playback: playAnimation().
Files
File (under src/) | Role |
|---|---|
core/animation/AnimationManager.js | The manager: scopes, triggers, playback, carry-over, reduced motion, speed bindings, segments |
core/animation/TriggerManager.js | One per scope: registrations per trigger, entity subscriptions for on_entity_change and while |
core/animation/resolveAnimParams.js | map_range in animation duration, delay and params |
core/animation/presets.js | The preset registry (registerAnimationPreset, getAnimationPreset, listAnimationPresets, preset info for the Pack Explorer) |
core/packs/animations/ | The built-in presets and registerBuiltinAnimationPresets() |
utils/lcards-anim-helpers.js | animateElement(), resolveEasing() (window.lcards.anim) |
utils/reduced-motion.js | prefersReducedMotion(), onReducedMotionChange() |
base/LCARdSActionHandler.js | Interactive triggers |
core/rules/RulesEngine.js | Rule animations (_executeRuleAnimations(), _stopRuleAnimations()) |
core/animation/PerformanceMonitor.js | FPS monitor for canvas backgrounds; not part of card animation playback |
Other moving visuals have their own systems: Background Animation System (Canvas2D and WebGL card backgrounds), Shape Texture System (effects inside button and elbow shapes), Screen Effect System (full-screen layers) and the alert-mode palette transitions in the Theme System.
Debugging
window.lcards.setGlobalLogLevel('debug');
window.lcards.core.animationManager.scopes; // Map of scope id to scope dataUseful log lines:
[RulesEngine] 🎬 Executing N animation(s) for rule: X[RulesEngine] 🛑 Stopping animations for rule: X[TriggerManager] 🎬 Triggering animation for <scope> on entity change: <entity>[TriggerManager] 🎬 while-start: .../⏹️ while-stop: ...[AnimationManager] 📊 Datasource change: X
More console helpers: Animation Manager: Console access.