-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdimswitch.yaml
More file actions
172 lines (168 loc) · 5.96 KB
/
Copy pathdimswitch.yaml
File metadata and controls
172 lines (168 loc) · 5.96 KB
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
blueprint:
name: Single button dim switch
description: >-
Switch a light on/off by pressing a button.
Dim it up/down (depending on it's current state) by holding the same button.
domain: automation
input:
button:
name: Push button
description:
Entity representing a physical push button (which restores its position
when released). It must emit a square signal on press.
selector:
entity:
domain: switch
light:
name: Light
selector:
entity:
domain: light
hold_threshold:
name: Hold threshold
description: Time to consider button is being held, instead of just pushed.
default: 0.8
selector:
number:
min: 0.05
max: 10
step: 0.05
unit_of_measurement: s
brightness_threshold:
name: Brightness threshold
description: If the light brightness is above this value,
the light is going to dim down when holding the button.
default: 130
selector:
number:
min: 0
max: 255
brightness_step_pct:
name: Brightness step
description: Percentage brightness increase/decrease in each step.
default: 20
selector:
number:
min: 1
max: 100
unit_of_measurement: "%"
transition_step_length:
name: Transition lenght
description: >-
Lenght of brightness transition in each step.
WARNING: may not be supported by all lights.
default: 0
selector:
number:
min: 0
max: 5
step: 0.01
unit_of_measurement: s
delay_step_length:
name: Delay length
description: >-
Length of pause after each step.
MUST be larger than Transition length.
default: 0.2
selector:
number:
min: 0.1
max: 5
step: 0.01
unit_of_measurement: s
mode: single
trigger:
- platform: state
entity_id: !input button
to: "on"
action:
- variables:
brightness_step_pct_positive: !input brightness_step_pct
- variables:
brightness_step_pct_negative: "{{ brightness_step_pct_positive|int * -1 }}"
light: !input light
- wait_for_trigger:
- platform: state
entity_id: !input button
to: "off"
from: "on"
timeout: !input hold_threshold
continue_on_timeout: true
- choose:
- conditions:
# when no trigger came (button has not been switched back to
# off state during timeout) = button is being held
- condition: template
value_template: "{{ wait.trigger == none }}"
sequence:
- choose:
- conditions:
# when brightness level is high
- condition: numeric_state
entity_id: !input light
attribute: brightness
above: !input brightness_threshold
sequence:
# dim down
- repeat:
while:
- condition: and
conditions:
- condition: state
entity_id: !input button
state: "on"
- condition: template
value_template: "{{ (state_attr(light, 'brightness') or 0) > 0 }}"
sequence:
- if:
- alias: If next step would not turn off the light
condition: template
value_template: "{{ (state_attr(light, 'brightness') or 0) > brightness_step_pct_positive }}"
then:
- action: light.turn_on
entity_id: !input light
data:
transition: !input transition_step_length
brightness_step_pct: "{{ brightness_step_pct_negative }}"
else:
- action: light.turn_off
entity_id: !input light
data:
transition: !input transition_step_length
- stop: Dimmed to zero
- delay: !input delay_step_length
default:
# otherwise, dim up
- repeat:
while:
- condition: and
conditions:
- condition: state
entity_id: !input button
state: "on"
- condition: template
value_template: "{{ (state_attr(light, 'brightness') or 0) < 255 }}"
sequence:
- if:
- alias: If next step would not turn the light fully on
condition: template
value_template: "{{ (state_attr(light, 'brightness') or 0) + brightness_step_pct_positive < 255 }}"
then:
- action: light.turn_on
entity_id: !input light
data:
transition: !input transition_step_length
brightness_step_pct: "{{ brightness_step_pct_positive }}"
else:
- action: light.turn_on
entity_id: !input light
data:
transition: !input transition_step_length
- stop: Dimmed to max
- delay: !input delay_step_length
# when trigger came (button has been released within timeout)
default:
- action: light.toggle
entity_id: !input light
data:
transition: !input transition_step_length