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

Rule Conditions ​

A rule's when block is its condition: while it is true the rule's apply block holds, and when it turns false the patch comes off. It can test an entity, the time, the sun, a template, or several of these combined. The rest of a rule is on the Rules Engine page.

  • A rule is checked again when an entity it names changes: the entity of a condition, or an entity a template reads. A rule with a time_between, weekday_in or random_chance condition is also checked at the start of every minute.
  • The examples on this page each hold one rule on one button. Use the controls under a card to change the entity and watch the rule match.

All conditions at a glance ​

One key picks the kind of condition; the table links to each.

ConditionKeyWhat it checks
Entity stateentityThe entity's state against a comparison
Entity attributeentity_attrOne attribute of an entity against a comparison
Labels, areas, devicestargetEvery entity a Home Assistant label, area, device or floor includes, compared one by one
Map rangemap_range_condThe state mapped onto a new scale, then compared
All, any, notall, any, notEvery, at least one, or none of the conditions inside
Time rangetime_betweenThe time is inside a "HH:MM-HH:MM" window
Day of weekweekday_inToday is in a list of days
Sun elevationsun_elevationThe sun is above or below an angle
Random chancerandom_chanceTrue with a probability from 0 to 1
JavaScriptcondition, javascript, jsA JavaScript expression returns a truthy value
Jinja2condition, jinja2A Home Assistant Jinja2 template renders true

entity ​

entity tests an entity's state: on its own, or with a comparison such as state: "on" or above: 25. This is the condition most rules use.

  • state means exactly the same as equals. Quote "on" and "off", or YAML may read them as true and false.
  • With no comparison at all, the condition is true while the entity has a state.
yaml
type: custom:lcards-button
id: docs-cond-entity-btn
preset: lozenge
entity: input_boolean.lcards_test_toggle
tap_action:
  action: toggle
text:
  name:
    content: TOGGLE
    show: true
rules:
  - id: docs-cond-entity
    when:
      entity: input_boolean.lcards_test_toggle
      state: "on"
    apply:
      overlays:
        docs-cond-entity-btn:
          style:
            card:
              color:
                background: var(--lcars-alert-red)
More about entity
  • Missing entities: a condition on an entity that does not exist (a typo, a deleted helper) is false.
KeyTypeDefaultDescription
entitystringrequiredThe entity whose state is tested
Comparison operatorsstate, equals, not_equals, above, at_least, below, at_most, in, not_in, regex

Comparison operators ​

The comparison keys test a value: an entity's state, an attribute or a mapped value. They work the same in entity, entity_attr and map_range_cond conditions.

  • The four numeric operators combine: every one you give must hold, so above: 18 with below: 26 is a range. at_least and at_most include the bound itself.
  • A condition uses one of the other operators at most, the first it finds in the order of the table, and then ignores any numeric ones next to it. Write a second condition in an all list to test two things.
  • The editor's operator list also offers "between" (at_least plus at_most) and "between (exclusive)" (above plus below), and fills in both bounds.
yaml
type: custom:lcards-button
id: docs-cond-range-btn
preset: lozenge
text:
  name:
    content: POWER 40 TO 80
    show: true
rules:
  # an inclusive range: 40 <= power <= 80
  - id: docs-cond-range
    when:
      entity: input_number.lcards_test_power
      at_least: 40
      at_most: 80
    apply:
      overlays:
        docs-cond-range-btn:
          style:
            card:
              color:
                background: var(--lcars-alert-yellow)
More about comparison operators
  • Numbers and text: equals and not_equals compare loosely, so equals: 25 matches the state "25". in and not_in compare exactly, and states are text: write in: ["1", "2"], not in: [1, 2].
  • Not a number: a numeric operator on a state that is not a number (unavailable, unknown) is false.
  • Regular expressions: regex is a JavaScript regular expression tested against the state; one that does not compile is false.
KeyTypeDefaultDescription
statestring / number-Equal to this. The same as equals
equalsstring / number-Equal to this (==)
not_equalsstring / number-Not equal to this (!=)
abovenumber-Greater than this (>)
at_leastnumber-Greater than or equal to this (>=)
belownumber-Less than this (<)
at_mostnumber-Less than or equal to this (<=)
inlist-One of these values, such as ["on", "idle"]
not_inlist-None of these values, such as ["off", "unavailable"]
regexstring-Matches this regular expression, such as "^heat"

