Skip to content

Instantly share code, notes, and snippets.

@Ceralor
Last active May 30, 2024 02:31
Show Gist options
  • Save Ceralor/67014ca3a7ddd45d7de23404c3976202 to your computer and use it in GitHub Desktop.
Save Ceralor/67014ca3a7ddd45d7de23404c3976202 to your computer and use it in GitHub Desktop.
Area Next Scene

Area Next Scene

Simple blueprint. Select a scene and then you can call the script to move to the next most-recently called scene, alphabetically for now.

Maybe I'll change it to oldest-used.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Alternatively, you can paste the URL of this gist in when you go to Settings->Automations->Blueprints and click Import.

blueprint:
name: Area Next Scene
description: Changes to the next scene in a given area
author: Kay Ohtie
source_url: https://gist.github.com/Ceralor/67014ca3a7ddd45d7de23404c3976202
domain: script
input:
area:
name: Area
description: Area for scenes, only permits areas with scenes
selector:
area:
entity:
domain: scene
mode: single
max_exceeded: silent
sequence:
- variables:
area: !input area
next_scene: |-
{%- set scenes = states.scene|map(attribute='entity_id')|select('in',area_entities(area))|list|sort %}
{%- set ns = namespace(index=0) %}
{%- for scene in scenes %}
{%- if states(scene) > states(scenes[ns.index]) %}
{%- set ns.index = loop.index0 %}
{%- endif %}
{%- endfor %}
{%- if ns.index == scenes|length -1 -%}
{{ scenes[0] }}
{%- else -%}
{{ scenes[ns.index+1] }}
{%- endif -%}
- service: scene.turn_on
target:
entity_id: "{{ next_scene }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment