-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdds666.yaml
500 lines (453 loc) · 12.5 KB
/
dds666.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
substitutions:
name: dds666
id_name: dds666
external_components_source: github://TheStaticTurtle/esphome_syslog@main
tx_pin: GPIO19
rx_pin: GPIO22
esphome:
name: ${name}
comment: "Grid meter: CHINT DDS666 modbus"
platform: ESP32
board: m5stack-atom
platformio_options:
upload_speed: 115200
external_components:
#- source: my_components
- source: github://TheStaticTurtle/esphome_syslog
components: [syslog]
logger:
#level: INFO
baud_rate: 0
wifi:
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
- ssid: !secret wifi_ssid_2
password: !secret wifi_password_2
manual_ip:
static_ip: 192.168.4.53
gateway: 192.168.2.1
subnet: 255.255.240.0
dns1: 8.8.8.8
dns2: 192.168.2.1
reboot_timeout: 15min
domain: .firtz.box
ap:
ssid: "${name}"
password: !secret ap_password
web_server:
port: 80
syslog:
ip_address: "192.168.2.32"
port: 514
strip_colors: true
api:
reboot_timeout: 0s
ota:
mqtt:
broker: 192.168.2.32
client_id: esphome_dds666
discovery_retain: false
discovery_object_id_generator: device_name
time:
- platform: homeassistant
id: homeassistant_time
light:
- platform: neopixelbus
variant: SK6812
pin: 27
num_leds: 1
type: GRB
id: status_led
name: ${name} Light
color_correct: [50%, 50%, 50%]
button:
- platform: restart
id: ${id_name}_restart_button
name: "${name} Restart"
binary_sensor:
- platform: gpio
pin:
number: 39
inverted: true
name: ${name} Button
id: ${id_name}_button
on_click:
- min_length: 200ms
max_length: 900ms
then:
- light.toggle: status_led
- min_length: 1000ms
max_length: 5000ms
then:
- button.press: ${id_name}_restart_button
#on_press:
# then:
# - light.toggle: ${id_name}_status_led
uart:
id: uart_0
baud_rate: 9600
parity: NONE
data_bits: 8
stop_bits: 1
tx_pin: ${tx_pin}
rx_pin: ${rx_pin}
rx_buffer_size: 384
# debug:
# direction: BOTH
# after:
# delimiter: "\r"
# sequence:
# - lambda: UARTDebug::log_string(direction, bytes);
modbus:
id: modbus0
uart_id: uart_0
send_wait_time: 200ms
modbus_controller:
id: dds666
modbus_id: modbus0
address: 0x1
command_throttle: 200ms
setup_priority: -10
update_interval: 30s
sensor:
- platform: modbus_controller
modbus_controller_id: dds666
name: "Voltage"
id: ${id_name}_voltage
register_type: holding
address: 0x2000
register_count: 2
unit_of_measurement: "V"
device_class: voltage
value_type: FP32
accuracy_decimals: 1
#filters:
# - multiply: 0.1
- platform: modbus_controller
modbus_controller_id: dds666
name: "Current"
id: ${id_name}_current
register_type: holding
address: 0x2002
register_count: 2
unit_of_measurement: "A"
device_class: current
value_type: FP32
accuracy_decimals: 3
- platform: modbus_controller
modbus_controller_id: dds666
name: "Active Power"
id: ${id_name}_active_power
register_type: holding
address: 0x2004
register_count: 2
unit_of_measurement: "W"
device_class: power
value_type: FP32
accuracy_decimals: 1
filters:
- multiply: 1000
on_value:
then:
#- mqtt.publish:
# topic: domoticz/in
# payload: !lambda |-
# std::string messageO;
# char str[256];
# snprintf(str, sizeof(str), "{\"idx\":25666,\"nvalue\":0,\"svalue\":\"%.2f\"}", x);
# messageO += str;
# // ESP_LOGD("domoticz/in", "%s", messageO.c_str());
# return messageO;
- mqtt.publish_json:
topic: domoticz/in
payload: |-
root["idx"] = 25666;
root["nvalue"] = 0;
root["svalue"] = to_string(id(${id_name}_active_power).state);
- platform: modbus_controller
modbus_controller_id: dds666
name: "Reactive Power"
id: ${id_name}_reactive_power
register_type: holding
address: 0x2006
register_count: 2
unit_of_measurement: "var"
device_class: reactive_power
value_type: FP32
accuracy_decimals: 1
filters:
- multiply: 1000
- platform: modbus_controller
modbus_controller_id: dds666
name: "Apparent Power"
id: ${id_name}_apparent_power
register_type: holding
address: 0x2008
register_count: 2
unit_of_measurement: "VA"
device_class: apparent_power
value_type: FP32
accuracy_decimals: 1
filters:
- multiply: 1000
- platform: modbus_controller
modbus_controller_id: dds666
name: "Power Factor"
id: ${id_name}_power_factor
register_type: holding
address: 0x200A
register_count: 2
device_class: power_factor
value_type: FP32
accuracy_decimals: 3
- platform: modbus_controller
modbus_controller_id: dds666
name: "Frequency"
id: ${id_name}_frequenzy
register_type: holding
address: 0x200E
register_count: 2
unit_of_measurement: "Hz"
device_class: frequency
value_type: FP32
accuracy_decimals: 3
- platform: modbus_controller
modbus_controller_id: dds666
name: "Total Energy"
# Current active total electric energy in forward direction
id: ${id_name}_total_energy
register_type: holding
address: 0x4000
register_count: 2
unit_of_measurement: "Wh"
device_class: energy
state_class: total_increasing
value_type: FP32
accuracy_decimals: 0
filters:
- multiply: 1000
#on_value:
# then:
# - mqtt.publish_json:
# topic: domoticz/in
# payload: |-
# root["type"] = "command";
# root["param"] = "udevice";
# root["idx"] = 26186;
# root["nvalue"] = 0;
# root["svalue"] = id(${id_name}_total_energy).state;
- platform: modbus_controller
modbus_controller_id: dds666
name: "Total Import Energy"
id: ${id_name}_imp_ep_t1
register_type: holding
address: 0x4002
register_count: 2
value_type: FP32
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 3
- platform: modbus_controller
modbus_controller_id: dds666
name: "Total Export Energy"
id: ${id_name}_exp_ep_t1
register_type: holding
address: 0x400C
register_count: 2
value_type: FP32
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 3
- platform: modbus_controller
modbus_controller_id: dds666
name: "UcodE"
id: ${id_name}_ucode
register_type: holding
address: 0x0000
register_count: 1
value_type: U_WORD
- platform: modbus_controller
modbus_controller_id: dds666
name: "Software Revision"
id: ${id_name}_revision
register_type: holding
address: 0x0001
register_count: 1
value_type: U_WORD
- platform: modbus_controller
modbus_controller_id: dds666
name: "Net"
id: ${id_name}_net
register_type: holding
address: 0x0003
register_count: 1
value_type: U_WORD
- platform: modbus_controller
modbus_controller_id: dds666
name: "Modbus Address"
id: ${id_name}_address
register_type: holding
address: 0x0006
register_count: 1
value_type: U_WORD
- platform: modbus_controller
modbus_controller_id: dds666
name: "Modbus Speed"
id: ${id_name}_baud_speed
register_type: holding
address: 0x000C
register_count: 1
value_type: U_WORD
- platform: modbus_controller
modbus_controller_id: dds666
name: "Export Energy"
#(Current) Total reverse active energy
id: ${id_name}_export_energy
register_type: holding
address: 0x400A
register_count: 2
unit_of_measurement: "Wh"
device_class: energy
state_class: total_increasing
value_type: FP32
accuracy_decimals: 0
filters:
- multiply: 1000
#- platform: modbus_controller
# modbus_controller_id: dds666
# name: "Energy Max Demand Time"
# # (Current) Total forward active energy maximum demand anc occurence time
# id: ${id_name}_imp_max_demand_time
# register_type: holding
# address: 0x5000
# register_count: 4
# value_type: U_QWORD
# accuracy_decimals: 0
#- platform: modbus_controller
# modbus_controller_id: dds666
# name: "Export Energy Max Demand Time"
# # (Current) Total reverse active energy maximum demand anc occurence time
# id: ${id_name}_exp_max_demand_time
# register_type: holding
# address: 0x5004
# register_count: 4
# value_type: U_QWORD
# accuracy_decimals: 0
- platform: wifi_signal
name: "${name} WiFi Signal"
update_interval: 60s
- platform: uptime
name: "${name} Uptime"
id: ${id_name}_uptime_sensor
update_interval: 60s
on_raw_value:
then:
- text_sensor.template.publish:
id: ${id_name}_uptime_human
state: !lambda |-
int seconds = round(id(${id_name}_uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
- platform: total_daily_energy
name: "Total Daily Energy"
power_id: ${id_name}_active_power
id: ${id_name}_total_daily_energy
method: trapezoid
state_class: total
filters:
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
unit_of_measurement: kWh
accuracy_decimals: 3
- platform: template
name: "${name} Difference Energy"
id: ${id_name}_difference_energy
#description: Import - Export energy
device_class: energy
unit_of_measurement: "kWh"
accuracy_decimals: 3
lambda: |-
if (id(${id_name}_exp_ep_t1).state >= 0 and id(${id_name}_imp_ep_t1).state >= 0) {
float export_energy = float(id(${id_name}_exp_ep_t1).state);
float import_energy = float(id(${id_name}_imp_ep_t1).state);
float diff = import_energy - export_energy;
return { diff };
} else {
return {0};
}
switch:
- platform: modbus_controller
modbus_controller_id: dds666
name: "Electric energy zero clearing clr.e"
id: ${id_name}_clre
register_type: holding
use_write_multiple: true
address: 0x002
bitmask: 1
entity_category: config
icon: "mdi:toggle-switch"
text_sensor:
- platform: version
name: "${name} ESPHome Version"
# Expose WiFi information as sensors.
- platform: wifi_info
ip_address:
name: ${name} IP
ssid:
name: ${name} SSID
bssid:
name: ${name} BSSID
mac_address:
name: ${name} MAC
scan_results:
name: ${name} Latest Scan Results
- platform: template
name: ${name} Uptime Human Readable
id: ${id_name}_uptime_human
icon: mdi:clock-start
- platform: template
name: "${name} Usage"
#description: Power + Energy usage to send to domoticz idx
lambda: |-
if (id(${id_name}_active_power).state >= 0 and id(${id_name}_total_energy).state >= 0) {
char str[20];
snprintf(str, sizeof(str), "%.2f;%.2f", id(${id_name}_active_power).state, id(${id_name}_total_energy).state);
// ESP_LOGD("text_sensor", "Creating ${name} Usage %s", str);
return { str };
} else {
// ESP_LOGD("text_sensor", "No values for usage");
return {""};
}
on_value:
then:
#- mqtt.publish:
# topic: domoticz/in
# payload: !lambda |-
# std::string messageO;
# char str[256];
# // ESP_LOGD("domoticz/in", "%s", x);
# snprintf(str, sizeof(str), "{\"idx\":26186,\"nvalue\":0,\"svalue\":\"%s\"}", x.c_str());
# // ESP_LOGD("domoticz/in", "%s", str);
# messageO += str;
# // ESP_LOGD("domoticz/in", "%s", messageO.c_str());
# return messageO;
- mqtt.publish_json:
topic: domoticz/in
payload: |-
root["idx"] = 26186;
root["nvalue"] = 0;
root["svalue"] = x;
update_interval: 60s