forked from nilsreiter/home-assistant-scenes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.yaml
208 lines (202 loc) · 6.36 KB
/
script.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
alias: Light / Hue Scene
description: >-
This script tries to replicate the Hue scenes. Colors are distributed randomly
on participating lights. Each scene currently has five different colors
represented by XY values. The script is only applied to lights that support XY
color mode.
fields:
target:
name: Target
required: true
description: Select one or more areas or light entities.
selector:
target:
entity:
domain: light
scene:
name: Scene
description: Which scene? Scenes are taken from the Hue app.
required: true
default: Savanna Sunset
selector:
select:
options:
- Savanna Sunset
- Golden Pond
- Horizon
- Frosty Dawn
- Crocus
- Tropical Twilight
- Ein bunter Garten
- Random
onlyonlights:
name: Only lights currently on?
description: If enabled, the scene is only applied to the lights currently on.
required: false
default: false
selector:
boolean: null
skipgroups:
name: Skip groups
description: If enabled, group light entities will be skipped.
required: false
default: true
selector:
boolean: null
hue_min:
name: Hue minimum value
description: >-
Only relevant when scene is "Random". Specifies the minimum hue value to
draw from.
required: false
selector:
number:
min: 0
max: 359
example: 0
hue_max:
name: Hue maximum value
description: >-
Only relevant when scene is "Random". Specifies the maximum hue value to
draw from.
required: false
selector:
number:
min: 1
max: 360
example: 360
sat_min:
name: Saturation minimum value
description: >-
Only relevant when scene is "Random". Specifies the minimum saturation
value to draw from.
required: false
selector:
number:
min: 0
max: 100
example: 99
sat_max:
required: false
name: Saturation maximum value
description: >-
Only relevant when scene is "Random". Specifies the maximum saturation
value to draw from.
selector:
number:
min: 1
max: 101
example: 101
brightness:
name: Brightness
description: If set, all lights will be specified to the given brightness percentage.
example: 50
selector:
number:
min: 1
max: 100
unit_of_measurement: "%"
sequence:
- variables:
colors: |-
{% set scenes = {
"Savanna Sunset": {
"colors": [[0.644, 0.3348],[0.5246,
0.3864],[0.4801, 0.4309],[0.5862, 0.3575],[0.4162, 0.4341]]
},
"Golden Pond": {
"colors": [[0.5695, 0.3999],[0.482,
0.4489],[0.496, 0.4424],[0.5584, 0.4083],[0.5063, 0.4474]]
},
"Horizon": {
"colors": [[0.2779, 0.2188],[0.1811,
0.1979],[0.5247, 0.3877],[0.592, 0.385],[0.1731, 0.1978]]
},
"Frosty Dawn": {
"colors": [[0.4221, 0.386],[0.387,
0.4328],[0.4013, 0.4172],[0.439, 0.3782],[0.4675, 0.3769]]
},
"Crocus": {
"colors": [[0.2877, 0.2519],[0.2194, 0.1332],[0.4212, 0.38],[0.3818, 0.485],[0.4195, 0.4216]]
},
"Tropical Twilight": {
"colors": [[0.5813, 0.3636],[0.2412, 0.1171],[0.3044, 0.1803],[0.4731, 0.3723],[0.363, 0.2716]]
},
"Ein bunter Garten": {
"colors": [[0.137, 0.053],[0.689, 0.307],[0.325093, 0.130816],[0.397, 0.161]]
},
"Color Palette #4557": {
"colors": [[0.0264,0.0368],[0.1369,0.2082],[0.6616,0.8396],[0.4481,0.2822],[0.1447,0.0799]]
},
"Random": {
"colors": []
}
}%}
# shuffle color order
{% set ns = namespace(x = scenes[scene].colors) %}
{% 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 }}
lights: |-
{% set l=[]%}
{% if target.area_id %}
{% if target.area_id is iterable and not target.area_id is string %}
{% for a in target.area_id %}
{% set l = l + area_entities(a)|select('match', 'light.')|list %}
{% endfor %}
{% else %}
{% set l = l + area_entities(target.area_id)|select('match', 'light.')|list %}
{% endif %}
{% endif %}
{% if target.entity_id %}
{% if target.entity_id is iterable and not target.entity_id is string %}
{% set l = l + (target.entity_id|list) %}
{% else %}
{% set l = l + [target.entity_id] %}
{% endif %}
{% endif %}
{% if onlyonlights|default(true) %}
{% set l = l| select('is_state', 'on')%}
{% endif %}
{% if skipgroups|default(true) %}
{% set l|from_json %}
[{%- for ll in l -%}
{%- if not state_attr(ll, "entity_id")-%}
"{{ ll }}"
{%- if not loop.last-%},{%-endif-%}
{%-endif-%}
{%- endfor -%}]
{% endset %}
{% endif %}
[{%- for ll in l %}
{%- set colormodes = state_attr(ll, "supported_color_modes") -%}
{%- if "xy" in colormodes or "rgb" in colormodes -%}
"{{ ll }}"
{%- if not loop.last-%},{%-endif-%}
{%- endif -%}
{%- endfor -%}]
- repeat:
for_each: "{{ lights }}"
sequence:
- variables:
datadict: |-
{% if scene == "Random" %}
{% set dd = { "hs_color": [
range(hue_min|default(0),hue_max|default(360))|random,
range(sat_min|default(99),sat_max|default(101))|random ] } %}
{% else %}
{% set xy = colors[repeat.index % colors|length] %}
{% set dd = {"xy_color": [xy|first, xy|last] } %}
{% endif %} {% if brightness %}
{% set bd = {"brightness_pct": brightness } %}
{% set dd = dict(dd, **bd) %}
{% endif %} {{ dd }}
- service: light.turn_on
data: "{{ datadict }}"
target:
entity_id: "{{ repeat.item }}"
mode: single