Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias: Loop Scenes in Area
- sequence:
- - variables:
- scene_info: |
- {# Define current scene and list of scenes #}
- {% set current_scene = states(current_scene_entity) %}
- {% set scenes = expand(area_entities(scene_area))
- | selectattr('domain', 'eq', 'scene')
- | map(attribute='entity_id')
- | list | sort %}
- {# Find the index of the current scene in the list of scenes #}
- {% set current_index = scenes.index(current_scene)
- if current_scene in scenes
- else -1 %}
- {# Retrieve the current direction (1 for forward, -1 for reverse) #}
- {% set current_direction = states(scene_direction_entity) | int %}
- {# Calculate the next index based on direction #}
- {% set next_index = current_index + current_direction %}
- {# Reverse direction if at the beginning or end of the list #}
- {% if next_index >= scenes | length %}
- {% set next_index = scenes | length - 2 %}
- {% set current_direction = -1 %}
- {% elif next_index < 0 %}
- {% set next_index = 1 %}
- {% set current_direction = 1 %}
- {% endif %}
- {# Output the next scene entity ID #}
- {{ {
- 'next_scene': scenes[next_index],
- 'direction': current_direction,
- } }}
- - action: scene.turn_on
- metadata: {}
- data:
- entity_id: "{{ scene_info['next_scene'] }}"
- - action: input_text.set_value
- metadata: {}
- target:
- entity_id: "{{ current_scene_entity }}"
- data:
- value: "{{ scene_info['next_scene'] }}"
- - action: input_number.set_value
- metadata: {}
- target:
- entity_id: "{{ scene_direction_entity }}"
- data:
- value: "{{ scene_info['direction'] | float }}"
- fields:
- current_scene_entity:
- selector:
- entity:
- filter:
- domain: input_text
- name: Current Scene Entity
- required: true
- description: Text entity to store the active scene.
- scene_area:
- selector:
- area: {}
- name: Scene Area
- description: >-
- Scenes must be attached to the selected area to be recognised by this
- script.
- required: true
- scene_direction_entity:
- selector:
- entity:
- filter:
- domain: input_number
- name: Scene Direction Entity
- description: Number entity to store the state of direction (-1/1).
- required: true
- description: Loop through scenes (a-z then back through z-a) in the specified area.
- icon: mdi:lightbulb-multiple-outline
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement