Entity Change Triggers
The on_entity_change trigger fires an animation whenever a watched entity's state (or attribute) changes. This page covers the full set of options available for entity-based triggering.
Basic Usage
animations:
- trigger: on_entity_change
entity: binary_sensor.motion
preset: pulse
to_state: "on"If entity is omitted, the card's own entity is watched.
State Gates (from_state / to_state)
These are fire-and-forget gates — they filter when the animation starts but do not stop a looping animation once it has begun.
# Only fires when transitioning from "off" → "on"
- trigger: on_entity_change
entity: light.kitchen
from_state: "off"
to_state: "on"
preset: bounceUse to_state alone when you only care about the destination. Use from_state alone when you only care about the origin. Combine both for exact transition matching.
To stop a loop when the entity state changes, use
whileinstead.
Lifecycle Conditions (while)
while turns an animation into a lifecycle-managed loop — it starts when the condition becomes true and stops automatically when it becomes false. Requires loop: true.
# Pulse while the light is on; stop when it turns off
- trigger: on_entity_change
entity: light.kitchen
preset: pulse
loop: true
while:
state: 'on'
check_on_load: truewhile condition keys
state/not_state are used alone. The 4 numeric bound keys AND-combine when more than one is present, so a range condition is expressed by combining two of them:
| Key | Meaning |
|---|---|
state | entity value equals this string |
not_state | entity value does NOT equal this string |
above | numeric value strictly greater than threshold |
at_least | numeric value greater than or equal to threshold |
below | numeric value strictly less than threshold |
at_most | numeric value less than or equal to threshold |
# Inclusive range: play while 20 <= value <= 80
while:
at_least: 20
at_most: 80
# Exclusive range: play while 20 < value < 80
while:
above: 20
below: 80The animation editor's "Play while..." dropdown offers these as ready-made "Between (inclusive)" / "Between (exclusive)" options.
check_on_load
| Value | Behaviour |
|---|---|
true (default) | Evaluate the condition immediately when the card loads. If already met, start the animation straight away. |
false | Only react to state transitions that occur after load. |
Set check_on_load: false when you want the animation to appear reactive (responding to changes) rather than presenting its current state on page load.
Attributes
Use attribute to watch a specific entity attribute instead of the main state:
- trigger: on_entity_change
entity: light.living_room
attribute: brightness_pct # 0–100, computed from raw 0–255 brightness
while:
above: 50
preset: glow
loop: truebrightness_pct is a special computed attribute that converts the raw HA brightness value (0–255) to a 0–100 percentage for easier threshold comparisons.
The animation editor's Attribute field is a searchable dropdown listing the selected entity's actual attributes (with brightness_pct injected right after brightness), not just a free-text box — pick an entity first to populate it.
attribute applies to from_state, to_state, and while alike.
map_range with on_entity_change
Entity values can be mapped to animation parameters dynamically:
- trigger: on_entity_change
entity: sensor.wind_speed
preset: rotate
loop: true
params:
speed:
map_range:
entity: sensor.wind_speed
input: [0, 50]
output: [2000, 200] # faster rotation when windier
clamp: trueSee the Animations overview for the full map_range reference.
Examples
Alert strobe while above threshold
- trigger: on_entity_change
entity: sensor.cpu_temp
while:
above: 80
preset: strobe
loop: true
check_on_load: trueEntrance on state change, fade on return
- trigger: on_entity_change
entity: binary_sensor.front_door
to_state: "on"
preset: slide
params:
from: left
duration: 400
- trigger: on_entity_change
entity: binary_sensor.front_door
to_state: "off"
preset: fade
params:
from: 1
to: 0.6
duration: 300
loop: 1
alternate: trueBrightness-driven speed
- trigger: on_entity_change
entity: light.desk
attribute: brightness_pct
preset: pulse
loop: true
while:
above: 0
params:
max_scale:
map_range:
entity: light.desk
attribute: brightness_pct
input: [0, 100]
output: [1.02, 1.2]
clamp: trueSee Also
- Animations overview — structure, options, easing
- Preset Reference — all available presets
- Rule-based Animations — entity conditions across multiple cards via the Rules Engine