entity_attr ​

entity_attr tests one attribute of an entity instead of its state, such as a light's brightness. Name the entity in entity_attr and the attribute in attribute, then add a comparison.

  • The condition editor writes the same test as entity plus attribute; both forms work.
  • The sample light here has a brightness of 200, so the rule matches.
yaml
type: custom:lcards-button
id: docs-cond-attr-btn
preset: lozenge
entity: light.demo
text:
  name:
    content: BRIGHT
    show: true
rules:
  - id: docs-cond-attr
    when:
      entity_attr: light.demo
      attribute: brightness
      above: 128
    apply:
      overlays:
        docs-cond-attr-btn:
          style:
            card:
              color:
                background: var(--lcars-alert-yellow)
KeyTypeDefaultDescription
entity_attrstringrequiredThe entity whose attribute is tested
attributestringrequiredThe attribute's name. Without it the condition is false
Comparison operatorsApplied to the attribute's value

target ​

target tests the entities you picked in Home Assistant's terms, such as every entity with a label or in an area, so the rule follows what you label in Home Assistant. Add a comparison; match says whether one entity is enough or every entity must pass.

  • target is Home Assistant's own target object, the one actions take: label_id, area_id, device_id, floor_id and entity_id, each one id or a list.
  • A label counts on the entity, on its device or on its area. An area takes the entities in it, also through their device. Hidden entities and configuration or diagnostic entities are left out unless named in entity_id, as in Home Assistant's own sections.
  • When the target includes no entity at all, the condition is false, with match: any and match: all alike.
  • The entities are found again when labels, areas or devices change in Home Assistant, and a change to any of them makes the rule check again.
  • Here the label is on the lights helper (on) and on the doors helper's device (off): with match: all the card turns red once both are on. Tap to switch the doors.
yaml
type: custom:lcards-button
id: docs-cond-target-btn
preset: lozenge
entity: input_boolean.lcards_test_doors
tap_action:
  action: toggle
text:
  name:
    content: DOORS
    show: true
rules:
  - id: docs-cond-target
    when:
      target:
        label_id: lcards_test_crew
      match: all
      state: "on"
    apply:
      overlays:
        docs-cond-target-btn:
          style:
            card:
              color:
                background: var(--lcars-alert-red)
More about target
  • Label ids: the condition uses the label's id, not its name (Low battery is low_battery). A card's editor lists its entity's labels with their ids.
  • An attribute: add attribute: <name> to compare that attribute of each entity instead of its state.
  • The editor: the condition editor's "Entities by label, area or device" type has Home Assistant's own target picker.
KeyTypeDefaultDescription
targetobjectrequiredHome Assistant's target: label_id, area_id, device_id, floor_id, entity_id (each an id or a list)
matchstringanyany: at least one entity passes. all: every entity passes
attributestring-Compare this attribute of each entity instead of its state
Comparison operatorsApplied to each entity's state (or attribute)

map_range_cond ​

map_range_cond maps an entity's numeric state from one scale onto another, then compares the mapped value. Use it when the threshold you think in is on a different scale from the raw value: a percentage of a power range, say.

  • input is the range the raw value moves over, output the range it is mapped onto, and the comparison keys sit inside map_range_cond next to them.
  • Here power (0 to 100) is mapped onto 0 to 5000 W, and the rule matches above 4000 W.
yaml
type: custom:lcards-button
id: docs-cond-map-btn
preset: lozenge
text:
  name:
    content: OVER 4000 W
    show: true
rules:
  - id: docs-cond-map
    when:
      map_range_cond:
        entity: input_number.lcards_test_power
        input: [0, 100]
        output: [0, 5000]
        above: 4000
    apply:
      overlays:
        docs-cond-map-btn:
          style:
            card:
              color:
                background: var(--lcars-alert-red)
More about map_range_cond
  • Not a number: a state that is not a number, or an input or output that is not two numbers, makes the condition false.
  • state is not an alias here: write equals to test for one mapped value.
KeyTypeDefaultDescription
entitystringrequiredThe entity whose state is mapped
input[min, max]requiredThe range of the raw value
output[min, max]requiredThe range it is mapped onto
clampbooleantrueKeep the mapped value inside output when the raw value leaves input
Comparison operatorsApplied to the mapped value; give at least one

