mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-23 01:06:52 +00:00
Clarify scripts example for scope of variables (#24336)
This commit is contained in:
parent
9bb113d65f
commit
f42664e3ad
@ -95,7 +95,7 @@ Variables can be templated.
|
|||||||
|
|
||||||
Variables have local scope. This means that if a variable is changed in a nested sequence block, that change will not be visible in an outer sequence block.
|
Variables have local scope. This means that if a variable is changed in a nested sequence block, that change will not be visible in an outer sequence block.
|
||||||
|
|
||||||
The following example will always say "There are 0 people home". Inside the `if` sequence the `variables` action will only alter the `people` variable for that sequence.
|
Inside the `if` sequence the `variables` action will only alter the `people` variable for that sequence.
|
||||||
|
|
||||||
{% raw %}
|
{% raw %}
|
||||||
|
|
||||||
@ -114,11 +114,13 @@ sequence:
|
|||||||
- variables:
|
- variables:
|
||||||
people: "{{ people + 1 }}"
|
people: "{{ people + 1 }}"
|
||||||
# At this scope, people will now be 1 ...
|
# At this scope, people will now be 1 ...
|
||||||
|
- service: notify.notify
|
||||||
|
data:
|
||||||
|
message: "There are {{ people }} people home" # "There are 1 people home"
|
||||||
# ... but at this scope it will still be 0
|
# ... but at this scope it will still be 0
|
||||||
# Announce the count of people home
|
|
||||||
- service: notify.notify
|
- service: notify.notify
|
||||||
data:
|
data:
|
||||||
message: "There are {{ people }} people home"
|
message: "There are {{ people }} people home" # "There are 0 people home"
|
||||||
```
|
```
|
||||||
|
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user