forked from muxa/esphome-state-machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dimmable-light-example.yaml
104 lines (98 loc) · 2.55 KB
/
dimmable-light-example.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
esphome:
name: dimmable-light-example
platform: ESP8266
board: d1_mini
logger:
level: DEBUG
external_components:
- source: components
state_machine:
- name: Light Brightness State Machine
initial_state: "OFF"
states:
- name: "OFF"
on_enter:
- light.turn_off: light1
- name: "ON"
on_enter:
- light.turn_on: light1
- EDITING
inputs:
- name: CLICK
transitions:
- ON -> OFF
- OFF -> ON
- from: EDITING
to: EDITING
on_transition: # cycle through brightness levels
- lambda: |-
auto call = id(light1).turn_on();
auto brightness = id(light1).current_values.get_brightness();
if (brightness > 0.21) {
call.set_brightness(brightness - 0.2);
} else {
call.set_brightness(1.0);
}
call.perform();
- name: HOLD
transitions:
- from: "ON"
to: EDITING
on_transition: # single flash to indicate beginning of editing
- light.turn_on:
id: light1
effect: Strobe
- delay: 0.2s
- light.turn_off: light1
- light.turn_on:
id: light1
transition_length: 100ms
- from: EDITING
to: "ON"
on_transition: # tripple flash to indicate end of editing
- light.turn_on:
id: light1
effect: Strobe
- delay: 0.6s
- light.turn_off: light1
- light.turn_on:
id: light1
transition_length: 100ms
diagram: mermaid
binary_sensor:
- platform: gpio
pin:
number: D6
mode: INPUT_PULLUP
inverted: True
name: "Button"
on_click:
min_length: 50ms
max_length: 350ms
then:
- state_machine.transition: CLICK
on_multi_click:
- timing:
- ON for at least 1.5s
then:
- state_machine.transition: HOLD
light:
- platform: monochromatic
name: "Light"
id: light1
default_transition_length: 200ms
output: led1
effects:
- strobe:
name: Strobe
colors:
- state: true
duration: 100ms
- state: false
duration: 100ms
output:
- platform: esp8266_pwm
pin:
number: D4
inverted: True
id: led1