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

Rules Engine ​

A rule changes cards while a condition holds: when an entity, the time or a template says so, it patches the cards it targets, and takes the patch off again when the condition stops holding. One rule can restyle a single card, every card with a tag, or the lines on an MSD.

  • A rule has three parts: when (the condition), apply (what changes) and an id. It can sit in any card's rules list and still change other cards on the page.
  • A patch is a piece of card config (style, text ...) merged over the card's own while the rule matches. Rules can also start animations and tint an MSD's blueprint.

Try it

  • Every card editor has a Rules tab: it lists the rules on the page, adds and edits them with a condition builder, and turns them on and off.
  • The Rules view of the Live Demo shows rules recolouring and blinking cards as you drag sliders.
PageCovers
Conditionswhen: entity states and attributes, numbers, time, sun, chance, all/any/not, JavaScript and Jinja2
Targets and Changesapply: naming cards with id and tags, selectors, patches, animations, MSD blueprint filters
Priority and DebuggingWhich rule wins, stop, enabled, and seeing which rules apply now
ExamplesWhole rule sets to copy: a temperature alert, day and night, a multi-condition alert

Quick start ​

A rule on one card can restyle a group of others: here the toggle turns the three panels red. The panels carry the tag docs-rules-deck, and the rule's tag:docs-rules-deck selector finds them.

  • Tap TOGGLE (or use the control under the card) to switch input_boolean.lcards_test_toggle; the rule matches while it is "on".
  • The rule lives on the toggle button, but it would work from any card on the page: rules are not tied to the card that holds them.
yaml
type: custom:lcards-layout-card
layout:
  height: 150px
  grid-gap: 6px
  grid-template-columns: 1fr 1fr 1fr
  grid-template-rows: 1fr 1fr
cards:
  - type: custom:lcards-button
    preset: lozenge
    entity: input_boolean.lcards_test_toggle
    tap_action:
      action: toggle
    text:
      name:
        content: TOGGLE
        show: true
    view_layout:
      grid-column: 1 / 4
    rules:
      - id: docs-rules-quick-start
        when:
          entity: input_boolean.lcards_test_toggle
          state: "on"
        apply:
          overlays:
            tag:docs-rules-deck:
              style:
                card:
                  color:
                    background: var(--lcars-alert-red)
  # three panels in one group
  - type: custom:lcards-button
    preset: filled
    tags:
      - docs-rules-deck
    text:
      name:
        content: REACTOR
        show: true
  - type: custom:lcards-button
    preset: filled
    tags:
      - docs-rules-deck
    text:
      name:
        content: INJECTORS
        show: true
  - type: custom:lcards-button
    preset: filled
    tags:
      - docs-rules-deck
    text:
      name:
        content: CONDUITS
        show: true

Where rules live ​

Rules go in the rules list of any LCARdS card, or in a content pack. All of them run in one engine for the whole page, keyed by rule id.

  • Give every rule an id no other card on the page uses: cards listing the same id share one rule (the one loaded last is used), and a card rule with the id of a pack rule is skipped.
  • A rule with no id is skipped too, with a warning in the browser console.

Rule changes apply when you save

Adding, changing or removing a rule takes effect when you save the card (the card editor's preview shows it straight away), with no page refresh. A card taken off the dashboard takes its rules with it a few seconds later.

Rule structure ​

Every rule needs id, when and apply; the other keys are optional. This rule recolours its own card while the power level is above 80.

  • Drag the power control under the card above or below 80 to see the rule match and let go.
  • priority, stop and enabled decide what happens when several rules patch the same card: see Priority and Debugging.
yaml
type: custom:lcards-button
id: docs-rules-structure-btn
preset: lozenge
text:
  name:
    content: POWER
    show: true
rules:
  - id: docs-rules-structure
    name: Power high
    priority: 10
    when:
      entity: input_number.lcards_test_power
      above: 80
    apply:
      overlays:
        docs-rules-structure-btn:
          style:
            card:
              color:
                background: var(--lcars-alert-red)
KeyTypeDefaultDescription
idstringrequiredThe rule's name, unique on the page. Shown in the Rules tab and in traces
namestring-A readable label for the editor
whenobject / listrequiredThe condition: see Conditions. A list means all of its items
applyobjectrequiredWhat changes while the rule matches: see Targets and Changes
prioritynumber0Higher runs first and wins where two rules patch the same key: see priority
stopbooleanfalseWhile this rule matches, lower-priority rules' patches on the same cards are dropped: see stop
enabledbooleantruefalse turns the rule off without deleting it: see enabled

Released under the MIT License. | About