-
Notifications
You must be signed in to change notification settings - Fork 61
/
huawei_derived_sensors.yaml
962 lines (826 loc) · 41.9 KB
/
huawei_derived_sensors.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
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
#############################
#
# WLCRS - Huawei Solar Integrattion - Combine multiple inverter values
# See: https://github.com/wlcrs/huawei_solar/wiki/Connecting-to-daisy-chained-inverters
#
# Note: To use this you MUST install the Energy_Meter integration using HACS.
# See: https://github.com/zeronounours/HA-custom-component-energy-meter
#
# If your HA instance has a /homeasssistant/packages directory configured, this may be deployed by saving this text into a file
# in that location. i.e. /homeasssistant/packages/huawei_derived_sensors.yaml
#
template:
########### Start: PV Strings - Power ###########
# Inverter 1 - PV String 1 - Power. Calculated from current x voltage.
# Referred to as PV1 on the SunSynk card.
- sensor:
- name: "Inverter 1 - PV 1 Power"
unique_id: inverter_1_pv_1_power
state_class: "measurement"
device_class: power
unit_of_measurement: "W"
icon: mdi:solar-power
state: >-
{% set current_state = states('sensor.inverter_pv_1_current') %}
{% set voltage_state = states('sensor.inverter_pv_1_voltage') %}
{% if current_state not in ['unknown', 'none', 'unavailable'] and
voltage_state not in ['unknown', 'none', 'unavailable'] %}
{% set current = current_state | float(default=0) %}
{% set voltage = voltage_state | float(default=0) %}
{{ (current * voltage) | round(3) }}
{% else %}
N/A
{% endif %}
availability: >-
{{ states('sensor.inverter_pv_1_current') | is_number
and states('sensor.inverter_pv_1_voltage') | is_number }}
# Inverter 1 - PV String 2 - Power. Calculated from current x voltage.
# Referred to as PV2 on the SunSynk card.
- sensor:
- name: "Inverter 1 - PV 2 Power"
unique_id: inverter_1_pv_2_power
state_class: "measurement"
device_class: power
unit_of_measurement: "W"
icon: mdi:solar-power
state: >-
{% set current_state = states('sensor.inverter_pv_2_current') %}
{% set voltage_state = states('sensor.inverter_pv_2_voltage') %}
{% if current_state not in ['unknown', 'none', 'unavailable'] and
voltage_state not in ['unknown', 'none', 'unavailable'] %}
{% set current = current_state | float(default=0) %}
{% set voltage = voltage_state | float(default=0) %}
{{ (current * voltage) | round(3) }}
{% else %}
N/A
{% endif %}
availability: >-
{{ states('sensor.inverter_pv_2_current') | is_number
and states('sensor.inverter_pv_2_voltage') | is_number }}
# Inverter 2 - PV String 1 - Power. Calculated from current x voltage.
# Referred to as PV3 on the SunSynk card.
- sensor:
- name: "Inverter 2 - PV 1 Power"
unique_id: inverter_2_pv_1_power
state_class: "measurement"
device_class: power
unit_of_measurement: "W"
icon: mdi:solar-power
state: >-
{% set current_state = states('sensor.inverter_pv_1_current_2') %}
{% set voltage_state = states('sensor.inverter_pv_1_voltage_2') %}
{% if current_state not in ['unknown', 'none', 'unavailable'] and
voltage_state not in ['unknown', 'none', 'unavailable'] %}
{% set current = current_state | float(default=0) %}
{% set voltage = voltage_state | float(default=0) %}
{{ (current * voltage) | round(3) }}
{% else %}
N/A
{% endif %}
availability: >-
{{ states('sensor.inverter_pv_1_current_2') | is_number
and states('sensor.inverter_pv_1_voltage_2') | is_number }}
# Inverter 2 - PV String 2 - Power. Calculated from current x voltage.
# Referred to as PV2 on the SunSynk card.
- sensor:
- name: "Inverter 2 - PV 2 Power"
unique_id: inverter_2_pv_2_power
state_class: "measurement"
device_class: power
unit_of_measurement: "W"
icon: mdi:solar-power
state: >-
{% set current_state = states('sensor.inverter_pv_2_current_2') %}
{% set voltage_state = states('sensor.inverter_pv_2_voltage_2') %}
{% if current_state not in ['unknown', 'none', 'unavailable'] and
voltage_state not in ['unknown', 'none', 'unavailable'] %}
{% set current = current_state | float(default=0) %}
{% set voltage = voltage_state | float(default=0) %}
{{ (current * voltage) | round(3) }}
{% else %}
N/A
{% endif %}
availability: >-
{{ states('sensor.inverter_pv_2_current_2') | is_number
and states('sensor.inverter_pv_2_voltage_2') | is_number }}
########### Start: Inverters - Combined values for 2 inverters ###########
# Provides the combined current Active Power of both inverters, in Watts.
- sensor:
- name: "Inverters - Active Power"
unique_id: inverters_active_power
unit_of_measurement: "W"
device_class: "power"
state_class: measurement
state: >-
{% set inverter_1_active_power = states('sensor.inverter_active_power') | float(default=0) %}
{% set inverter_2_active_power = states('sensor.inverter_active_power_2') | float(default=0) %}
{% if states('sensor.inverter_active_power_2') == 'unknown' %}
{{ inverter_1_active_power }}
{% else %}
{% set count = 0 %}
{% set sum = 0 %}
{% if states('sensor.inverter_active_power') != 'unknown' %}
{% set sum = sum + inverter_1_active_power %}
{% set count = count + 1 %}
{% endif %}
{% if states('sensor.inverter_active_power_2') != 'unknown' %}
{% set sum = sum + inverter_2_active_power %}
{% set count = count + 1 %}
{% endif %}
{% if count > 0 %}
{{ sum | round(1) }}
{% else %}
N/A
{% endif %}
{% endif %}
availability: >-
{{ states('sensor.inverter_active_power') | is_number
and states('sensor.inverter_active_power_2') | is_number }}
# Provides the combined Input Power from PV string of both inverters, in Watts
- sensor:
- name: "Inverters - Input Power"
unique_id: inverters_input_power
unit_of_measurement: "W"
device_class: "power"
state_class: measurement
state: >-
{% set inverter_1_input_power = states('sensor.inverter_input_power') | float(default=0) %}
{% set inverter_2_input_power = states('sensor.inverter_input_power_2') | float(default=0) %}
{% if states('sensor.inverter_input_power_2') == 'unknown' %}
{{ inverter_1_input_power }}
{% else %}
{% set count = 0 %}
{% set sum = 0 %}
{% if states('sensor.inverter_input_power') != 'unknown' %}
{% set sum = sum + inverter_1_input_power %}
{% set count = count + 1 %}
{% endif %}
{% if states('sensor.inverter_input_power_2') != 'unknown' %}
{% set sum = sum + inverter_2_input_power %}
{% set count = count + 1 %}
{% endif %}
{% if count > 0 %}
{{ sum | round(1) }}
{% else %}
N/A
{% endif %}
{% endif %}
availability: >-
{{ states('sensor.inverter_input_power') | is_number
and states('sensor.inverter_input_power_2') | is_number }}
# Provides the combined Lifetime Yield of both inverters, in kWh.
- sensor:
- name: "Inverters - Total Yield"
unique_id: inverters_total_yield
unit_of_measurement: "kWh"
device_class: "energy"
state_class: total_increasing
state: >-
{% set inverter_1_total_yield = states('sensor.inverter_total_yield') | float(default=0) %}
{% set inverter_2_total_yield = states('sensor.inverter_total_yield_2') | float(default=0) %}
{% if states('sensor.inverter_total_yield_2') == 'unknown' %}
{{ inverter_1_total_yield }}
{% else %}
{% set count = 0 %}
{% set sum = 0 %}
{% if states('sensor.inverter_total_yield') != 'unknown' %}
{% set sum = sum + inverter_1_total_yield %}
{% set count = count + 1 %}
{% endif %}
{% if states('sensor.inverter_total_yield_2') != 'unknown' %}
{% set sum = sum + inverter_2_total_yield %}
{% set count = count + 1 %}
{% endif %}
{% if count > 0 %}
{{ sum | round(2) }}
{% else %}
N/A
{% endif %}
{% endif %}
availability: >-
{{ states('sensor.inverter_total_yield') | is_number
and states('sensor.inverter_total_yield_2') | is_number }}
# Provides the combined daily yield of both inverters, in kWh.
- sensor:
- name: "Inverters - Daily Yield"
unique_id: inverters_daily_yield
unit_of_measurement: "kWh"
device_class: "energy"
state_class: total_increasing
state: >-
{% set inverter_1_daily_yield = states('sensor.inverter_daily_yield') | float(default=0) %}
{% set inverter_2_daily_yield = states('sensor.inverter_daily_yield_2') | float(default=0) %}
{% if states('sensor.inverter_daily_yield_2') == 'unknown' %}
{{ inverter_1_daily_yield }}
{% else %}
{% set count = 0 %}
{% set sum = 0 %}
{% if states('sensor.inverter_daily_yield') != 'unknown' %}
{% set sum = sum + inverter_1_daily_yield %}
{% set count = count + 1 %}
{% endif %}
{% if states('sensor.inverter_daily_yield_2') != 'unknown' %}
{% set sum = sum + inverter_2_daily_yield %}
{% set count = count + 1 %}
{% endif %}
{% if count > 0 %}
{{ sum }}
{% else %}
N/A
{% endif %}
{% endif %}
availability: >-
{{ states('sensor.inverter_daily_yield') | is_number
and states('sensor.inverter_daily_yield_2') | is_number }}
#############################
# Provides 'Daily Solar Yield' being the yield of your solar panels, minus any efficiency losses by the inverter
# See: https://github.com/wlcrs/huawei_solar/wiki/Daily-Solar-Yield
# This version works if you have an inverter and a LUNA ESS battery attached.
# Note: Update 'inverter_rating = 6000' to the total rating of your inverter 1.
# - sensor:
# - name: "Inverter 1 - Input Power with Efficiency Loss"
# unique_id: inverter_1_input_power_with_efficiency_loss
# unit_of_measurement: "W"
# device_class: power
# state_class: measurement
# state: >-
# {% set inverter_rating = 6000 %} {# adjust this value to the rated power of your inverter(s) ie. 5000 = 5kW #}
# {% set inpower = states('sensor.inverter_input_power')|float(0) %}
# {% if inpower < (inverter_rating*0.1) %}
# {{ (inpower * 0.90) | round(2) }}
# {% elif inpower < (inverter_rating*0.2) %}
# {{ (inpower * 0.95) | round(2) }}
# {% else %}
# {{ (inpower * 0.98) | round(2) }}
# {% endif %}
# availability: >-
# {{ (states('sensor.inverter_input_power')|is_number) }}
# This version works if you have an inverter and a LUNA ESS battery attached.
# Note: Update 'inverter_rating = 120000' to the total rating of your inverter 2.
# - sensor:
# - name: "Inverter 2 - Input Power with Efficiency Loss"
# unique_id: inverter_2_input_power_with_efficiency_loss
# unit_of_measurement: "W"
# device_class: power
# state_class: measurement
# state: >-
# {% set inverter_rating = 6000 %} {# adjust this value to the rated power of your inverter(s) ie. 5000 = 5kW #}
# {% set inpower = states('sensor.inverter_input_power_2')|float(0) %}
# {% if inpower < (inverter_rating*0.1) %}
# {{ (inpower * 0.90) | round(2) }}
# {% elif inpower < (inverter_rating*0.2) %}
# {{ (inpower * 0.95) | round(2) }}
# {% else %}
# {{ (inpower * 0.98) | round(2) }}
# {% endif %}
# availability: >-
# {{ (states('sensor.inverter_input_power_2')|is_number) }}
# This versions calculations works if you have an inverter and a LUNA ESS battery attached.
# Note: Update 'inverter_rating = 120000' to the total rating of your inverter(s).
# i.e. 1 x 5KW inverter enter 5000 or 2 x 6Kw inverters enter 12000.
- sensor:
- name: "Inverters - Input Power with Efficiency Loss"
unique_id: inverters_input_power_with_efficiency_loss
unit_of_measurement: "W"
device_class: power
state_class: measurement
state: >-
{% set inverter_rating = 12000 %} {# adjust this value to the rated power of your inverter(s) #}
{% set inpower = states('sensor.inverters_input_power')|float(0) %}
{% if inpower < (inverter_rating*0.1) %}
{{ (inpower * 0.90) | round(2) }}
{% elif inpower < (inverter_rating*0.2) %}
{{ (inpower * 0.95) | round(2) }}
{% else %}
{{ (inpower * 0.98) | round(2) }}
{% endif %}
availability: >-
{{ (states('sensor.inverters_input_power') | is_number) }}
# Provides the combined status of inverter(s). If either inverter is in state unknown or an error/stop state
# then the combined state will be shown as the error/stop state. Otherwise the standby/grid connected state
# of Inverter 1 will be shown, with Inverter 2 state as a fall back.
#
- sensor:
- name: "Inverters - State"
unique_id: inverters_state
state: >-
{% set inverter_1_state = states('sensor.inverter_inverter_state') %}
{% set inverter_2_state = states('sensor.inverter_inverter_state_2') %}
{% if ['unknown', 'unavailable'] in [inverter_1_state, inverter_2_state] %}
unknown
{% elif 'shutdown' in [inverter_1_state, inverter_2_state] %}
shutdown
{% elif 'spot check' in [inverter_1_state, inverter_2_state] %}
'spot check'
{% elif 'normal stop' in [inverter_1_state, inverter_2_state] %}
'normal stop'
{% elif 'stop due to faults' in [inverter_1_state, inverter_2_state] %}
'stop due to faults'
{% elif 'stop due to power rationing' in [inverter_1_state, inverter_2_state] %}
'stop due to power rationing'
{% else %}
{{ inverter_1_state if inverter_1_state not in ['unknown', 'unavailable'] else inverter_2_state }}
{% endif %}
availability: >-
{{ (states('sensor.inverter_inverter_state') not in [ 'unknown', 'unavailable' ] )
or (states('sensor.inverter_inverter_state_2') not in [ 'unknown', 'unavailable' ]) }}
# Provides the Temperature of both inverters in °C, with the inverter with the higher temperature being displayed.
# Note: If either inverter temperature state is 'uknown', then displays the state of the other inverter.
- sensor:
- name: "Inverters - Internal Temperature"
unique_id: inverters_internal_temperature
unit_of_measurement: "°C"
device_class: "temperature"
state: >-
{% set inverter_temp_1 = states('sensor.inverter_internal_temperature') | float(default=0) %}
{% set inverter_temp_2 = states('sensor.inverter_internal_temperature_2') | float(default=0) %}
{{ max(inverter_temp_1, inverter_temp_2) | round(1) }}
availability: >-
{{ states('sensor.inverter_internal_temperature') != 'unavailable'
or states('sensor.inverter_internal_temperature_2') != 'unavailable' }}
# Provides the combined status off-grid status of both inverters. If either inverter is off-grid
# then the sensor will show this as the overall status both the combined status.
- sensor:
- name: "Inverters - Off Grid Status"
unique_id: inverters_off_grid_status
state: >-
{% set inverter_1_grid_status = states('sensor.inverter_off_grid_status') %}
{% set inverter_2_grid_status = states('sensor.inverter_off_grid_status_2') %}
{% if 'Off-grid' in [inverter_1_grid_status, inverter_2_grid_status] %}
Off-grid
{% else %}
{{ inverter_1_grid_status if inverter_1_grid_status not in ['unknown', 'unavailable'] else inverter_2_grid_status }}
{% endif %}
availability: >-
{{ (states('sensor.inverter_off_grid_status') not in [ 'unknown', 'unavailable' ] )
or (states('sensor.inverter_off_grid_status_2') not in [ 'unknown', 'unavailable' ]) }}
########### Start: Batteries - Combined values for 2 batteries ###########
#
# Note: If you do NOT have two batteries, these sensors may cause your configuration to not load, due to yaml error
# casued by the sensor.battery_<entity_name>_2 not being detected.
#
# Provides the combined avaeraged State of Capacity both batteries, as a %.
- sensor:
- name: "Batteries - State of Capacity"
unique_id: batteries_state_of_capacity
unit_of_measurement: "%"
device_class: "battery"
state_class: measurement
state: >-
{% set battery_1_soc = states('sensor.battery_state_of_capacity') |float(default=0) %}
{% set battery_2_soc = states('sensor.battery_state_of_capacity_2') |float(default=0) %}
{% if states('sensor.battery_state_of_capacity_2') == 'unknown' %}
{{ battery_1_soc }}
{% else %}
{% set count = 0 %}
{% set sum = 0 %}
{% if states('sensor.battery_state_of_capacity') != 'unknown' %}
{% set sum = sum + battery_1_soc %}
{% set count = count + 1 %}
{% endif %}
{% if states('sensor.battery_state_of_capacity_2') != 'unknown' %}
{% set sum = sum + battery_2_soc %}
{% set count = count + 1 %}
{% endif %}
{% if count > 0 %}
{{ (sum / count) }}
{% else %}
N/A
{% endif %}
{% endif %}
availability: >-
{{ states('sensor.battery_state_of_capacity') | is_number
or states('sensor.battery_state_of_capacity_2') | is_number }}
# Provides the combined daily charge of both batteries, in kWh.
- sensor:
- name: "Batteries - Day Charge"
unique_id: batteries_day_charge
unit_of_measurement: "kWh"
device_class: "energy_storage"
state: >-
{% set battery_1_day_charge = states('sensor.battery_day_charge') |float(default=0) %}
{% set battery_2_day_charge = states('sensor.battery_day_charge_2') |float(default=0) %}
{% if states('sensor.battery_day_charge_2') == 'unknown' %}
{{ battery_1_day_charge }}
{% else %}
{% set count = 0 %}
{% set sum = 0 %}
{% if states('sensor.battery_day_charge') != 'unknown' %}
{% set sum = sum + battery_1_day_charge %}
{% set count = count + 1 %}
{% endif %}
{% if states('sensor.battery_day_charge_2') != 'unknown' %}
{% set sum = sum + battery_2_day_charge %}
{% set count = count + 1 %}
{% endif %}
{% if count > 0 %}
{{ sum }}
{% else %}
N/A
{% endif %}
{% endif %}
availability: >-
{{ states('sensor.battery_day_charge') | is_number
or states('sensor.battery_day_charge_2') | is_number }}
# Provides the combined daily discharge of both batteries, in kWh.
- sensor:
- name: "Batteries - Day Discharge"
unique_id: batteries_day_discharge
unit_of_measurement: "kWh"
device_class: "energy_storage"
state: >-
{% set battery_1_day_discharge = states('sensor.battery_day_discharge') |float(default=0) %}
{% set battery_2_day_discharge = states('sensor.battery_day_discharge_2') |float(default=0) %}
{% if states('sensor.battery_day_discharge_2') == 'unknown' %}
{{ battery_1_day_discharge }}
{% else %}
{% set count = 0 %}
{% set sum = 0 %}
{% if states('sensor.battery_day_discharge') != 'unknown' %}
{% set sum = sum + battery_1_day_discharge %}
{% set count = count + 1 %}
{% endif %}
{% if states('sensor.battery_day_discharge_2') != 'unknown' %}
{% set sum = sum + battery_2_day_discharge %}
{% set count = count + 1 %}
{% endif %}
{% if count > 0 %}
{{ sum | round(2) }}
{% else %}
N/A
{% endif %}
{% endif %}
availability: >-
{{ states('sensor.battery_day_discharge') | is_number
or states('sensor.battery_day_discharge_2') | is_number }}
# Provides the combined daily Charge/Discharge of both batteries, in Watts.
- sensor:
- name: "Batteries - Charge/Discharge Power"
unique_id: batteries_charge_discharge_power
unit_of_measurement: "W"
device_class: "power"
state: >-
{% set battery_1_charge_discharge = states('sensor.battery_charge_discharge_power') |float(default=0) %}
{% set battery_2_charge_discharge = states('sensor.battery_charge_discharge_power_2') |float(default=0) %}
{% if states('sensor.battery_charge_discharge_power_2') == 'unknown' %}
{{ battery_1_charge_discharge }}
{% else %}
{% set count = 0 %}
{% set sum = 0 %}
{% if states('sensor.battery_charge_discharge_power') != 'unknown' %}
{% set sum = sum + battery_1_charge_discharge %}
{% set count = count + 1 %}
{% endif %}
{% if states('sensor.battery_charge_discharge_power_2') != 'unknown' %}
{% set sum = sum + battery_2_charge_discharge %}
{% set count = count + 1 %}
{% endif %}
{% if count > 0 %}
{{ sum }}
{% else %}
N/A
{% endif %}
{% endif %}
availability: >-
{{ states('sensor.battery_charge_discharge_power') | is_number
or states('sensor.battery_charge_discharge_power_2') | is_number }}
# Provides the combined averaged Bus Current both batteries, in Amps.
- sensor:
- name: "Batteries - Bus Current"
unique_id: batteries_bus_current
unit_of_measurement: "A"
device_class: "current"
state: >-
{% set battery_1_bus_current = states('sensor.battery_bus_current') | float(default=0) %}
{% set battery_2_bus_current = states('sensor.battery_bus_current_2') | float(default=0) %}
{% if states('sensor.battery_bus_current_2') == 'unknown' %}
{{ battery_1_bus_current | round(1) }}
{% else %}
{% set count = 0 %}
{% set sum = 0 %}
{% if states('sensor.battery_bus_current') != 'unknown' %}
{% set sum = sum + battery_1_bus_current %}
{% set count = count + 1 %}
{% endif %}
{% if states('sensor.battery_bus_current_2') != 'unknown' %}
{% set sum = sum + battery_2_bus_current %}
{% set count = count + 1 %}
{% endif %}
{% if count > 0 %}
{{ sum / count }}
{% else %}
N/A
{% endif %}
{% endif %}
availability: >-
{{ states('sensor.battery_bus_current') | is_number
or states('sensor.battery_bus_current_2') | is_number }}
# Provides the combined averaged Bus Voltage both batteries, in Volts.
- sensor:
- name: "Batteries - Bus Voltage"
unique_id: batteries_bus_voltage
unit_of_measurement: "V"
device_class: "voltage"
state: >-
{% set battery_1_bus_voltage = states('sensor.battery_bus_voltage') | float(default=0) %}
{% set battery_2_bus_voltage = states('sensor.battery_bus_voltage_2') | float(default=0) %}
{% if states('sensor.battery_bus_voltage_2') == 'unknown' %}
{{ battery_1_bus_voltage | round(1) }}
{% else %}
{% set count = 0 %}
{% set sum = 0 %}
{% if states('sensor.battery_bus_voltage') != 'unknown' %}
{% set sum = sum + battery_1_bus_voltage %}
{% set count = count + 1 %}
{% endif %}
{% if states('sensor.battery_bus_voltage_2') != 'unknown' %}
{% set sum = sum + battery_2_bus_voltage %}
{% set count = count + 1 %}
{% endif %}
{% if count > 0 %}
{{ (sum / count) | round(1) }}
{% else %}
N/A
{% endif %}
{% endif %}
availability: >-
{{ states('sensor.battery_bus_voltage') | is_number
or states('sensor.battery_bus_voltage_2') | is_number }}
# Provides the Temperature of both batteries in °C, with the battery with the higher temperature being displayed.
# Note: If either batteries temperature state is 'uknown', then displays the state of the other battery.
- sensor:
- name: "Batteries - Temperature"
unique_id: batteries_temperature
unit_of_measurement: "°C"
device_class: "temperature"
state: >-
{% set battery_temp_1 = states('sensor.battery_battery_1_temperature') | float(default=0) %}
{% set battery_temp_2 = states('sensor.battery_battery_2_temperature') | float(default=0) %}
{{ max(battery_temp_1, battery_temp_2) | round(1) }}
availability: >-
{{ states('sensor.battery_battery_1_temperature') != 'unavailable'
or states('sensor.battery_battery_1_temperature_2') != 'unavailable' }}
# Provides the combined status both batteries. If either battery is offline of faulty
# then the sensor will show this as the overall status, otherwise it will the status of the online battery.
- sensor:
- name: "Batteries - Status"
unique_id: batteries_status
state: >-
{% set battery_1_state = states('sensor.battery_status') %}
{% set battery_2_state = states('sensor.battery_status_2') %}
{% if 'offline' in [battery_1_state, battery_2_state] %}
offline
{% elif 'fault' in [battery_1_state, battery_2_state] %}
fault
{% else %}
{{ battery_1_state if battery_1_state not in ['unknown', 'unavailable'] else battery_2_state }}
{% endif %}
availability: >-
{{ (states('sensor.battery_status') not in [ 'unknown', 'unavailable' ] )
or (states('sensor.battery_status_2') not in [ 'unknown', 'unavailable' ]) }}
########### Start: Power Meter - Calculates the Active Power being consumed in the house from grid, inveters & battery ###########
# Provides the calculated current load, in Watts, of the house including power being drawn from solar, battery & grid.
- sensor:
- name: "House Consumption - Power"
unique_id: house_consumption_power
unit_of_measurement: "W"
icon: mdi:home-lightning-bolt-outline
device_class: "power"
state_class: measurement
state: >-
{% set inverters_power = states('sensor.inverters_active_power') | float(default=0) %}
{% set power_meter_power = states('sensor.power_meter_active_power') | float(default=0) %}
{{ max(0, (inverters_power - power_meter_power)) }}
availability: >-
{{ states('sensor.inverters_active_power') | is_number
and states('sensor.power_meter_active_power') | is_number }}
########### Start: Power Flows - Derive power flows between PV, Batteries, Grid and House ###########
# Calculates the Power (W) being exported from the Battery(s) to the Grid.
- sensor:
- name: Batteries - Power to Grid
unique_id: batteries_power_to_grid
unit_of_measurement: W
icon: mdi:home-export-outline
device_class: power
state_class: measurement
state: >-
{% set inverters_output = states('sensor.inverters_active_power')|int(default=0) %}
{% set battery = states('sensor.batteries_charge_discharge_power')|int(default=0) %}
{% set grid_power = states('sensor.power_meter_active_power')|int(default=0) %}
{% if grid_power > 0 and battery < 0 and inverters_output > grid_power %}
{% if grid_power - inverters_output - battery >= 0 %} {{ grid_power - inverters_output - battery }}
{% else %} 0
{% endif %}
{% else %} 0
{% endif %}
availability: >-
{{ (states('sensor.inverters_active_power') not in [ 'unknown', 'none', 'unavailable' ])
or (states('sensor.batteries_charge_discharge_power') not in [ 'unknown', 'none', 'unavailable' ])
or (states('sensor.power_meter_active_power') not in [ 'unknown', 'none', 'unavailable' ]) }}
# Calculates the Power (W) being consumed from the Battery(s) to the House.
- sensor:
- name: Batteries - Power to House
unique_id: batteries_power_to_house
device_class: power
state_class: measurement
unit_of_measurement: W
state: >-
{% set battery = states('sensor.batteries_charge_discharge_power')|int(default=0) %}
{% set to_grid = states('sensor.batteries_to_grid')|int(default=0) %}
{% if battery < 0 %} {{ to_grid - battery | int }}
{% else %} 0
{% endif %}
availability: >-
{{ (states('sensor.batteries_charge_discharge_power') not in [ 'unknown', 'none', 'unavailable' ])
or (states('sensor.batteries_to_grid') not in [ 'unknown', 'none', 'unavailable' ]) }}
# Calculates the Power (W) being consumed from the Battery(s) to the EV Charger.
- sensor:
- name: Batteries - Power to EV Charger
unique_id: batteries_power_to_ev_charger
device_class: power
state_class: measurement
unit_of_measurement: W
state: >-
{% set battery = states('sensor.batteries_charge_discharge_power')|int(default=0) %}
{% set grid_power = states('sensor.power_meter_active_power')|int(default=0) %}
{% set ev_charger = states('sensor.ev_charger_active_power')|int(default=0) %}
{% if battery < 0 and grid_power > 0 %} {{ ev_charger | int }}
{% else %} 0
{% endif %}
availability: >-
{{ (states('sensor.batteries_charge_discharge_power') not in [ 'unknown', 'none', 'unavailable' ])
or (states('sensor.power_meter_active_power') not in [ 'unknown', 'none', 'unavailable' ])
or (states('sensor.ev_charger_active_power') not in [ 'unknown', 'none', 'unavailable' ]) }}
# Calculates the Power (W) being produced by the Solar Inverter(s) and consumed by the House.
- sensor:
- name: Inverters - Solar Power to House
unique_id: inverters_solar_power_to_house
device_class: power
state_class: measurement
unit_of_measurement: W
state: >-
{% set grid_power = states('sensor.power_meter_active_power')|int(default=0) %}
{% set inverters_input = states('sensor.inverters_input_power')|int(default=0) %}
{% set inverters_output = states('sensor.inverters_active_power')|int(default=0) %}
{% set battery = states('sensor.batteries_charge_discharge_power')|int(default=0) %}
{% if inverters_output > 0 %}
{% if grid_power > 0 %}
{% if battery > 0 %} {{ inverters_output - grid_power }}
{% else %} {{ inverters_output + battery - grid_power | abs }}
{% endif %}
{% else %} 0
{% endif %}
{% else %} 0
{% endif %}
availability: >-
{{ (states('sensor.power_meter_active_power') not in [ 'unknown', 'none', 'unavailable' ])
or (states('sensor.inverters_input_power') not in [ 'unknown', 'none', 'unavailable' ])
or (states('sensor.inverters_active_power') not in [ 'unknown', 'none', 'unavailable' ])
or (states('sensor.batteries_charge_discharge_power') not in [ 'unknown', 'none', 'unavailable' ]) }}
# Calculates the Power (W) being produced by the Solar Inverter(s) and used to charge the Battery(s).
- sensor:
- name: Inverters - Solar Power to Batteries
unique_id: inverters_solar_power_to_batteries
device_class: power
state_class: measurement
unit_of_measurement: W
state: >-
{% set inverters_input = states('sensor.inverters_input_power')|int(default=0) %}
{% set battery = states('sensor.batteries_charge_discharge_power')|int(default=0) %}
{% set inverters_output = states('sensor.inverters_active_power')|int(default=0) %}
{% if battery > 0 %}
{% if inverters_output < 0 %} {{ inverters_input }}
{% else %} {{ battery }}
{% endif %}
{% else %} 0
{% endif %}
availability: >-
{{ (states('sensor.power_meter_active_power') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.inverters_active_power') not in [ 'unavailable', 'none', 'unknown' ])
and (states('sensor.ev_charger_active_power') not in [ 'unavailable', 'none', 'unknown' ]) }}
# Calculates the Power (W) being produced by the Solar Inverter(s) and Exported to the Power Grid.
- sensor:
- name: Inverters - Solar Power to Grid
unique_id: inverters_solar_power_to_grid
device_class: power
state_class: measurement
unit_of_measurement: W
state: >-
{% set grid_power = states('sensor.power_meter_active_power')|int(default=0) %}
{% set inverters_output = states('sensor.inverters_active_power')|int(default=0) %}
{% if inverters_output > 0 and grid_power > 0 %} {{ grid_power }}
{% else %} 0
{% endif %}
availability: >-
{{ (states('sensor.power_meter_active_power') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.inverters_active_power') not in [ 'unavailable', 'none', 'unknown' ]) }}
# Calculates the Power (W) being produced by the Solar Inverter(s) and used by the EV Charger.
- sensor:
- name: Inverters - Solar Power to EV Charger
unique_id: inverters_solar_power_to_ev_charger
device_class: power
state_class: measurement
unit_of_measurement: W
state: >-
{% set grid_power = states('sensor.power_meter_active_power')|int(default=0) %}
{% set inverters_output = states('sensor.inverters_active_power')|int(default=0) %}
{% set ev_charger = states('sensor.ev_charger_active_power')|int(default=0) %}
{% if inverters_output > 0 and grid_power > 0 %} {{ ev_charger }}
{% else %} 0
{% endif %}
availability: >-
{{ (states('sensor.power_meter_active_power') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.inverters_active_power') not in [ 'unavailable', 'none', 'unknown' ])
and (states('sensor.ev_charger_active_power') not in [ 'unavailable', 'none', 'unknown' ]) }}
# Calculates the Power (W) being Imported from the GRID to CHARGE the Batteries.
- sensor:
- name: Power Meter - Grid to Batteries
unique_id: power_meter_grid_to_batteries
device_class: power
state_class: measurement
unit_of_measurement: W
state: >-
{% set inverters_power = states('sensor.inverters_active_power') |int(default=0) %}
{% set batteries_cdp = states('sensor.batteries_charge_discharge_power') | int(default=0) %}
{% if inverters_power < 0 and batteries_cdp > 0 %}
{{ (-1 * inverters_power) | int }}
{% else %}
{{ (0) }}
{% endif %}
availability: >-
{{ ( states('sensor.inverters_active_power') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.batteries_charge_discharge_power') not in [ 'unavailable', 'none', 'unknown' ]) }}
# Calculates the Power (W) being Imported from the GRID and consumed by the house.
- sensor:
- name: Power Meter - Grid to House
unique_id: power_meter_grid_to_house
device_class: power
state_class: measurement
unit_of_measurement: W
state: >-
{% set inverters_power = states('sensor.inverters_active_power')|int(default=0) %}
{% set grid_power = states('sensor.power_meter_active_power')|int(default=0) %}
{% if grid_power < 0 %}
{% if inverters_power < 0 %} {{ inverters_power - grid_power | int }}
{% else %} {{ 0 - grid_power | int }}
{% endif %}
{% else %} 0
{% endif %}
availability: >-
{{ (states('sensor.inverters_active_power') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.power_meter_active_power') not in [ 'unavailable', 'none', 'unknown' ]) }}
# Calculates the Power (W) being Imported from the GRID and consumed by the EV Charger.
- sensor:
- name: Power Meter - Grid to EV Charger
unique_id: power_meter_grid_to_ev_charger
device_class: power
state_class: measurement
unit_of_measurement: W
state: >-
{% set grid_power = states('sensor.power_meter_active_power')|int(default=0) %}
{% set battery = states('sensor.batteries_charge_discharge_power')|int(default=0) %}
{% set inverters_input = states('sensor.inverters_input_power')|int(default=0) %}
{% set ev_charger = states('sensor.pro3em_em2_active_power')|int(default=0) %}
{% if battery >= 0 and inverters_input <= 0 and grid_power < 0 %} {{ ev_charger | int }}
{% elif battery < 0 and grid_power < 0 %} {{ ev_charger | int }}
{% else %} 0
{% endif %}
availability: >-
{{ (states('sensor.power_meter_active_power') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.batteries_charge_discharge_power') not in [ 'unavailable', 'none', 'unknown' ])
and (states('sensor.inverters_input_power') not in [ 'unknown', 'none', 'unavailable' ])
and (states('sensor.pro3em_em2_active_power') not in [ 'unavailable', 'none', 'unknown' ]) }}
########### Start: Helpers - Riemann Sum to conver Power (W) to Energy (kWh) ###########
# Riemann Sum sensor to take "Inverters - Input Power with efficiency loss" and convert it into an ENERGY sensor.
sensor:
- platform: integration
name: "Inverter - Input Power - Energy"
unique_id: inverters_input_power_energy
source: sensor.inverters_input_power_with_efficiency_loss
round: 3
unit_prefix: k
unit_time: h
method: left
# Riemann Sum sensor to take "House Consumption - Power" and convert it into ENERGY sensor.
- platform: integration
name: "House Consumption - Energy"
unique_id: house_consumption_energy
source: sensor.house_consumption_power
round: 3
unit_prefix: k
unit_time: h
method: left
########### Start: Energy Meter - Used to create sensors that track usage over a set period ###########
#
# Note: Energy_Meter a HACS integration is used INSTEAD OF the utility_meter, with it providing
# additional functionality, including the ability to quickly add costs to energy sensors.
# See: https://github.com/zeronounours/HA-custom-component-energy-meter
#
energy_meter:
# Used to convert the above Riemann sum sensor into an ENERGY sensor that RESETS to ZERO DAILY.
house_consumption_energy_daily:
unique_id: house_consumption_energy_daily
name: "House Consumption - Energy - Daily"
source: sensor.house_consumption_energy
cycle: daily
######################### End of File #########################