mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-16 22:06:50 +00:00
Add template function: shuffle (#37864)
* Add template function: shuffle * Use 'reproducible' instead * tiny tweak --------- Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com>
This commit is contained in:
parent
c231846cab
commit
f872e128a3
@ -1185,6 +1185,28 @@ See: [Python regular expression operations](https://docs.python.org/3/library/re
|
|||||||
- Filter `value | regex_findall(find='', ignorecase=False)` will find all regex matches of the find expression in `value` and return the array of matches.
|
- Filter `value | regex_findall(find='', ignorecase=False)` will find all regex matches of the find expression in `value` and return the array of matches.
|
||||||
- Filter `value | regex_findall_index(find='', index=0, ignorecase=False)` will do the same as `regex_findall` and return the match at index.
|
- Filter `value | regex_findall_index(find='', index=0, ignorecase=False)` will do the same as `regex_findall` and return the match at index.
|
||||||
|
|
||||||
|
### Shuffling
|
||||||
|
|
||||||
|
The template engine contains a filter and function to shuffle a list.
|
||||||
|
|
||||||
|
Shuffling can happen randomly or reproducibly using a seed. When using a seed
|
||||||
|
it will always return the same shuffled list for the same seed.
|
||||||
|
|
||||||
|
Some examples:
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
|
||||||
|
- `{{ [1, 2, 3] | shuffle }}` - renders as `[3, 1, 2]` (_random_)
|
||||||
|
- `{{ shuffle([1, 2, 3]) }}` - renders as `[3, 1, 2]` (_random_)
|
||||||
|
- `{{ shuffle(1, 2, 3) }}` - renders as `[3, 1, 2]` (_random_)
|
||||||
|
|
||||||
|
- `{{ [1, 2, 3] | shuffle("random seed") }}` - renders as `[2, 3, 1] (_reproducible_)
|
||||||
|
- `{{ shuffle([1, 2, 3], seed="random seed") }}` - renders as `[2, 3, 1] (_reproducible_)
|
||||||
|
- `{{ shuffle([1, 2, 3], "random seed") }}`- renders as `[2, 3, 1] (_reproducible_)
|
||||||
|
- `{{ shuffle(1, 2, 3, seed="random seed") }}` - renders as `[2, 3, 1] (_reproducible_)
|
||||||
|
|
||||||
|
{% endraw %}
|
||||||
|
|
||||||
## Merge action responses
|
## Merge action responses
|
||||||
|
|
||||||
Using action responses we can collect information from various entities at the same time.
|
Using action responses we can collect information from various entities at the same time.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user