-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlock.yaml
198 lines (175 loc) · 4.04 KB
/
lock.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
substitutions:
device_name: test-lock
entity_name: test_lock
friendly_name: test lock
device_name_wifi: testlock
esphome:
name: ${device_name}
name_add_mac_suffix: false
esp32:
board: esp32dev
logger:
api:
reboot_timeout: 50min
#encryption:
# key: !secret api_password
ota:
platform: esphome
password: !secret ota_password
safe_mode:
reboot_timeout: 50min
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: on
reboot_timeout: 50min
ap:
ssid: ${device_name_wifi}
#password: !secret wifi_ap_pass
# Example config.yaml
i2c:
sda: 21
scl: 22
scan: true
id: bus_a
as5600:
id: my_as5600
dir_pin: 23
start_position: 0deg
range: 360deg
globals:
- id: full_cycle
type: int
restore_value: yes
initial_value: '0'
- id: prev_angle
type: int
restore_value: yes
initial_value: '0'
button:
- platform: template
name: "Full Cycle Reset"
id: full_cycle_reset
on_press:
- lambda: |-
id(full_cycle) = 0;
- stepper.report_position:
id: my_stepper
position: 0
- number.set:
id: number_pos
value: 0
sensor:
- platform: as5600
update_interval: 100ms
name: Angle
id: angle
unit_of_measurement: °
accuracy_decimals: 0
icon: mdi:rotate-right
out_of_range_mode: nan
filters:
- delta: 1
- lambda:
uint16_t deg = (uint16_t)floor(x * as5600::RAW_TO_DEGREES * id(my_as5600).get_range_scale());
return deg % 360;
on_value:
then:
- lambda: |-
if ((id(prev_angle) > 310 && x < 50) || (id(prev_angle) < x) && !(id(prev_angle) < 50 && x > 310))
id(full_cycle) += (id(prev_angle) > x ? 359 - id(prev_angle) + x : x - id(prev_angle));
else if ((id(prev_angle) < 50 && x > 310) || (id(prev_angle) > x))
id(full_cycle) -= (id(prev_angle) < x ? 359 - x + id(prev_angle) : id(prev_angle) - x);
id(prev_angle) = x;
- platform: template
update_interval: 100ms
name: "Full cycle"
lambda: |-
return id(full_cycle);
# - platform: template
# update_interval: 100ms
# name: "Position MAP"
# id: position_map
# lambda: |-
# return min(9000, max(0, (int)map(id(full_cycle), 0, 2018, 0, 9000)));
- platform: template
update_interval: 100ms
name: "Position MAP"
id: position_map
lambda: |-
return 9000 - min(9000, max(0, (int)map(id(full_cycle), 0, 2018, 0, 9000)));
- platform: as5600
update_interval: 100ms
name: Position
filters:
- delta: 1
raw_position:
name: Raw Position
filters:
- delta: 1
gain:
name: Gain
filters:
- delta: 1
magnitude:
name: Magnitude
filters:
- delta: 1
status:
name: Status
filters:
- delta: 1
captive_portal:
stepper:
- platform: a4988
id: my_stepper
step_pin: GPIO15
dir_pin:
number: GPIO4
inverted: true
sleep_pin:
number: GPIO2
inverted: true
max_speed: 1550 steps/s
number:
- platform: template
name: Position stepper
optimistic: true
min_value: 0
id: number_pos
max_value: 9000
step: 1
set_action:
then:
- stepper.set_target:
id: my_stepper
target: !lambda return x;
lock:
- platform: template
name: Lock
optimistic: true
lambda: |-
if (id(position_map).state < 5)
{
return LOCK_STATE_UNLOCKED;
}
else
{
return LOCK_STATE_LOCKED;
}
lock_action:
- stepper.report_position:
id: my_stepper
position: !lambda |-
return id(position_map).state;
- stepper.set_target:
id: my_stepper
target: 9000
unlock_action:
- stepper.report_position:
id: my_stepper
position: !lambda |-
return id(position_map).state;
- stepper.set_target:
id: my_stepper
target: 0