all, any and not ​

all, any and not combine conditions: every one, at least one, or the opposite. They nest to any depth, so a rule can say "this, and one of those, but not that".

  • A bare list under when means all.
  • not takes one condition. Given a list, it is true unless every item in the list is true.
  • Here the button turns red while power is above 50, the doors are not open, and the lights are on or the mode is gamma.
yaml
type: custom:lcards-button
id: docs-cond-logic-btn
preset: lozenge
text:
  name:
    content: COMBINED
    show: true
rules:
  - id: docs-cond-logic
    when:
      all:
        # power above 50
        - entity: input_number.lcards_test_power
          above: 50
        # doors not open
        - not:
            entity: input_boolean.lcards_test_doors
            state: "on"
        # lights on, or the mode is gamma
        - any:
            - entity: input_boolean.lcards_test_lights
              state: "on"
            - entity: input_select.lcards_test_mode
              state: gamma
    apply:
      overlays:
        docs-cond-logic-btn:
          style:
            card:
              color:
                background: var(--lcars-alert-red)
KeyTypeDefaultDescription
alllist-True when every condition in the list is true (AND)
anylist-True when at least one condition in the list is true (OR)
notcondition-True when the condition inside is false (NOT)

time_between ​

time_between is true inside a time window each day, such as "22:00-06:00" for the night. A window that ends before it starts runs past midnight.

  • The rule is checked at the start of every minute, so it turns on and off on time with no entity to watch.
yaml
type: custom:lcards-button
id: docs-cond-time-btn
preset: lozenge
text:
  name:
    content: DAY SHIFT
    show: true
rules:
  - id: docs-cond-time
    when:
      time_between: "08:00-20:00"
    apply:
      overlays:
        docs-cond-time-btn:
          style:
            card:
              color:
                background: var(--lcars-blue)
More about time_between
  • Format: two-digit hours and minutes, 24-hour ("08:00-20:00", not "8:00-20:00"); any other text is false.
  • Edges: both ends count, to the minute: "08:00-20:00" is true from 08:00 through 20:00. The time is the browser's local time.
KeyTypeDefaultDescription
time_betweenstring-"HH:MM-HH:MM", start then end. Wraps past midnight when the end is earlier

weekday_in ​

weekday_in is true on the days you list, such as weekdays only. Pair it with time_between in an all list for "weekday mornings".

  • Like time_between, the rule is checked at the start of every minute, so it follows the day as it changes.
yaml
type: custom:lcards-button
id: docs-cond-weekday-btn
preset: lozenge
text:
  name:
    content: WEEKDAY
    show: true
rules:
  - id: docs-cond-weekday
    when:
      weekday_in: [mon, tue, wed, thu, fri]
    apply:
      overlays:
        docs-cond-weekday-btn:
          style:
            card:
              color:
                background: var(--lcars-blue)
KeyTypeDefaultDescription
weekday_inlist-Days from mon, tue, wed, thu, fri, sat, sun (any case). The browser's local day

sun_elevation ​

sun_elevation compares the sun's height above the horizon, in degrees, for rules that follow daylight. Below 0 the sun has set; a few degrees above it is the golden hour.

  • It takes the four numeric operators, which combine as on an entity: above: 0 with below: 8 is a band.
  • The elevation comes from Home Assistant's sun.sun entity (its elevation attribute).
yaml
type: custom:lcards-button
id: docs-cond-sun-btn
preset: lozenge
text:
  name:
    content: DAYLIGHT
    show: true
rules:
  - id: docs-cond-sun
    when:
      sun_elevation:
        above: 0
    apply:
      overlays:
        docs-cond-sun-btn:
          style:
            card:
              color:
                background: var(--lcars-yellow)
KeyTypeDefaultDescription
sun_elevation.abovenumber-The sun is higher than this, degrees
sun_elevation.at_leastnumber-The sun is at this height or higher, degrees
sun_elevation.belownumber-The sun is lower than this, degrees (0 is the horizon)
sun_elevation.at_mostnumber-The sun is at this height or lower, degrees

random_chance ​

