Skip to content

Commit 21ca7ad

Browse files
DubhAddale3h
authored andcommitted
Dim (and brighten) lights via a remote (home-assistant#3309)
* Dim (and brighten) lights via a remote As per chat in the Discord, these are the scripts, automations, and input_sliders to allow a light to be dimmed and brightened by holding down the down or up button on an appropriate remote. This has been extended to use input_sliders for the dim/brighten step, and for the minimum and maximum brightness levels. * Updates Replacing pointless data_templates with just data, complying with preferred formatting standards ;) * Further updates More fixes ;)
1 parent 293658a commit 21ca7ad

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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-04 22: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 light on a dimmer, 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.YOURCONTROLLER` 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.YOURCONTROLLER
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.YOURCONTROLLER
41+
action:
42+
- service: script.turn_off
43+
data:
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.YOURCONTROLLER
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.YOURCONTROLLER
70+
action:
71+
- service: script.turn_off
72+
data:
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` - smaller steps create a smoother transition. The second is the delay, smaller delays will create a faster transition.
80+
81+
To allow flexibility, we'll use an [input_slider](/components/input_slider/) for the step (at the time of writing this, it's not possible to template the delay when the delay uses milliseconds). We're also using a slider 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: 3
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: 5
103+
max: 255
104+
step: 1
105+
```
106+
107+
Now the scripts. There are 2 pairs of scripts. The first steps the light brighter, up to the maximum, and the second provides the delay between steps. These call each other until both are stopped. The second pair do 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.YOURLIGHT
117+
brightness: >-
118+
{% set current = states.light.YOURLIGHT.attributes.brightness|int %}
119+
{% set step = states.input_slider.light_step.state|int %}
120+
{% set next = current + step %}
121+
{% if next > states.input_slider.light_maximum.state|int %}
122+
{% set next = states.input_slider.light_maximum.state|int %}
123+
{% endif %}
124+
{{ next }}
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: 5
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.YOURLIGHT
143+
brightness: >-
144+
{% set current = states.light.YOURLIGHT.attributes.brightness|int %}
145+
{% set step = states.input_slider.light_step.state|int %}
146+
{% set next = current - step %}
147+
{% if next < states.input_slider.light_minimum.state|int %}
148+
{% set next = states.input_slider.light_minimum.state|int %}
149+
{% endif %}
150+
{{ next }}
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: 5
160+
- service: script.turn_on
161+
data:
162+
entity_id: script.light_dim
163+
```
164+

0 commit comments

Comments
 (0)