What the Current Documentation Says
The current Define variables page answers the scope question directly: it sets variables that templates in the next steps can use, so you can calculate a value once and reuse it later in the same run instead of repeating the template.
The page's own notes add the key detail. If a variable with the same name was defined earlier, Define variables changes its value, and that also works from inside another building block such as If-then. If no variable with that name existed before, it becomes available for the rest of the automation or script run. That is a per-run rule, not a promise that the value will appear anywhere else.
Why Older Answers Still Say Otherwise
Older forum posts and issue threads describe the opposite result: a value changed inside a branch seemed to stay behind. One historical example is issue #112812, reported against core-2024.3.0, where the trace showed the variable changing inside the If-then branch while a later notification still printed the earlier value. Read that as old evidence of a reported behavior, not as a current defect report.
Before you copy an old verdict, check your installed version, since a thread written for an older release may not describe your install, then read the trace of an actual run. The current documentation describes reassignment surviving the branch; do not assume a specific release such as 2026.10 introduced it, because no release boundary is verified here.
A Safe Example To Read, Not Run
The script below is a proposed illustration. It is not something we ran here, and it touches no device, helper, sensor state, or failure path.
sequence:
- variables:
count: 0
- if:
- condition: template
value_template: "{{ true }}"
then:
- variables:
count: "{{ count + 1 }}"
- action: persistent_notification.create
data:
title: "Run variable check"
message: "count after the branch: {{ count }}"The first step declares count as 0. The constant template is always true, so the If-then branch runs and reassigns count to count + 1 while still inside that branch. The final notification-only action reads the value afterward. According to the documented semantics, the notification should show 1. That expected value comes from the documentation, not from an observed run.
Expected Versus Observed: A Trace Worksheet
Fill in one row per step of your run and keep the trace alongside the table.
Home Assistant version | Step or alias | Expected | Observed |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The next table is an illustrative expected-value example only. It is not a test result and not evidence that a particular install behaves the same way.
Step | Illustrative expected value |
|---|---|
|
|
If-then with an always-true template | the then branch runs |
|
|
| the message shows |
Run Variables Are Not Helpers, Globals, or Live Subscriptions
A value created this way belongs to the run. It is not a helper entity you can watch in a dashboard, it does not become a global shared by every automation, and it is not restored on the next run. If a value must survive a restart or be shared outside the run, a helper is the durable option; this block is for a computed value used later in the same sequence.
A templated value is evaluated when its step executes. It is not a live subscription that keeps updating later steps whenever an entity changes, so do not build parallel branches that depend on a shared changing value, and do not expect a loop to accumulate results beyond what the documented steps describe.
The same sequence logic applies to Home Assistant variables in a script: the script's sequence is the run, and each step sees what earlier steps set. For an automation, the Then do section is that run. Step aliases matter here because the trace uses them as labels, as the documentation on how automations and scripts run their steps explains.
Manual Runs and Real Triggers Are Different Tests
A script runs when you start it, for example from a dashboard or with Assist. An automation runs when one of its triggers reacts. That difference matters when you verify a variable update: running the steps by hand shows that the sequence works, but it does not prove that a real trigger starts the automation.
For a run that pauses between steps, Home Assistant automation delay covers automation modes and how to read the trace. If the automation does not start at all, Home Assistant numeric state trigger not firing separates a trigger that never fires from a condition that blocks the run.
Keep the change small, keep the trace, and record expected versus observed in the worksheet. A single changed trial does not prove a cause, and a manual run is not a substitute for a real trigger.