random_chance is true with the probability you give, drawn again each time the rule is checked. Use it for alerts or accents that come and go at random.

  • 0.25 is true about one time in four; 0 is never and 1 is always.
  • The rule is checked at the start of every minute (and when an entity it names changes), and each check is a new draw.
yaml
type: custom:lcards-button
id: docs-cond-chance-btn
preset: lozenge
text:
  name:
    content: ONE IN TWO
    show: true
rules:
  - id: docs-cond-chance
    when:
      random_chance: 0.5
    apply:
      overlays:
        docs-cond-chance-btn:
          style:
            card:
              color:
                background: var(--lcars-alert-red)
KeyTypeDefaultDescription
random_chancenumber-The probability of being true, 0.0 to 1.0

Template conditions ​

For logic no built-in condition covers, write the condition as JavaScript or a Jinja2 template. condition tells the two apart by their brackets: [[[ ]]] is JavaScript, {{ }} is Jinja2.

  • A condition with neither (condition: light.desk is on) never matches, and a warning is logged in the browser console.
  • Templates covers the template syntax used elsewhere in LCARdS.

JavaScript ​

condition: "[[[ ... ]]]" runs JavaScript in the browser; the rule matches when it returns a truthy value. The code must return its result.

  • The rule is checked again when an entity read as states['domain.object'] (or hass.states['domain.object']) changes. Entities read any other way, such as a computed id, do not trigger it.
  • A YAML block (condition: |) holds longer code. javascript: (or js:) takes the same code without the brackets.
yaml
type: custom:lcards-button
id: docs-cond-js-btn
preset: lozenge
text:
  name:
    content: POWER ABOVE 80
    show: true
rules:
  - id: docs-cond-js
    when:
      condition: |
        [[[
          const power = Number(states['input_number.lcards_test_power'].state);
          return power > 80;
        ]]]
    apply:
      overlays:
        docs-cond-js-btn:
          style:
            card:
              color:
                background: var(--lcars-alert-red)
More about JavaScript conditions
  • Errors: code that throws makes the condition false; the error is logged in the browser console.
  • entity: rules are shared by every card on the page, and entity is the entity of the card that happens to check the rule, which may not be the card holding it. Read states['...'] by id instead.
KeyTypeDefaultDescription
conditionstring-JavaScript inside [[[ ]]]
javascriptstring-The same code without [[[ ]]]. js is a short name for it
entity (in the code)object-The bound entity of a card on the page, or null
hass (in the code)object-The full Home Assistant object
states (in the code)object-hass.states: every entity's state object by id

Jinja2 ​

condition: "{{ ... }}" is a Home Assistant template, rendered by Home Assistant; the rule matches when it renders true. It can use Home Assistant's own functions and filters (is_state, state_attr, float ...).

  • The rule is checked again when an entity the template reads (states('...'), is_state('...')) changes.
  • True, true, 1, yes and on count as true; False, false, 0, no, off, none and an empty result as false. Any other number is true unless it is 0, and any other text is true.
yaml
type: custom:lcards-button
id: docs-cond-jinja-btn
preset: lozenge
text:
  name:
    content: MODE GAMMA
    show: true
rules:
  - id: docs-cond-jinja
    when:
      condition: "{{ is_state('input_select.lcards_test_mode', 'gamma') }}"
    apply:
      overlays:
        docs-cond-jinja-btn:
          style:
            card:
              color:
                background: var(--lcars-alert-red)
KeyTypeDefaultDescription
conditionstring-A template inside {{ }}
jinja2string-A template, named as Jinja2 explicitly

Choosing between JS and Jinja2 ​

JavaScript is instant and runs in the browser; Jinja2 runs on Home Assistant and has its functions.

JavaScriptJinja2
Evaluated byBrowserHome Assistant server
LatencySynchronous, instantAsync round-trip
Access to Home Assistant functionsNo (use states directly)Yes (is_state, state_attr, filters ...)
Best forFast logic, math, multi-entityHome Assistant native functions, formatted values

Invalid conditions ​

A condition LCARdS does not recognise never matches, so a typo turns the rule off rather than on everywhere.

  • Unknown key (a typo such as entitty:): the condition never matches.
  • Plain-string condition: (no [[[ ]]] or {{ }}, such as condition: light.desk is on): a warning is logged in the browser console and the condition never matches. Wrap it as JavaScript or Jinja2 instead.

Released under the MIT License. | About