-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPZEM_004T_for_udp.yaml
552 lines (373 loc) · 11.8 KB
/
PZEM_004T_for_udp.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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
modbus:
- type: udp
host: 192.168.8.143
port: 9000
name: "peacefair_PZEM_004T"
close_comm_on_error: false
#delay: 0
#message_wait_milliseconds: 30
retries: 3
retry_on_empty: false #Tcp为true udp为false
timeout: 60
sensors:
- name: "PZEM 004T Voltage [V]"
unique_id: pzem_004t_voltage_v
device_class: voltage
unit_of_measurement: V
state_class: measurement
slave: 1
address: 0
input_type: input
scale: 0.1
offset: 0
precision: 1
data_type: uint16
- name: "PZEM 004T Current [A]"
unique_id: pzem_004t_current_a
unit_of_measurement: A
state_class: measurement
device_class: current
slave: 1
address: 1
input_type: input
scale: 0.001
offset: 0
precision: 3
data_type: uint16
- name: "PZEM 004T Power [W]"
unique_id: pzem_004t_power_w
unit_of_measurement: W
state_class: measurement
device_class: power
slave: 1
address: 3
input_type: input
scale: 0.1
offset: 0
precision: 1
data_type: uint16
- name: "PZEM 004T Energy [Wh]"
unique_id: pzem_004t_energy_wh
unit_of_measurement: Wh
state_class: total_increasing
device_class: energy
slave: 1
address: 5
input_type: input
scale: 1
offset: 0
precision: 1
data_type: uint16
- name: "PZEM 004T Frequency [Hz]"
unique_id: pzem_004t_frequency_hz
unit_of_measurement: Hz
state_class: measurement
slave: 1
address: 7
input_type: input
scale: 0.1
offset: 0
precision: 1
data_type: uint16
- name: "PZEM 004T Power factor [PF]"
unique_id: pzem_004t_power_factor_pf
unit_of_measurement: PF
state_class: measurement
slave: 1
address: 8
input_type: input
scale: 0.01
offset: 0
precision: 2
data_type: uint16
- name: "PZEM 004T Power Alarm Value [W]"
unique_id: pzem_004t_power_alarm_value_w
unit_of_measurement: W
slave: 1
address: 1
#Input Registers - Function Code 0x04
#Holding Registers - Function Code 0x03 & 0x10
input_type: holding
scale: 1
offset: 0
precision: 0
data_type: uint16
binary_sensors:
- name: "PZEM 004T Power Alarm Status"
unique_id: pzem_004t_power_alarm_status
slave: 1
address: 9
input_type: input
input_number:
pzem_004t_box1:
name: "PZEM 004T Power Alarm Threshold [W]"
initial: 1
min: 1
# For PZEM-004T-10A use max value 2300 W,
# for PZEM-004T-100A use max value 23000 W
max: 23000
step: 1
mode: box
unit_of_measurement: W
input_button:
pzem_004t_button0:
name: "PZEM 004T Set Power Alarm"
icon: mdi:flash-triangle
pzem_004t_button1:
name: "PZEM 004T Reset Energy Consumption"
icon: mdi:reload
switch:
- platform: template
switches:
pzem_004t_turn_modbus:
unique_id: pzem_004t_turn_modbus
friendly_name: "PZEM 004T Turn Modbus"
value_template: >-
{% if states('sensor.pzem_004t_voltage_v') != 'unavailable' %}
true
{% else %}
false
{% endif %}
turn_on:
service: modbus.write_register
data:
hub: PZEM_004T_V3
slave: 1
address: 9
value: 1
turn_off:
service: modbus.write_register
data:
hub: PZEM_004T_V3
slave: 1
address: 9
value: 0
customize:
sensor.pzem_004t_energy_wh:
last_reset: '1970-01-01T00:00:00+00:00'
sensor.pzem_004t_voltage_v:
icon: mdi:flash
sensor.pzem_004t_current_a:
icon: mdi:flash-circle
sensor.pzem_004t_power_w:
icon: mdi:flash-outline
sensor.pzem_004t_energy_wh:
icon: mdi:flash-circle-outline
sensor.pzem_004t_frequency_hz:
icon: mdi:flash-circle
sensor.pzem_004t_power_factor_pf:
icon: mdi:flash-circle
sensor.pzem_004t_power_alarm_value_w:
icon: mdi:flash-circle
binary_sensor.pzem_004t_power_alarm_status:
icon: mdi:flash-alert
shell_command:
pzem_004t_reset:
command: echo '0' > /sys/class/gpio/gpio21/value
- name: hub1
type: rtuovertcp
host: 485转tcp IP地址
port: 502
sensors:
- name: 666_voltage
unit_of_measurement: V
slave: 1
address: 8192
input_type: holding
data_type: float32
count: 2
precision: 2
device_class: voltage
- name: 666_power_current
unit_of_measurement: A
slave: 1
address: 8194
data_type: float32
count: 2
precision: 2
device_class: current
- name: 666_power
unit_of_measurement: W
slave: 1
address: 8196
input_type: holding
data_type: float32
scale: 1000
count: 2
precision: 2
device_class: power
- name: 666_Freq
unit_of_measurement: Hz
slave: 1
address: 8206
input_type: holding
data_type: float32
count: 2
precision: 2
device_class: frequency
- name: 666_totalkWh
unit_of_measurement: kWh
slave: 1
address: 16384
input_type: holding
data_type: float32
count: 2
precision: 2
device_class: energy
state_class: total_increasing
modbus:
#https://community.home-assistant.io/t/assistance-with-modbus-and-pzem-004t/330723/3
- name: PZEM_004T_V3
type: serial
method: rtu
port: /dev/rfcomm0
baudrate: 9600
stopbits: 1
bytesize: 8
parity: N
timeout: 60
retries: 3
retry_on_empty: true
close_comm_on_error: false
sensors:
- name: "PZEM 004T Voltage [V]"
unique_id: pzem_004t_voltage_v
device_class: voltage
unit_of_measurement: V
state_class: measurement
slave: 1
address: 0
input_type: input
scale: 0.1
offset: 0
precision: 1
data_type: uint16
- name: "PZEM 004T Current [A]"
unique_id: pzem_004t_current_a
unit_of_measurement: A
state_class: measurement
device_class: current
slave: 1
address: 1
input_type: input
scale: 0.001
offset: 0
precision: 3
data_type: uint16
- name: "PZEM 004T Power [W]"
unique_id: pzem_004t_power_w
unit_of_measurement: W
state_class: measurement
device_class: power
slave: 1
address: 3
input_type: input
scale: 0.1
offset: 0
precision: 1
data_type: uint16
- name: "PZEM 004T Energy [Wh]"
unique_id: pzem_004t_energy_wh
unit_of_measurement: Wh
state_class: total_increasing
device_class: energy
slave: 1
address: 5
input_type: input
scale: 1
offset: 0
precision: 1
data_type: uint16
- name: "PZEM 004T Frequency [Hz]"
unique_id: pzem_004t_frequency_hz
unit_of_measurement: Hz
state_class: measurement
slave: 1
address: 7
input_type: input
scale: 0.1
offset: 0
precision: 1
data_type: uint16
- name: "PZEM 004T Power factor [PF]"
unique_id: pzem_004t_power_factor_pf
unit_of_measurement: PF
state_class: measurement
slave: 1
address: 8
input_type: input
scale: 0.01
offset: 0
precision: 2
data_type: uint16
- name: "PZEM 004T Power Alarm Value [W]"
unique_id: pzem_004t_power_alarm_value_w
unit_of_measurement: W
slave: 1
address: 1
#Input Registers - Function Code 0x04
#Holding Registers - Function Code 0x03 & 0x10
input_type: holding
scale: 1
offset: 0
precision: 0
data_type: uint16
binary_sensors:
- name: "PZEM 004T Power Alarm Status"
unique_id: pzem_004t_power_alarm_status
slave: 1
address: 9
input_type: input
input_number:
pzem_004t_box1:
name: "PZEM 004T Power Alarm Threshold [W]"
initial: 1
min: 1
#For PZEM-004T-10A use max value 2300 W,
#for PZEM -004T-100A use max value 23000 W
max: 23000
step: 1
mode: box
unit_of_measurement: W
input_button:
pzem_004t_button0:
name: "PZEM 004T Set Power Alarm"
icon: mdi:flash-triangle
pzem_004t_button1:
name: "PZEM 004T Reset Energy Consumption"
icon: mdi:reload
switch:
- platform: template
switches:
pzem_004t_turn_modbus:
unique_id: pzem_004t_turn_modbus
friendly_name: "PZEM 004T Turn Modbus"
value_template: >-
{% if states('sensor.pzem_004t_voltage_ v ') != 'unavailable' %}
on
{% else %}
off
{% endif %}
turn_on:
service: modbus.restart
data:
hub: PZEM_004T_V3
turn_off:
service: modbus.stop
data:
hub: PZEM_004T_V3
homeassistant:
name: Home
unit_system: metric
customize:
sensor.pzem_004t_energy_wh:
last_reset: '1970-01-01T00:00:00+00:00'
sensor.pzem_004t_frequency_hz:
icon: mdi:current -ac
sensor.pzem_004t_power_factor_pf:
icon: mdi:angle-acute
sensor.pzem_004t_power_alarm_value_w:
icon: mdi:meter-electric
shell_command:
#https://community.home-assistant.io/t/how-to-use-pzem004t-energy -monitor-with-esphome/107083/186
send_reset_to_pzem_004t: echo -en '\x01\x42\x80\x11' > /dev/rfcomm0