Advertisement
tigattack

HASS Script Next Scene in Area

Jan 1st, 2025
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.37 KB | None | 0 0
  1. alias: Next Scene in Area
  2. sequence:
  3.   - variables:
  4.       next_scene: |
  5.        {% set current_scene = states(current_scene_entity) %}
  6.         {% set scenes = expand(area_entities(scene_area))
  7.                         | selectattr('domain', 'eq', 'scene')
  8.                         | map(attribute='entity_id')
  9.                         | list | sort %}
  10.  
  11.         {% set current_index = scenes.index(current_scene)
  12.                                if current_scene in scenes
  13.                                else -1 %}
  14.  
  15.         {% set next_index = (current_index + 1) % scenes | length %}
  16.         {{ scenes[next_index] }}
  17.   - action: scene.turn_on
  18.     metadata: {}
  19.     data:
  20.       entity_id: "{{ next_scene }}"
  21.   - action: input_text.set_value
  22.     metadata: {}
  23.     target:
  24.       entity_id: "{{ current_scene_entity }}"
  25.     data:
  26.       value: "{{ next_scene }}"
  27. fields:
  28.   current_scene_entity:
  29.     selector:
  30.       entity:
  31.         filter:
  32.           domain: input_text
  33.     name: Current Scene Entity
  34.     required: true
  35.     description: Text entity to store the active scene.
  36.   scene_area:
  37.     selector:
  38.       area: {}
  39.     name: Scene Area
  40.     description: >-
  41.       Scenes must be attached to the selected area to be recognised by this
  42.       script.
  43.     required: true
  44. description: Go to the next scene (a-z) in the specified area.
  45. icon: mdi:lightbulb-multiple-outline
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement