generated from esphome/esphome-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ezo_ec.yaml
311 lines (299 loc) · 9.02 KB
/
ezo_ec.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
substitutions:
# EC circuit, who's address is 100
addEC: "100"
update_ec: "60s"
update_button_ec: "60s"
esphome:
on_boot:
priority: 200
then:
- button.press: read_ec
- button.press: send_selected_ec
interval:
# Update Raw EC
- interval: "${update_button_ec}"
then:
- button.press: read_ec
sensor:
# EZO Circuits (yellow - SCL/RX, blue - SDA/TX)
# EZO Circuit - EC
# Conductivity
- platform: ezo
icon: mdi:shaker-outline
name: "Conductivity"
id: ec_ezo
address: ${addEC}
unit_of_measurement: "mS/cm"
accuracy_decimals: 2
update_interval: "${update_ec}"
state_class: "measurement"
filters:
- lambda:
return (x / 1000);
on_custom:
then:
- lambda:
id(raw_value_ec).publish_state(x);
on_calibration:
then:
- lambda:
id(result_ec).publish_state(x);
on_device_information:
then:
- lambda:
id(result_ec).publish_state(x);
on_slope:
then:
- lambda:
id(result_ec).publish_state(x);
on_t:
then:
- lambda:
id(result_ec).publish_state(x);
# # Conductivity
# - platform: template
# name: Conductivity
# id: sensor_conductivity
# icon: mdi:lightning-bolt-outline
# unit_of_measurement: "uS/cm"
# accuracy_decimals: 0
# update_interval: "${update_ec}"
# state_class: "measurement"
# lambda: |-
# std::string str = id(raw_value_ec).state;
# std::vector<std::string> v;
# char * token;
# char seps[] = ",";
# token = strtok (&str[0],seps);
# while (token != NULL) {
# v.push_back(token);
# token = strtok (NULL, seps);
# }
# if (v.size() == 4) {
# return std::stof(v[0]);
# }
# else {
# return NULL;
# }
# TDS
- platform: template
name: TDS
id: sensor_tds
unit_of_measurement: "g/L"
icon: mdi:water-opacity
accuracy_decimals: 2
disabled_by_default: true
update_interval: "${update_ec}"
state_class: "measurement"
lambda: |-
std::string str = id(raw_value_ec).state;
std::vector<std::string> v;
char * token;
char seps[] = ",";
token = strtok (&str[0],seps);
while (token != NULL) {
v.push_back(token);
token = strtok (NULL, seps);
}
if (v.size() == 4) {
return (std::stof(v[1]) / 1000);
}
else {
return NAN;
}
# Salinity
- platform: template
name: Salinity
id: sensor_salinity
icon: mdi:shaker-outline
unit_of_measurement: "ppt"
accuracy_decimals: 2
update_interval: "${update_ec}"
state_class: "measurement"
lambda: |-
std::string str = id(raw_value_ec).state;
std::vector<std::string> v;
char * token;
char seps[] = ",";
token = strtok (&str[0],seps);
while (token != NULL) {
v.push_back(token);
token = strtok (NULL, seps);
}
if (v.size() == 4) {
return std::stof(v[2]);
}
else {
return NAN;
}
# Specific Gravity
- platform: template
name: Specific Gravity
id: sensor_specific_gravity
icon: mdi:cup-water
unit_of_measurement: ""
accuracy_decimals: 3
update_interval: "${update_ec}"
state_class: "measurement"
lambda: |-
std::string str = id(raw_value_ec).state;
std::vector<std::string> v;
char * token;
char seps[] = ",";
token = strtok (&str[0],seps);
while (token != NULL) {
v.push_back(token);
token = strtok (NULL, seps);
}
if (v.size() == 4) {
return std::stof(v[3]);
}
else {
return NAN;
}
text_sensor:
# Conductivity Raw Value
- platform: template
name: EC - Raw Value
id: raw_value_ec
icon: mdi:counter
disabled_by_default: true
on_value:
then:
- component.update: sensor_salinity
# - component.update: sensor_conductivity
- component.update: sensor_tds
- component.update: sensor_specific_gravity
# Selected Command Result - Conductivity
- platform: template
name: EC - Command Result
icon: mdi:data-matrix
id: result_ec
disabled_by_default: true
button:
# Read Conductivity Probe
- platform: template
name: EC - Read
id: read_ec
entity_category: "Config"
disabled_by_default: true
on_press:
then:
- lambda: |-
byte error;
Wire.beginTransmission(${addEC});
error = Wire.endTransmission();
if (error == 0) {
id(ec_ezo).send_custom("R");
}
else {
ESP_LOGW("custom_conductivity_read", "No Conductivity sensor detected at address: ${addEC}!!");
}
# Send Selected EZO Command - Conductitivy
- platform: template
name: EC - Command Send Selected
id: send_selected_ec
entity_category: "Config"
disabled_by_default: true
on_press:
then:
- lambda: |-
if (id(select_command_ec).state == "Read") {
id(ec_ezo).send_custom("R");
}
if (id(select_command_ec).state == "Information") {
id(ec_ezo).get_device_information();
}
if (id(select_command_ec).state == "Status") {
id(ec_ezo).send_custom("Status");
}
if (id(select_command_ec).state == "Get Probe K Value") {
id(ec_ezo).send_custom("K,?");
}
if (id(select_command_ec).state == "Get TDS Value") {
id(ec_ezo).send_custom("TDS,?");
}
if (id(select_command_ec).state == "Get Enabled Parameter(s)") {
id(ec_ezo).send_custom("O,?");
}
if (id(select_command_ec).state == "Set Probe Type K1") {
id(ec_ezo).send_custom("K,1");
}
if (id(select_command_ec).state == "Output Units - All (Default)") {
id(ec_ezo).send_custom("O,EC,1");
id(ec_ezo).send_custom("O,TDS,1");
id(ec_ezo).send_custom("O,S,1");
id(ec_ezo).send_custom("O,SG,1");
}
if (id(select_command_ec).state == "Output Units - Conductivity") {
id(ec_ezo).send_custom("O,EC,1");
id(ec_ezo).send_custom("O,TDS,0");
id(ec_ezo).send_custom("O,S,0");
id(ec_ezo).send_custom("O,SG,0");
}
if (id(select_command_ec).state == "Salinity") {
id(ec_ezo).send_custom("O,EC,0");
id(ec_ezo).send_custom("O,TDS,0");
id(ec_ezo).send_custom("O,S,1");
id(ec_ezo).send_custom("O,SG,0");
}
if (id(select_command_ec).state == "Output Units - Specific Gravity") {
id(ec_ezo).send_custom("O,EC,0");
id(ec_ezo).send_custom("O,TDS,0");
id(ec_ezo).send_custom("O,S,0");
id(ec_ezo).send_custom("O,SG,1");
}
if (id(select_command_ec).state == "Output Units - TDS") {
id(ec_ezo).send_custom("O,EC,0");
id(ec_ezo).send_custom("O,TDS,1");
id(ec_ezo).send_custom("O,S,0");
id(ec_ezo).send_custom("O,SG,0");
}
if (id(select_command_ec).state == "Check Calibration") {
id(ec_ezo).get_calibration();
}
if (id(select_command_ec).state == "Calibrate @ 0 (WILL RESET CALIBRATION)") {
id(ec_ezo).set_calibration_point_mid(7.00);
}
if (id(select_command_ec).state == "Calibrate @ LOW = 12880 (WILL RESET CALIBRATION)") {
id(ec_ezo).set_calibration_point_low(4.00);
}
if (id(select_command_ec).state == "Calibrate @ HIGH = 80000 (WILL RESET CALIBRATION)") {
id(ec_ezo).set_calibration_point_high(10.00);
}
if (id(select_command_ec).state == "Calibrate CLEAR (WILL RESET CALIBRATION)") {
id(ec_ezo).clear_calibration();
}
else {
id(ec_ezo).send_custom("R");
}
select:
- platform: template
name: EC - Command Select
id: select_command_ec
disabled_by_default: true
optimistic: true
entity_category: "Config"
options:
- "Read"
- "Information"
- "Status"
- "Get Probe K Value"
- "Get TDS Value"
- "Get Enabled Parameter(s)"
- "Set Probe Type K1"
- "Output Units - All (Default)"
- "Output Units - Conductivity"
- "Output Units - Salinity"
- "Output Units - Specific Gravity"
- "Output Units - TDS"
- "Check Calibration"
- "Calibrate @ 0 (WILL RESET CALIBRATION)"
- "Calibrate @ LOW = 12880 (WILL RESET CALIBRATION)"
- "Calibrate @ HIGH = 80000 (WILL RESET CALIBRATION)"
- "Calibrate CLEAR (WILL RESET CALIBRATION)"
initial_option: "Check Calibration"
set_action:
- logger.log:
format: "Chosen option: %s"
args: ["x.c_str()"]