Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fields for individual phases active/reactive power import/export #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions custom_components/amshan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,21 @@ def _migrate_entity_entry_from_v2_to_v3(entity: entity_registry.RegistryEntry):
obis_map.FIELD_METER_TYPE,
obis_map.FIELD_OBIS_LIST_VER_ID,
obis_map.FIELD_ACTIVE_POWER_IMPORT,
obis_map.FIELD_ACTIVE_POWER_IMPORT_L1,
obis_map.FIELD_ACTIVE_POWER_IMPORT_L2,
obis_map.FIELD_ACTIVE_POWER_IMPORT_L3,
obis_map.FIELD_ACTIVE_POWER_EXPORT,
obis_map.FIELD_ACTIVE_POWER_EXPORT_L1,
obis_map.FIELD_ACTIVE_POWER_EXPORT_L2,
obis_map.FIELD_ACTIVE_POWER_EXPORT_L3,
obis_map.FIELD_REACTIVE_POWER_IMPORT,
obis_map.FIELD_REACTIVE_POWER_IMPORT_L1,
obis_map.FIELD_REACTIVE_POWER_IMPORT_L2,
obis_map.FIELD_REACTIVE_POWER_IMPORT_L3,
obis_map.FIELD_REACTIVE_POWER_EXPORT,
obis_map.FIELD_REACTIVE_POWER_EXPORT_L1,
obis_map.FIELD_REACTIVE_POWER_EXPORT_L2,
obis_map.FIELD_REACTIVE_POWER_EXPORT_L3,
obis_map.FIELD_CURRENT_L1,
obis_map.FIELD_CURRENT_L2,
obis_map.FIELD_CURRENT_L3,
Expand All @@ -259,7 +271,13 @@ def _migrate_entity_entry_from_v2_to_v3(entity: entity_registry.RegistryEntry):

if measure_id in (
obis_map.FIELD_REACTIVE_POWER_IMPORT,
obis_map.FIELD_REACTIVE_POWER_IMPORT_L1,
obis_map.FIELD_REACTIVE_POWER_IMPORT_L2,
obis_map.FIELD_REACTIVE_POWER_IMPORT_L3,
obis_map.FIELD_REACTIVE_POWER_EXPORT,
obis_map.FIELD_REACTIVE_POWER_EXPORT_L1,
obis_map.FIELD_REACTIVE_POWER_EXPORT_L2,
obis_map.FIELD_REACTIVE_POWER_EXPORT_L3,
):
update["device_class"] = ha_sensor.SensorDeviceClass.REACTIVE_POWER
update["unit_of_measurement"] = ha_const.POWER_VOLT_AMPERE_REACTIVE
Expand Down
122 changes: 122 additions & 0 deletions custom_components/amshan/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,36 @@ class AmsHanSensorEntityDescription(SensorEntityDescription):
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_ACTIVE_POWER_IMPORT_L1,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=ha_const.POWER_WATT,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_IMPORT,
name="Active power import (Q1+Q4) phase L1",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_ACTIVE_POWER_IMPORT_L2,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=ha_const.POWER_WATT,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_IMPORT,
name="Active power import (Q1+Q4) phase L2",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_ACTIVE_POWER_IMPORT_L3,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=ha_const.POWER_WATT,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_IMPORT,
name="Active power import (Q1+Q4) phase L3",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_ACTIVE_POWER_EXPORT,
device_class=SensorDeviceClass.POWER,
Expand All @@ -108,6 +138,36 @@ class AmsHanSensorEntityDescription(SensorEntityDescription):
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_ACTIVE_POWER_EXPORT_L1,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=ha_const.POWER_WATT,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_EXPORT,
name="Active power export (Q2+Q3) phase L1",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_ACTIVE_POWER_EXPORT_L2,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=ha_const.POWER_WATT,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_EXPORT,
name="Active power export (Q2+Q3) phase L2",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_ACTIVE_POWER_EXPORT_L3,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=ha_const.POWER_WATT,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_EXPORT,
name="Active power export (Q2+Q3) phase L3",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_REACTIVE_POWER_IMPORT,
device_class=SensorDeviceClass.REACTIVE_POWER,
Expand All @@ -118,6 +178,36 @@ class AmsHanSensorEntityDescription(SensorEntityDescription):
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_REACTIVE_POWER_IMPORT_L1,
device_class=SensorDeviceClass.REACTIVE_POWER,
native_unit_of_measurement=ha_const.POWER_VOLT_AMPERE_REACTIVE,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_IMPORT,
name="Reactive power import (Q1+Q2) phase L1",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_REACTIVE_POWER_IMPORT_L2,
device_class=SensorDeviceClass.REACTIVE_POWER,
native_unit_of_measurement=ha_const.POWER_VOLT_AMPERE_REACTIVE,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_IMPORT,
name="Reactive power import (Q1+Q2) phase L2",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_REACTIVE_POWER_IMPORT_L3,
device_class=SensorDeviceClass.REACTIVE_POWER,
native_unit_of_measurement=ha_const.POWER_VOLT_AMPERE_REACTIVE,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_IMPORT,
name="Reactive power import (Q1+Q2) phase L3",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_REACTIVE_POWER_EXPORT,
device_class=SensorDeviceClass.REACTIVE_POWER,
Expand All @@ -128,6 +218,36 @@ class AmsHanSensorEntityDescription(SensorEntityDescription):
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_REACTIVE_POWER_EXPORT_L1,
device_class=SensorDeviceClass.REACTIVE_POWER,
native_unit_of_measurement=ha_const.POWER_VOLT_AMPERE_REACTIVE,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_EXPORT,
name="Reactive power export (Q3+Q4) phase L1",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_REACTIVE_POWER_EXPORT_L2,
device_class=SensorDeviceClass.REACTIVE_POWER,
native_unit_of_measurement=ha_const.POWER_VOLT_AMPERE_REACTIVE,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_EXPORT,
name="Reactive power export (Q3+Q4) phase L2",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_REACTIVE_POWER_EXPORT_L3,
device_class=SensorDeviceClass.REACTIVE_POWER,
native_unit_of_measurement=ha_const.POWER_VOLT_AMPERE_REACTIVE,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_POWER_EXPORT,
name="Reactive power export (Q3+Q4) phase L3",
decimals=0,
use_configured_scaling=True,
),
AmsHanSensorEntityDescription(
key=obis_map.FIELD_CURRENT_L1,
device_class=SensorDeviceClass.CURRENT,
Expand All @@ -143,6 +263,7 @@ class AmsHanSensorEntityDescription(SensorEntityDescription):
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=ha_const.ELECTRIC_CURRENT_AMPERE,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_CURRENT,
name="Current phase L2",
decimals=3,
use_configured_scaling=True,
Expand All @@ -152,6 +273,7 @@ class AmsHanSensorEntityDescription(SensorEntityDescription):
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=ha_const.ELECTRIC_CURRENT_AMPERE,
state_class=SensorStateClass.MEASUREMENT,
icon=ICON_CURRENT,
name="Current phase L3",
decimals=3,
use_configured_scaling=True,
Expand Down