-
Notifications
You must be signed in to change notification settings - Fork 5
/
modbus_wallbox.yaml
787 lines (731 loc) · 24 KB
/
modbus_wallbox.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
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
# Home Assistant Sungrow wallbox integration
# https://github.com/Louisbertelsmann/Sungrow-Wallbox-Modbus-HomeAssistant
# by Louis Bertelsmann
# last update: 2024-07-24
modbus:
- name: SungrowACx
type: tcp
host: !secret wallbox_modbus_host_ip
port: !secret wallbox_modbus_port
sensors:
- name: Wallbox device type code
unique_id: wb1_dev_number_raw
slave: !secret wallbox_modbus_slave
address: 21223 # reg 21224
input_type: input
data_type: uint16
scan_interval: 600
- name: Power phases
unique_id: wb1_power_phases
slave: !secret wallbox_modbus_slave
address: 21224 # reg 21225
input_type: input
data_type: uint16
scan_interval: 600
- name: Rated voltage
unique_id: wb1_rated_voltage
slave: !secret wallbox_modbus_slave
address: 21261 # reg 21262
input_type: input
data_type: uint16
unit_of_measurement: V
device_class: Voltage
scan_interval: 600
- name: Phase switching status Raw
unique_id: wb1_phase_switching_status_raw
slave: !secret wallbox_modbus_slave
address: 21269 # reg 21270
input_type: input
data_type: uint16
scan_interval: 60
- name: Minimum charging power
unique_id: wb1_minimum_charging_power
slave: !secret wallbox_modbus_slave
address: 21271 # reg 21272
input_type: input
data_type: uint16
precision: 1
unit_of_measurement: W
device_class: Power
scale: 1
scan_interval: 60
- name: Maximum charging power
unique_id: wb1_maximum_charging_power
slave: !secret wallbox_modbus_slave
address: 21272 # reg 21273
input_type: input
data_type: uint16
precision: 1
unit_of_measurement: W
device_class: Power
scale: 1
scan_interval: 60
- name: Total energy
unique_id: wb1_total_energy
slave: !secret wallbox_modbus_slave
address: 21299 # reg 21300
input_type: input
data_type: uint32
precision: 1
unit_of_measurement: Wh
state_class: total_increasing
device_class: Energy
scale: 1
swap: word
scan_interval: 600
- name: Phase A charging voltage
unique_id: wb1_phase_a_charging_voltage
slave: !secret wallbox_modbus_slave
address: 21301 # reg 21302
input_type: input
data_type: uint16
unit_of_measurement: V
device_class: Voltage
scale: 0.1
scan_interval: 600
- name: Phase A charging current
unique_id: wb1_phase_a_charging_current
slave: !secret wallbox_modbus_slave
address: 21302 # reg 21303
input_type: input
data_type: uint16
unit_of_measurement: A
device_class: Current
state_class: measurement
scale: 0.1
scan_interval: 600
- name: Phase B charging voltage
unique_id: wb1_phase_b_charging_voltage
slave: !secret wallbox_modbus_slave
address: 21303 # reg: 21304
input_type: input
data_type: uint16
unit_of_measurement: V
device_class: Voltage
state_class: measurement
scale: 0.1
scan_interval: 600
- name: Phase B charging current
unique_id: wb1_phase_b_charging_current
slave: !secret wallbox_modbus_slave
address: 21304 # reg: 21305
input_type: input
data_type: uint16
unit_of_measurement: A
device_class: Current
state_class: measurement
scale: 0.1
scan_interval: 600
- name: Phase C charging voltage
unique_id: wb1_phase_c_charging_voltage
slave: !secret wallbox_modbus_slave
address: 21305 # reg: 21306
input_type: input
data_type: uint16
unit_of_measurement: V
device_class: Voltage
state_class: measurement
scale: 0.1
scan_interval: 600
- name: Phase C charging current
unique_id: wb1_phase_c_charging_current
slave: !secret wallbox_modbus_slave
address: 21306 # reg 21307
input_type: input
data_type: uint16
unit_of_measurement: A
device_class: Current
state_class: measurement
scale: 0.1
scan_interval: 600
- name: Charging power
unique_id: wb1_charging_power
slave: !secret wallbox_modbus_slave
address: 21307 # reg 21308
input_type: input
data_type: uint32
unit_of_measurement: W
device_class: power
state_class: measurement
swap: word
scan_interval: 600
- name: Charging energy
unique_id: wb1_charging_energy
slave: !secret wallbox_modbus_slave
address: 21309 # reg 21310
input_type: input
data_type: uint32
unit_of_measurement: Wh
device_class: Energy
scale: 1
swap: word
scan_interval: 600
- name: Charging status Raw
unique_id: wb1_charging_status
slave: !secret wallbox_modbus_slave
address: 21316 # reg 21317
input_type: input
data_type: uint16
scan_interval: 10
- name: Charging start time Raw
unique_id: wb1_charging_start_time_raw
slave: !secret wallbox_modbus_slave
address: 21317 # reg 21318
input_type: input
data_type: uint32
swap: word
scan_interval: 600
- name: Charging end time Raw
unique_id: wb1_charging_end_time_raw
slave: !secret wallbox_modbus_slave
address: 21319 # reg 21320
input_type: input
data_type: uint32
swap: word
scan_interval: 600
- name: Start mode Raw
unique_id: wb1_start_mode_raw
slave: !secret wallbox_modbus_slave
address: 21313
input_type: input
data_type: uint16
scan_interval: 600
#####################
# holding registers
#####################
- name: Output current setting
unique_id: wb1_output_current_setting
slave: !secret wallbox_modbus_slave
address: 21202 # reg 21203
input_type: holding
data_type: uint16
scale: 0.1
unit_of_measurement: A
scan_interval: 600
- name: Single phase/Three phase switching
unique_id: wb1_phase_switching
slave: !secret wallbox_modbus_slave
address: 21203 # reg 21204
input_type: holding
data_type: uint16
scan_interval: 60
- name: Charger enable raw
unique_id: wb1_charger_enable_raw
slave: !secret wallbox_modbus_slave
address: 21210 # reg 21211
input_type: holding
data_type: uint16
scan_interval: 60
- name: Remote control
unique_id: wb1_remote_control
slave: !secret wallbox_modbus_slave
address: 21211 # reg 21212
input_type: holding
data_type: uint16
scan_interval: 60
- name: Mileage per kWh
unique_id: wb1_mile_per_kwh
slave: !secret wallbox_modbus_slave
address: 21231 # reg 21232
input_type: holding
data_type: uint16
unit_of_measurement: km/kWh
precision: 1
scale: 0.1
scan_interval: 60
- name: Working mode
unique_id: wb1_working_mode
slave: !secret wallbox_modbus_slave
address: 21262 # reg 21263
input_type: holding
data_type: uint16
scan_interval: 600
template:
- sensor:
- name: Charging start time
unique_id: wb1_charging_start_time
state: >
{{ as_datetime(states.sensor.charging_start_time_raw.state).strftime("%d.%m.%Y %H:%M") }}
- name: Charging end time
unique_id: wb1_charging_end_time
state: >
{{ as_datetime(states.sensor.charging_end_time_raw.state).strftime("%d.%m.%Y %H:%M") }}
- name: Charging duration
unique_id: wb1_charging_duration
state: >
{{ as_datetime(states.sensor.charging_end_time_raw.state) - as_datetime(states.sensor.charging_start_time_raw.state) }}
- name: Charged range
unique_id: wb1_charged_range
state: >
{{ (((states.sensor.charging_energy.state | int) * (states.sensor.mileage_per_kwh.state | int) / 1000) | round(1))}} km
- name: Wallbox device type
unique_id: wb1_device_type
availability:
"{{states('sensor.wallbox_device_type_code')|is_number}}"
state: >-
{% if ((states('sensor.wallbox_device_type_code') | int(default=0)) == 0x20ED) %}
AC007-00
{% elif ((states('sensor.wallbox_device_type_code') | int(default=0)) == 0x20DA) %}
AC011E-01
{% else %}
Unknown device code!
{% endif %}
- name: Wallbox working mode
unique_id: wb1_working_mode
availability:
"{{states('sensor.working_mode')|is_number}}"
state: >-
{% if ((states('sensor.working_mode') | int(default=0)) == 0) %}
Network
{% elif ((states('sensor.working_mode') | int(default=0)) == 2) %}
Plug and Play
{% elif ((states('sensor.working_mode') | int(default=0)) == 6) %}
EMS
{% else %}
Unknown working mode!
{% endif %}
- name: Phase switching status
unique_id: wb1_phase_switching_status
availability:
"{{states('sensor.phase_switching_status_raw')|is_number}}"
state: >-
{% if ((states('sensor.phase_switching_status_raw') | int(default=0)) == 0) %}
Three phase
{% elif ((states('sensor.phase_switching_status_raw') | int(default=0)) == 1) %}
Single phase
{% else %}
Unknown phase switching status!
{% endif %}
- name: Charging status
unique_id: wb1_charging_status
availability:
"{{states('sensor.charging_status_raw')|is_number}}"
state: >-
{% if ((states('sensor.charging_status_raw') | int(default=0)) == 1) %}
Idle
{% elif ((states('sensor.charging_status_raw') | int(default=0)) == 2) %}
Standby
{% elif ((states('sensor.charging_status_raw') | int(default=0)) == 3) %}
Charging
{% elif ((states('sensor.charging_status_raw') | int(default=0)) == 4) %}
Charging is suspended (pile side)
{% elif ((states('sensor.charging_status_raw') | int(default=0)) == 5) %}
Charging is suspended (vehicle side)
{% elif ((states('sensor.charging_status_raw') | int(default=0)) == 6) %}
Charging is completed
{% elif ((states('sensor.charging_status_raw') | int(default=0)) == 7) %}
Reserved
{% elif ((states('sensor.charging_status_raw') | int(default=0)) == 8) %}
Disabled
{% elif ((states('sensor.charging_status_raw') | int(default=0)) == 9) %}
Fault
{% else %}
Unknown charging status!
{% endif %}
- name: Start mode
unique_id: wb1_start_mode
availability:
"{{states('sensor.start_mode_raw')|is_number}}"
state: >-
{% if ((states('sensor.start_mode_raw') | int(default=0)) == 0) %}
Stopped
{% elif ((states('sensor.start_mode_raw') | int(default=0)) == 1) %}
Start with EMS
{% elif ((states('sensor.start_mode_raw') | int(default=0)) == 2) %}
Start by swiping
{% else %}
Unknown start mode!
{% endif %}
- name: Charger enable
unique_id: wb1_charger_enable
availability:
"{{states('sensor.charger_enable_raw')|is_number}}"
state: >-
{% if ((states('sensor.charger_enable_raw') | int(default=0)) == 0) %}
Disabled
{% elif ((states('sensor.charger_enable_raw') | int(default=0)) == 1) %}
Enabled
{% else %}
Unknown charger enable mode!
{% endif %}
input_number:
set_wb1_output_current:
name: Set output current
min: 6
max: 63
initial: 16
step: 0.1
set_wb1_mileage_per_kwh:
name: Set mileage per kwh
min: 1
max: 500
mode: box
step: 0.1
input_select:
set_wb_phase_switch:
name: Phase switch
options:
- "Three phase"
- "Single phase"
set_wb_charger_enable:
name: Charger enable
options:
- "Disabled"
- "Enabled"
set_wb_working_mode:
name: Working mode
options:
- "Network"
- "Plug and Play"
- "EMS"
input_button:
wb_start_charging:
name: Start charging
icon: mdi:play
wb_stop_charging:
name: Stop charging
icon: mdi:stop
automation:
- id: "automation_wallbox_output_current"
alias: "wallbox output current"
description: "Sets the maximum output current of the wallbox"
trigger:
- platform: state
entity_id:
- input_number.set_wb1_output_current
condition:
- condition: template
value_template: >-
{{ states('input_number.set_wb1_output_current') | float != states('sensor.output_current_setting') | float }}
action:
- service: modbus.write_register
data_template:
hub: SungrowACx
slave: !secret wallbox_modbus_slave
address: 21202 # reg 21203
value: "{{ (states('input_number.set_wb1_output_current') | int) * 10 }}"
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.output_current_setting
mode: single
- id: "automation_wallbox_output_current_update"
alias: "wallbox output current update"
description: "Sets the maximum output current of the wallbox update"
trigger:
- platform: homeassistant
event: start
- platform: state
entity_id:
- sensor.output_current_setting
condition:
- condition: template
value_template: "{{ not is_state('sensor.output_current_setting', 'unavailable') }}"
action:
- service: input_number.set_value
target:
entity_id: input_number.set_wb1_output_current
data:
value: "{{ states('sensor.output_current_setting') }}"
mode: single
- id: "automation_mileage_per_kwh"
alias: "wallbox mileage per kwh"
description: "Sets mileage per kWh"
trigger:
- platform: state
entity_id:
- input_number.set_wb1_mileage_per_kwh
condition:
- condition: template
value_template: >-
{{ states('input_number.set_wb1_mileage_per_kwh') | float != states('sensor.mileage_per_kwh') | float }}
action:
- service: modbus.write_register
data_template:
hub: SungrowACx
slave: !secret wallbox_modbus_slave
address: 21231 # reg 21232
value: "{{ ((states('input_number.set_wb1_mileage_per_kwh') | float ) * 10) | int }}"
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.mileage_per_kwh
mode: single
- id: "automation_mileage_per_kwh_update"
alias: "wallbox mileage per kwh update"
description: "Sets mileage per kWh update"
trigger:
- platform: homeassistant
event: start
- platform: state
entity_id:
- sensor.mileage_per_kwh
condition:
- condition: template
value_template: "{{ not is_state('sensor.mileage_per_kwh', 'unavailable') }}"
action:
- service: input_number.set_value
target:
entity_id: input_number.set_wb1_mileage_per_kwh
data:
value: "{{ states('sensor.mileage_per_kwh') }}"
mode: single
- id: "automation_wallbox_change_phase_switch_cmd"
alias: "wallbox change phase switch cmd"
description: "Switch wallbox operation mode between Single- and Three-phase mode"
trigger:
- platform: state
entity_id:
- input_select.set_wb_phase_switch
condition:
- condition: template
value_template: >-
{{ states('input_select.set_wb_phase_switch') != states('sensor.phase_switching_status') }}
variables:
three_phase: 0
single_phase: 1
action:
- service: modbus.write_register
data_template:
hub: SungrowACx
slave: !secret wallbox_modbus_slave
address: 21203 # reg 21204
value: >
{% if is_state('input_select.set_wb_phase_switch', "Three phase") %}
{{three_phase}}
{% elif is_state('input_select.set_wb_phase_switch', "Single phase") %}
{{single_phase}}
{% endif %}
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.single_phase_three_phase_switching
mode: single
- id: "automation_wallbox_change_phase_switch_cmd_update"
alias: "wallbox change phase switch cmd update"
description: "Switch wallbox operation mode between Single- and Three-phase mode update"
trigger:
- platform: homeassistant
event: start
- platform: state
entity_id:
- sensor.single_phase_three_phase_switching
condition:
- condition: template
value_template: "{{ not is_state('sensor.single_phase_three_phase_switching', 'unavailable') }}"
action:
- service: input_select.select_option
target:
entity_id: input_select.set_wb_phase_switch
data:
option: "{{ states('sensor.phase_switching_status') }}"
mode: single
- id: "automation_wallbox_charger_enable_cmd"
alias: "wallbox charger enable cmd"
description: "Switch wallbox operation mode between enabled and disabled"
trigger:
- platform: state
entity_id:
- input_select.set_wb_charger_enable
condition:
- condition: template
value_template: >-
{{ states('input_select.set_wb_charger_enable') != states('sensor.charger_enable') }}
variables:
disable: 0
enable: 1
action:
- service: modbus.write_register
data_template:
hub: SungrowACx
slave: !secret wallbox_modbus_slave
address: 21210 # reg 21211
value: >
{% if is_state('input_select.set_wb_charger_enable', "Disable") %}
{{disable}}
{% elif is_state('input_select.set_wb_charger_enable', "Enable") %}
{{enable}}
{% endif %}
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.charger_enable
mode: single
- id: "automation_wallbox_charger_enable_cmd_update"
alias: "wallbox charger enable cmd update"
description: "Switch wallbox operation mode between enabled and disabled update"
trigger:
- platform: homeassistant
event: start
- platform: state
entity_id:
- sensor.charger_enable_raw
condition:
- condition: template
value_template: "{{ not is_state('sensor.charger_enable', 'unavailable') }}"
action:
- service: input_select.select_option
target:
entity_id: input_select.set_wb_charger_enable
data:
option: "{{ states('sensor.charger_enable') }}"
mode: single
- id: "automation_wallbox_start_charging"
alias: "wallbox charger start remote control cmd"
description: "Remote control wallbox"
trigger:
- platform: state
entity_id:
- input_button.wb_start_charging
condition: []
variables:
start_charging: 0
stop_charging: 1
action:
- service: modbus.write_register
data_template:
hub: SungrowACx
slave: !secret wallbox_modbus_slave
address: 21211 # reg 21212
value: >
{{start_charging}}
mode: single
- id: "automation_wallbox_stop_charging"
alias: "wallbox charger stop remote control cmd"
description: "Remote control wallbox"
trigger:
- platform: state
entity_id:
- input_button.wb_stop_charging
condition: []
variables:
start_charging: 0
stop_charging: 1
action:
- service: modbus.write_register
data_template:
hub: SungrowACx
slave: !secret wallbox_modbus_slave
address: 21211 # reg 21212
value: >
{{stop_charging}}
mode: single
- id: "automation_wallbox_set_wb_working_mode"
alias: "wallbox set working mode"
description: "Set wallbox working mode"
trigger:
- platform: state
entity_id:
- input_select.set_wb_working_mode
condition:
- condition: template
value_template: >-
{{ states('input_select.set_wb_working_mode') != states('sensor.wallbox_working_mode') }}
variables:
network: 0
plug_and_play: 2
ems: 6
action:
- service: modbus.write_register
data_template:
hub: SungrowACx
slave: !secret wallbox_modbus_slave
address: 21262 # reg 21263
value: >
{% if is_state('input_select.set_wb_working_mode', "Network") %}
{{network}}
{% elif is_state('input_select.set_wb_working_mode', "Plug and Play") %}
{{plug_and_play}}
{% elif is_state('input_select.set_wb_working_mode', "EMS") %}
{{ems}}
{% endif %}
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.working_mode
mode: single
- id: "automation_wallbox_set_wb_working_mode_update"
alias: "wallbox set working mode update"
description: "Set wallbox working mode update"
trigger:
- platform: homeassistant
event: start
- platform: state
entity_id:
- sensor.working_mode
condition:
- condition: template
value_template: "{{ not is_state('sensor.working_mode', 'unavailable') }}"
action:
- service: input_select.select_option
target:
entity_id: input_select.set_wb_working_mode
data:
option: "{{ states('sensor.wallbox_working_mode') }}"
mode: single
- id: "automation_fast_update_while_charging"
alias: automation_fast_update_while_charging
description: Update relevant entities for charging every 10sec and not just every hour
trigger:
- platform: state
entity_id:
- sensor.charging_status_raw
to: "3"
condition: []
action:
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.charging_start_time_raw
- repeat:
sequence:
- service: homeassistant.update_entity
data: {}
target:
entity_id:
- sensor.charging_power
- sensor.phase_a_charging_current
- sensor.phase_a_charging_voltage
- sensor.phase_b_charging_current
- sensor.phase_b_charging_voltage
- sensor.phase_c_charging_current
- sensor.phase_c_charging_voltage
- sensor.output_current_setting
- sensor.charging_energy
- sensor.charging_end_time_raw
- sensor.total_energy
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
while:
- condition: state
entity_id: sensor.charging_status_raw
state: "3"
mode: single