-
Notifications
You must be signed in to change notification settings - Fork 29
/
scene_toggle.yaml
133 lines (105 loc) · 4.24 KB
/
scene_toggle.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
blueprint:
name: Scene Toggle
description: >
## Features
- toggle through scenes by order or last activated timestamp
- define a transition time
- select scenes by area and/or include/exclude specific scenes
- timeout for beginning at start if using static order
**Help & FAQ**: [Simple Scene Toggle](https://community.home-assistant.io/t/simple-scene-toggle)
**Version**: 3.2
If you like my work and support feel free to support me.
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Q5Q3QEH52)
source_url: https://github.com/panhans/homeassistant/blob/main/blueprints/script/scene_toggle.yaml
domain: script
input:
area:
name: Name of area
description: Name of the area where you want to toggle scenes
default: ""
selector:
area:
included_scenes:
name: Included Scenes
description: Additional scenes to be included
default: []
selector:
entity:
filter:
domain: scene
multiple: true
excluded_scenes:
name: Excluded Scenes
description: Scenes to be excluded
default: []
selector:
entity:
filter:
domain: scene
multiple: true
transition:
name: Transition time
description: Transition time when switching between scenes
default: 1
selector:
number:
min: 0
max: 10
step: 0.1
unit_of_measurement: s
use_static_order:
name: "Static order"
description: "This automation is based on timestamps of the activation of the scenes. If this option is enabled a static order will be used instead of the dynamic one."
default: false
selector:
boolean:
reset_after:
name: Reset After
description: If the static order is activated, a timeout can be set after which the order is reset to the first scene. If 0 is set the timeout is disabled.
default: 0
selector:
number:
min: 0
max: 120
step: 1
unit_of_measurement: s
mode: queued
variables:
area: !input "area"
included_scenes: !input "included_scenes"
excluded_scenes: !input "excluded_scenes"
reset_after: !input "reset_after"
use_static_order: !input use_static_order
last_triggered: "{{ as_timestamp(iif(state_attr(this.entity_id,'last_triggered') == none, now(), state_attr(this.entity_id,'last_triggered'))) }}"
sequence:
- service: scene.turn_on
data_template:
transition: !input transition
entity_id: >
{% set area_scenes = states.scene | selectattr('entity_id', 'in', area_entities(area)) | map(attribute='entity_id') | list %}
{% set all_scenes = (area_scenes | reject('in', excluded_scenes) | list) + included_scenes %}
{% if use_static_order == true %}
{% set is_reset = reset_after > 0 and (as_timestamp(now()) - last_triggered >= reset_after) %}
{% if is_reset == true %}
{{ all_scenes[0] }}
{% else %}
{% set unknown_scenes = expand(all_scenes) | selectattr('state', 'eq', 'unknown') | map(attribute='entity_id') | list %}
{% set scenes_sorted_by_activation = expand(all_scenes) | sort(attribute='state', reverse = true) | map(attribute='entity_id') | reject('in', unknown_scenes) | list %}
{% set last_activated_scene = scenes_sorted_by_activation[0] %}
{% set index_of_last_activated_scene = all_scenes.index(last_activated_scene) %}
{% set new_index = index_of_last_activated_scene + 1 %}
{% if new_index == all_scenes | count %}
{{ all_scenes[0] }}
{% else %}
{{ all_scenes[new_index] }}
{% endif %}
{% endif %}
{% else %}
{% set unknown_scenes = expand(all_scenes) | selectattr('state', 'eq', 'unknown') | map(attribute='entity_id') | list %}
{% if unknown_scenes | count > 0 %}
{{ unknown_scenes[0] }}
{% else %}
{% set known_scenes = expand(all_scenes) | sort(attribute='state', reverse = false) | map(attribute='entity_id') | list %}
{{ known_scenes[0] }}
{% endif %}
{% endif %}