Created
February 1, 2024 04:39
-
-
Save Didgeridrew/d4283ff227a1338fd9574fbcda9c2d00 to your computer and use it in GitHub Desktop.
HA - Randomize Options from a Select
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This was just a weird idea to randomize a list of values. | |
# Maybe it could be used for chores or activity planning? | |
alias: Random Option to calendar | |
sequence: | |
- variables: | |
option: |- | |
{% set options = state_attr('input_select.colors_warm', 'options')%} | |
{% set ns = namespace(x = options) %} | |
{% for i in range(ns.x|length- 1, 0, -1) %} | |
{% set j = range(0, i + 1)|random %} | |
{% if j !=i %} | |
{% set ns.x = ns.x[:j]+[ns.x[i]]+ns.x[j+1:i]+[ns.x[j]]+ns.x[i+1:]%} | |
{% endif %}{% endfor %}{{ ns.x }} | |
- repeat: | |
count: "{{ option|count }}" | |
sequence: | |
- service: calendar.create_event | |
data: | |
summary: "{{ option|random }}: {{ repeat.index }}" | |
start_date_time: "{{ today_at('18:00') + timedelta(days= repeat.index) }}" | |
end_date_time: "{{ today_at('19:00') + timedelta(days= repeat.index) }}" | |
target: | |
entity_id: calendar.home_assistant_events | |
mode: single |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment