-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightswitch_stue.yaml
143 lines (128 loc) · 3.96 KB
/
lightswitch_stue.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
esphome:
name: "lightswitch_stue"
platform: ESP8266
board: d1_mini
#Used to turn off led as on_boot procedure, but is used for status pin now
# on_boot:
# priority: -100
# then:
# - output.turn_off: onboard_status_light
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: " Fallback Hotspot"
password: "nVBQR6PpuaOD"
captive_portal:
# Enable logging
logger:
api:
# Enable Home Assistant API (as part of API)
# services:
# - service: control_servo_on
# variables:
# level: float
# then:
# - servo.write:
# id: stue_on
# level: !lambda 'return level / 100.0;'
# - service: control_servo_off
# variables:
# level: float
# then:
# - servo.write:
# id: stue_off
# level: !lambda 'return level / 100.0;'
ota:
# web_server:
# port: 80
# Example configuration entry
status_led:
pin:
number: D4
inverted: True
globals: #Global variable, see on_turn_on in lights for further explaination
- id: is_last_stuelys_state_on
type: bool
restore_value: "yes"
initial_value: "false"
light:
- platform: binary
name: "Stue taklys"
id: stue_taklys
output: mock #Output is required, this output is not used
on_turn_on:
then:
- if: #Ensures that the lights havent been turned off already. Prevents scenes/automations from triggering servo when lights are already turned on
condition: #Need to use global variable since on_turn_on changes the state before this code will run
lambda: |-
if(!id(is_last_stuelys_state_on)) {
id(is_last_stuelys_state_on) = true;
return true;
}
return false;
then:
- script.stop: turn_on_power_supply_pin_for_short_duration
- script.execute: turn_on_power_supply_pin_for_short_duration
- logger.log: "Light is being turned on"
- servo.write:
id: stue_on
level: -44%
- delay: 500ms
- servo.write:
id: stue_on
level: 100%
on_turn_off:
then:
- if:
condition: #See turn on for explaination
lambda: |-
if(id(is_last_stuelys_state_on)) {
id(is_last_stuelys_state_on) = false;
return true;
}
return false;
then:
- script.stop: turn_on_power_supply_pin_for_short_duration
- script.execute: turn_on_power_supply_pin_for_short_duration
- logger.log: "Light is being turned off"
- servo.write:
id: stue_off
level: 45%
- delay: 500ms
- servo.write:
id: stue_off
level: -100%
script:
- id: turn_on_power_supply_pin_for_short_duration
then:
- output.turn_on: power_supply_pin
- delay: 1200ms
- output.turn_off: power_supply_pin
servo:
- id: stue_on
output: pwm_output_on
- id: stue_off
output: pwm_output_off
output:
- platform: esp8266_pwm
id: pwm_output_on
pin: D3 #Be careful when using other pins, some will make the ESP fail to boot.
frequency: 50 Hz
- platform: esp8266_pwm
id: pwm_output_off
pin: D2
frequency: 50 Hz
- platform: gpio #Required for light to work, not used
id: mock
pin: D5
- platform: gpio #This pin controls a relay to cut of the power to the servos
id: power_supply_pin
pin: D1 #Not all pins work for this, using D3 causes the pin to turn on during boot. D2 should also work
#Used to turn off led as on_boot procedure, but is used for status pin now
# - platform: gpio
# id: onboard_status_light
# pin:
# number: D4
# inverted: True