-
Notifications
You must be signed in to change notification settings - Fork 4
/
esphome-rd01.yaml
174 lines (162 loc) · 4.77 KB
/
esphome-rd01.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
substitutions:
devicename: rd01
upper_devicename: "Ai-Think RD-01"
esphome:
name: ${devicename}
comment: ${upper_devicename}
includes:
- components/rd01_uart.h
esp8266:
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# reboot_timeout: 0s
ap:
password: "admin1234"
ap_timeout: 30s
# Enable logging
logger:
baud_rate: 0
# Enable Home Assistant API
api:
ota:
uart:
id: uart_rd01
tx_pin: TX
rx_pin: RX
baud_rate: 256000
parity: NONE
stop_bits: 1
custom_component:
- lambda: |-
return {new RD01(id(uart_rd01))};
components:
- id: rd01
binary_sensor:
- platform: custom
lambda: |-
auto uart_component = static_cast<RD01 *>(rd01);
return {uart_component->hasTarget,uart_component->hasMovingTarget,uart_component->hasStillTarget,uart_component->lastCommandSuccess};
binary_sensors:
- name: "Has Target"
- name: "Has Moving Target"
- name: "Has Still Target"
- name: "Last Command Success"
sensor:
- platform: custom
lambda: |-
auto uart_component = static_cast<RD01 *>(rd01);
return {uart_component->movingTargetDistance,uart_component->movingTargetEnergy,uart_component->stillTargetDistance,uart_component->stillTargetEnergy,uart_component->detectDistance};
sensors:
- name: "Moving Target Distance"
unit_of_measurement: "cm"
accuracy_decimals: 1
- name: "Moving Target Energy"
unit_of_measurement: "%"
accuracy_decimals: 0
- name: "Still Target Distance"
unit_of_measurement: "cm"
accuracy_decimals: 1
- name: "Still Target Energy"
unit_of_measurement: "%"
accuracy_decimals: 0
- name: "Detect Distance"
unit_of_measurement: "cm"
accuracy_decimals: 1
number:
- platform: template
name: "Max Moving Distance Range"
id: maxMovingDistanceRange
min_value: 2
max_value: 8
step: 1
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<RD01 *>(rd01);
uart_component->setMaxDistancesAndNoneDuration(x,id(maxStillDistanceRange).state,id(noneDuration).state);
- platform: template
name: "Max Still Distance Range"
id: maxStillDistanceRange
min_value: 2
max_value: 8
step: 1
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<RD01 *>(rd01);
uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,x,id(noneDuration).state);
- platform: template
name: "None Duration"
id: noneDuration
min_value: 0
max_value: 65535
step: 1
mode: box
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<RD01 *>(rd01);
uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,id(maxStillDistanceRange).state,x);
- platform: template
name: "Max Moving Distance Range"
id: DistanceRange1
min_value: 0
max_value: 65535
step: 1
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<RD01 *>(rd01);
uart_component->setDistancesAndStillSensitive(x, id(DistanceRange2).state, id(StillSensitive).state);
- platform: template
name: "Max Still Distance Range"
id: DistanceRange2
min_value: 0
max_value: 65535
step: 1
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<RD01 *>(rd01);
uart_component->setDistancesAndStillSensitive(id(DistanceRange1).state, x, id(StillSensitive).state);
- platform: template
name: "Still Sensitive"
id: StillSensitive
min_value: 0
max_value: 65535
step: 1
mode: box
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<RD01 *>(rd01);
uart_component->setDistancesAndStillSensitive(id(DistanceRange1).state, id(DistanceRange2).state, x);
button:
- platform: template
name: "Turn on Engineer mode"
on_press:
- lambda: 'static_cast<RD01 *>(rd01)->setEngineeringMode(true);'
- platform: template
name: "Turn off Engineer mode"
on_press:
- lambda: 'static_cast<RD01 *>(rd01)->setEngineeringMode(false);'
- platform: template
name: "Turn on config mode"
on_press:
- lambda: 'static_cast<RD01 *>(rd01)->setConfigMode(true);'
- platform: template
name: "Turn off config mode"
on_press:
- lambda: 'static_cast<RD01 *>(rd01)->setConfigMode(false);'
- platform: template
name: "Get config"
on_press:
- lambda: 'static_cast<RD01 *>(rd01)->queryParameters();'