-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlock_32.yaml
204 lines (176 loc) · 4.74 KB
/
lock_32.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
199
200
201
202
203
204
substitutions:
device_name: test-lock32
entity_name: test_lock32
friendly_name: test lock32
device_name_wifi: testlock32
#pinout_mapping ESP32
i2c_sda_pin: GPIO21 # Пин sda для работы с шиной I2C магнитного энкодера AS560
i2c_scl_pin: GPIO22 # Пин scl для работы с шиной I2C магнитного энкодера AS560
as5600_dir_pin: GPIO23 # Пин dir магнитного энкодера AS5600
a4988_step_pin: GPIO14 # Пин step драйвера шагового двигателя a4988 (TMC2209 V3.0)
a4988_dir_pin: GPIO12 # Пин dir драйвера шагового двигателя a4988 (TMC2209 V3.0)
a4988_sleep_pin: GPIO4 # Пин sleep драйвера шагового двигателя a4988 (TMC2209 V3.0)
esphome:
name: ${device_name}
name_add_mac_suffix: false
esp32:
board: esp32dev
framework:
type: esp-idf
version: recommended
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_password
# Example config.yaml
i2c:
sda: $i2c_sda_pin
scl: $i2c_scl_pin
scan: true
id: bus_a
as5600:
id: my_as5600
dir_pin: $as5600_dir_pin
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;
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 9000 - min(9000, max(0, (int)remap(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:
number: $a4988_step_pin
# ignore_strapping_warning: true
dir_pin:
number: $a4988_dir_pin
inverted: true
sleep_pin:
number: $a4988_sleep_pin
inverted: true
# ignore_strapping_warning: true
max_speed: 2550 steps/s
number:
- platform: template
name: Position stepper
optimistic: true
min_value: 0
id: number_pos
max_value: 9000
step: 0.5
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 < 1)
{
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