Skip to content

Commit 0fd77c2

Browse files
Merge pull request #201 from vincentwolsink/net_consumption
Expose net consumption sensors
2 parents 7dbfebb + 01f5fe1 commit 0fd77c2

File tree

4 files changed

+728
-8
lines changed

4 files changed

+728
-8
lines changed

custom_components/enphase_envoy/const.py

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def get_model_name(model, hardware_id):
104104
SENSORS = (
105105
SensorEntityDescription(
106106
key="production",
107-
name="Current Power Production",
107+
name="Power Production",
108108
native_unit_of_measurement=UnitOfPower.WATT,
109109
state_class=SensorStateClass.MEASUREMENT,
110110
device_class=SensorDeviceClass.POWER,
@@ -127,7 +127,15 @@ def get_model_name(model, hardware_id):
127127
),
128128
SensorEntityDescription(
129129
key="consumption",
130-
name="Current Power Consumption",
130+
name="Power Consumption",
131+
native_unit_of_measurement=UnitOfPower.WATT,
132+
state_class=SensorStateClass.MEASUREMENT,
133+
device_class=SensorDeviceClass.POWER,
134+
suggested_display_precision=0,
135+
),
136+
SensorEntityDescription(
137+
key="net_consumption",
138+
name="Net Power Consumption",
131139
native_unit_of_measurement=UnitOfPower.WATT,
132140
state_class=SensorStateClass.MEASUREMENT,
133141
device_class=SensorDeviceClass.POWER,
@@ -345,14 +353,14 @@ def get_model_name(model, hardware_id):
345353
),
346354
SensorEntityDescription(
347355
key="voltage",
348-
name="Current Voltage",
356+
name="Voltage",
349357
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
350358
state_class=SensorStateClass.MEASUREMENT,
351359
device_class=SensorDeviceClass.VOLTAGE,
352360
),
353361
SensorEntityDescription(
354362
key="ampere",
355-
name="Current Amps",
363+
name="Amperes",
356364
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
357365
state_class=SensorStateClass.MEASUREMENT,
358366
device_class=SensorDeviceClass.CURRENT,
@@ -479,7 +487,7 @@ def get_model_name(model, hardware_id):
479487
[
480488
SensorEntityDescription(
481489
key=f"production_{phase}",
482-
name=f"Current Power Production {phase.upper()}",
490+
name=f"Power Production {phase.upper()}",
483491
native_unit_of_measurement=UnitOfPower.WATT,
484492
state_class=SensorStateClass.MEASUREMENT,
485493
device_class=SensorDeviceClass.POWER,
@@ -503,14 +511,14 @@ def get_model_name(model, hardware_id):
503511
),
504512
SensorEntityDescription(
505513
key=f"voltage_{phase}",
506-
name=f"Current Voltage {phase.upper()}",
514+
name=f"Voltage {phase.upper()}",
507515
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
508516
state_class=SensorStateClass.MEASUREMENT,
509517
device_class=SensorDeviceClass.VOLTAGE,
510518
),
511519
SensorEntityDescription(
512520
key=f"ampere_{phase}",
513-
name=f"Current Amps {phase.upper()}",
521+
name=f"Amperes {phase.upper()}",
514522
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
515523
state_class=SensorStateClass.MEASUREMENT,
516524
device_class=SensorDeviceClass.CURRENT,
@@ -550,7 +558,7 @@ def get_model_name(model, hardware_id):
550558
#
551559
SensorEntityDescription(
552560
key=f"consumption_{phase}",
553-
name=f"Current Power Consumption {phase.upper()}",
561+
name=f"Power Consumption {phase.upper()}",
554562
native_unit_of_measurement=UnitOfPower.WATT,
555563
state_class=SensorStateClass.MEASUREMENT,
556564
device_class=SensorDeviceClass.POWER,
@@ -572,6 +580,30 @@ def get_model_name(model, hardware_id):
572580
device_class=SensorDeviceClass.ENERGY,
573581
suggested_display_precision=0,
574582
),
583+
SensorEntityDescription(
584+
key=f"net_consumption_{phase}",
585+
name=f"Net Power Consumption {phase.upper()}",
586+
native_unit_of_measurement=UnitOfPower.WATT,
587+
state_class=SensorStateClass.MEASUREMENT,
588+
device_class=SensorDeviceClass.POWER,
589+
suggested_display_precision=0,
590+
),
591+
SensorEntityDescription(
592+
key=f"daily_net_consumption_{phase}",
593+
name=f"Today's Net Energy Consumption {phase.upper()}",
594+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
595+
state_class=SensorStateClass.TOTAL,
596+
device_class=SensorDeviceClass.ENERGY,
597+
suggested_display_precision=0,
598+
),
599+
SensorEntityDescription(
600+
key=f"lifetime_net_consumption_{phase}",
601+
name=f"Lifetime Net Energy Consumption {phase.upper()}",
602+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
603+
state_class=SensorStateClass.TOTAL,
604+
device_class=SensorDeviceClass.ENERGY,
605+
suggested_display_precision=0,
606+
),
575607
]
576608
)
577609
ADDITIONAL_METRICS.extend(

custom_components/enphase_envoy/envoy_reader.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,18 @@ def __new__(cls, *a, **kw):
593593
full_path = f"{ct_path}.lines[{i}]{path}"
594594
setattr(cls, f"{attr}_{phase}_value", full_path)
595595

596+
for attr, path in {
597+
"net_consumption": ".wNow",
598+
"daily_net_consumption": ".whToday",
599+
"lifetime_net_consumption": ".whLifetime",
600+
}.items():
601+
ct_path = cls._net_consumption_ct
602+
setattr(cls, f"{attr}_value", ct_path + path)
603+
604+
for i, phase in enumerate(["l1", "l2", "l3"]):
605+
full_path = f"{ct_path}.lines[{i}]{path}"
606+
setattr(cls, f"{attr}_{phase}_value", full_path)
607+
596608
return EnvoyStandard.__new__(cls)
597609

598610
_production = "endpoint_production_json.production[?(@.type=='inverters')]"
@@ -615,6 +627,7 @@ def lifetime_production(self):
615627
"endpoint_production_json.production[?(@.type=='eim' && @.activeCount > 0)]"
616628
)
617629
_consumption_ct = "endpoint_production_json.consumption[?(@.measurementType == 'total-consumption' && @.activeCount > 0)]"
630+
_net_consumption_ct = "endpoint_production_json.consumption[?(@.measurementType == 'net-consumption' && @.activeCount > 0)]"
618631
voltage_value = _production_ct + ".rmsVoltage"
619632

620633

custom_components/enphase_envoy/envoy_test_data.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@
7070
"installer_required": False,
7171
"optional": False,
7272
},
73+
"device_data": {
74+
"url": TEST_DATA + "endpoint_device_data.json",
75+
"cache": 0,
76+
"installer_required": False,
77+
"optional": True,
78+
},
7379
"devstatus": {
7480
"url": TEST_DATA + "endpoint_devstatus.json",
7581
"cache": 20,

0 commit comments

Comments
 (0)