Skip to content

Commit

Permalink
#69 meter reading value for socket 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuen Lee committed Sep 27, 2023
1 parent e675f8b commit 3f25f6c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
3 changes: 2 additions & 1 deletion custom_components/alfen_wallbox/alfen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CAT_GENERIC,
CAT_GENERIC2,
CAT_METER1,
CAT_METER2,
CAT_METER4,
CAT_OCPP,
CAT_STATES,
Expand Down Expand Up @@ -239,7 +240,7 @@ async def _get_value(self, api_param):
async def _get_all_properties_value(self):
_LOGGER.debug(f"Get properties")
properties = []
for cat in (CAT_GENERIC, CAT_GENERIC2, CAT_METER1, CAT_STATES, CAT_TEMP, CAT_OCPP, CAT_METER4, CAT_MBUS_TCP, CAT_COMM, CAT_DISPLAY):
for cat in (CAT_GENERIC, CAT_GENERIC2, CAT_METER1, CAT_STATES, CAT_TEMP, CAT_OCPP, CAT_METER4, CAT_MBUS_TCP, CAT_COMM, CAT_DISPLAY, CAT_METER2):
nextRequest = True
offset = 0
while (nextRequest):
Expand Down
3 changes: 3 additions & 0 deletions custom_components/alfen_wallbox/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
CAT_MBUS_TCP = "MbusTCP"
CAT_COMM = "comm"
CAT_DISPLAY = "display"
#CAT_LEDS = "leds"
#CAT_ACCELERO = "accelero"
CAT_METER2 = "meter2"

COMMAND_REBOOT = "reboot"

Expand Down
30 changes: 25 additions & 5 deletions custom_components/alfen_wallbox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ class AlfenSensorDescription(
device_class=SensorDeviceClass.CURRENT,
),
AlfenSensorDescription(
key="active_power_total",
name="Active Power Total",
key="active_power_total_socket_1",
name="Active Power Total Socket 1",
icon="mdi:circle-slice-3",
api_param="2221_16",
unit=UnitOfPower.WATT,
Expand All @@ -440,8 +440,8 @@ class AlfenSensorDescription(
device_class=SensorDeviceClass.POWER,
),
AlfenSensorDescription(
key="meter_reading",
name="Meter Reading",
key="meter_reading_socket_1",
name="Meter Reading Socket 1",
icon="mdi:counter",
api_param="2221_22",
unit=UnitOfEnergy.KILO_WATT_HOUR,
Expand Down Expand Up @@ -1149,6 +1149,26 @@ class AlfenSensorDescription(
api_param="3191_2",
round_digits=None,
),
AlfenSensorDescription(
key="meter_reading_socket_2",
name="Meter Reading Socket 2",
icon="mdi:counter",
api_param="3221_22",
unit=UnitOfEnergy.KILO_WATT_HOUR,
round_digits=None,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY
),
AlfenSensorDescription(
key="active_power_total_socket_2",
name="Active Power Total Socket 2",
icon="mdi:circle-slice-3",
api_param="3221_16",
unit=UnitOfPower.WATT,
round_digits=2,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER,
),
)


Expand Down Expand Up @@ -1351,7 +1371,7 @@ def state(self) -> StateType:
return STATUS_DICT.get(prop[VALUE], 'Unknown')

# meter_reading from w to kWh
if self.entity_description.api_param == "2221_22":
if self.entity_description.api_param == "2221_22" or self.entity_description.api_param == "3221_22":
return round((prop[VALUE] / 1000), 2)

# Car PWM Duty cycle %
Expand Down

0 comments on commit 3f25f6c

Please sign in to comment.