Skip to content

Commit d53a51f

Browse files
DubhAddale3h
authored andcommitted
Dim (and brighten) lights via a remote (home-assistant#3319)
* Dim (and brighten) lights via a remote Hopefully this one won't break everything ;) * Changes as requested * Updates Other than the last point, done. The last part I've left, as these aren't strictly independent parts - the section after the comma is the explanation for how the "lever" works. * Updates You snuck those in while I was editing ;) * Update dim_and_brighten_lights.markdown
1 parent fa69ddb commit d53a51f

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
layout: page
3+
title: "Dim (and brighten) lights via a remote"
4+
description: "The scripts and automations to allow you to use a remote to dim and brighten a light"
5+
date: 2017-09-06 18:30
6+
sidebar: true
7+
comments: false
8+
sharing: true
9+
footer: true
10+
ha_category: Automation Examples
11+
---
12+
13+
This requires both a dimmable light, and a Z-Wave remote control that sends one scene when a button is held, and another when released. This ensures that the scripts (which follow) are stopped, avoiding the risks of a script that never ends.
14+
15+
In the following automation, replace `zwave.YOUR_REMOTE` with the actual entity ID of your controller. For the controller this was written for scene ID 13 was sent when the up button was held, and 15 when released. Similarly, scene 14 when the down button was held, and 16 when released. You'll need to use the scene IDs that are sent by your remote if different.
16+
17+
```yaml
18+
automation:
19+
20+
- alias: 'Make the lights go bright'
21+
initial_state: 'on'
22+
trigger:
23+
- platform: event
24+
event_type: zwave.scene_activated
25+
event_data:
26+
scene_id: 13
27+
entity_id: zwave.YOUR_REMOTE
28+
action:
29+
- service: script.turn_on
30+
data:
31+
entity_id: script.light_bright
32+
33+
- alias: 'Stop the bright just there'
34+
initial_state: 'on'
35+
trigger:
36+
- platform: event
37+
event_type: zwave.scene_activated
38+
event_data:
39+
scene_id: 15
40+
entity_id: zwave.YOUR_REMOTE
41+
action:
42+
- service: script.turn_off
43+
data_template:
44+
entity_id: script.light_bright
45+
- service: script.turn_off
46+
data:
47+
entity_id: script.light_bright_pause
48+
49+
- alias: 'Make the lights go dim'
50+
initial_state: 'on'
51+
trigger:
52+
- platform: event
53+
event_type: zwave.scene_activated
54+
event_data:
55+
scene_id: 14
56+
entity_id: zwave.YOUR_REMOTE
57+
action:
58+
- service: script.turn_on
59+
data:
60+
entity_id: script.light_dim
61+
62+
- alias: 'Stop the dim just there'
63+
initial_state: 'on'
64+
trigger:
65+
- platform: event
66+
event_type: zwave.scene_activated
67+
event_data:
68+
scene_id: 16
69+
entity_id: zwave.YOUR_REMOTE
70+
action:
71+
- service: script.turn_off
72+
data_template:
73+
entity_id: script.light_dim
74+
- service: script.turn_off
75+
data:
76+
entity_id: script.light_dim_pause
77+
```
78+
79+
There are 2 variables that control the speed of the change for the scripts below. The first is the `step`, small steps create a smooth transition. The second is the delay, larger delays will create a slower transition.
80+
81+
To allow flexibility, an [Input Slider](/components/input_slider/) is used for the step (at the time of writing this, it's not possible to template the delay when the delay uses milliseconds). Two additional [Input Sliders](/components/input_slider/) are used to set the minimum and maximum brightness, so that it's easy to tune that (or manage it through an automation).
82+
83+
```yaml
84+
input_slider:
85+
light_step:
86+
name: 'Step the lights this much'
87+
initial: 20
88+
min: 1
89+
max: 64
90+
step: 1
91+
92+
light_minimum:
93+
name: 'No dimmer than this'
94+
initial: 5
95+
min: 1
96+
max: 255
97+
step: 1
98+
99+
light_maximum:
100+
name: 'No brighter than this'
101+
initial: 255
102+
min: 50
103+
max: 255
104+
step: 1
105+
```
106+
107+
Now the scripts. There are 2 pairs of scripts. The first steps the light brighter to the maximum and the second provides the delay. These call each other until both are stopped. The second pair does the same for dimming.
108+
109+
```yaml
110+
# Replace YOURLIGHT with the actual light entity
111+
script:
112+
light_bright:
113+
sequence:
114+
- service: light.turn_on
115+
data_template:
116+
entity_id: light.YOUR_LIGHT
117+
brightness: >-
118+
{% raw %}{% set current = states.light.YOUR_LIGHT.attributes.brightness|default(0)|int %}
119+
{% set step = states('input_slider.light_step')|int %}
120+
{% set next = current + step %}
121+
{% if next > states('input_slider.light_maximum')|int %}
122+
{% set next = states('input_slider.light_maximum')|int %}
123+
{% endif %}
124+
{{ next }}{% endraw %}
125+
126+
- service: script.turn_on
127+
data:
128+
entity_id: script.light_bright_pause
129+
130+
light_bright_pause:
131+
sequence:
132+
- delay:
133+
milliseconds: 1
134+
- service: script.turn_on
135+
data:
136+
entity_id: script.light_bright
137+
138+
light_dim:
139+
sequence:
140+
- service: light.turn_on
141+
data_template:
142+
entity_id: light.YOUR_LIGHT
143+
brightness: >-
144+
{% raw %}{% set current = states.light.YOUR_LIGHT.attributes.brightness|default(0)|int %}
145+
{% set step = states('input_slider.light_step')|int %}
146+
{% set next = current - step %}
147+
{% if next < states('input_slider.light_minimum')|int %}
148+
{% set next = states('input_slider.light_minimum')|int %}
149+
{% endif %}
150+
{{ next }}{% endraw %}
151+
152+
- service: script.turn_on
153+
data:
154+
entity_id: script.light_dim_pause
155+
156+
light_dim_pause:
157+
sequence:
158+
- delay:
159+
milliseconds: 1
160+
- service: script.turn_on
161+
data:
162+
entity_id: script.light_dim
163+
```

0 commit comments

Comments
 (0)