From 8e9eca844f2ea784827502e2ae190304dd98b8c8 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Fri, 23 Feb 2024 14:45:06 -0800 Subject: [PATCH] Add support for inverters --- README.md | 6 ++++ custom_components/victron_ble/device.py | 38 +++++++++++++++++++++++++ custom_components/victron_ble/sensor.py | 26 ++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a0987e..2589b93 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,12 @@ Supported Devices & Entities: - Solar Power (W) - Yield Today (Wh) - External Device Load (A) +- Inverter + - Device State (Off, Inverting) + - Battery Voltage (V) + - AC Voltage (V) + - AC Current (A) + - AC Apparent Power (VA) # Installation diff --git a/custom_components/victron_ble/device.py b/custom_components/victron_ble/device.py index 9af3fc9..d4a98ba 100644 --- a/custom_components/victron_ble/device.py +++ b/custom_components/victron_ble/device.py @@ -11,6 +11,7 @@ from victron_ble.devices.battery_sense import BatterySenseData from victron_ble.devices.dc_energy_meter import DcEnergyMeterData from victron_ble.devices.dcdc_converter import DcDcConverterData +from victron_ble.devices.inverter import InverterData from victron_ble.devices.solar_charger import SolarChargerData _LOGGER = logging.getLogger(__name__) @@ -28,6 +29,10 @@ class VictronSensor(StrEnum): STARTER_BATTERY_VOLTAGE = "starter_battery_voltage" MIDPOINT_VOLTAGE = "midpoint_voltage" TIME_REMAINING = "time_remaining" + BATTERY_VOLTAGE = "battery_voltage" + AC_VOLTAGE = "ac_voltage" + AC_CURRENT = "ac_current" + AC_APPARENT_POWER = "ac_apparent_power" class VictronBluetoothDeviceData(BluetoothData): @@ -198,4 +203,37 @@ def _process_mfr_data( device_class=SensorDeviceClass.ENUM, ) + elif isinstance(parsed, InverterData): + self.update_sensor( + key=VictronSensor.OPERATION_MODE, + native_unit_of_measurement=None, + native_value=parsed.get_device_state().name.lower(), + device_class=SensorDeviceClass.ENUM, + ) + self.update_sensor( + key=VictronSensor.BATTERY_VOLTAGE, + native_unit_of_measurement=Units.ELECTRIC_POTENTIAL_VOLT, + native_value=parsed.get_battery_voltage(), + device_class=SensorDeviceClass.VOLTAGE, + ) + self.update_sensor( + key=VictronSensor.AC_VOLTAGE, + native_unit_of_measurement=Units.ELECTRIC_POTENTIAL_VOLT, + native_value=parsed.get_ac_voltage(), + device_class=SensorDeviceClass.VOLTAGE, + ) + self.update_sensor( + key=VictronSensor.AC_CURRENT, + native_unit_of_measurement=Units.ELECTRIC_CURRENT_AMPERE, + native_value=parsed.get_ac_current(), + device_class=SensorDeviceClass.CURRENT, + ) + self.update_sensor( + key=VictronSensor.AC_APPARENT_POWER, + native_unit_of_measurement=Units.POWER_VOLT_AMPERE, + native_value=parsed.get_ac_apparent_power(), + device_class=SensorDeviceClass.APPARENT_POWER, + ) + + return diff --git a/custom_components/victron_ble/sensor.py b/custom_components/victron_ble/sensor.py index 3b091ac..98d8fb7 100644 --- a/custom_components/victron_ble/sensor.py +++ b/custom_components/victron_ble/sensor.py @@ -24,7 +24,7 @@ from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info from sensor_state_data.data import SensorUpdate from sensor_state_data.units import Units -from victron_ble.devices.base import ChargerError, OffReason, OperationMode +from victron_ble.devices.base import ACInState, ChargerError, OffReason, OperationMode from victron_ble.devices.battery_monitor import AuxMode from .const import DOMAIN @@ -154,6 +154,30 @@ native_unit_of_measurement=Units.ELECTRIC_POTENTIAL_VOLT, state_class=SensorStateClass.MEASUREMENT, ), + (VictronSensor.BATTERY_VOLTAGE, Units.ELECTRIC_POTENTIAL_VOLT): SensorEntityDescription( + key=VictronSensor.BATTERY_VOLTAGE, + device_class=SensorDeviceClass.VOLTAGE, + native_unit_of_measurement=Units.ELECTRIC_POTENTIAL_VOLT, + state_class=SensorStateClass.MEASUREMENT, + ), + (VictronSensor.AC_VOLTAGE, Units.ELECTRIC_POTENTIAL_VOLT): SensorEntityDescription( + key=VictronSensor.AC_VOLTAGE, + device_class=SensorDeviceClass.VOLTAGE, + native_unit_of_measurement=Units.ELECTRIC_POTENTIAL_VOLT, + state_class=SensorStateClass.MEASUREMENT, + ), + (VictronSensor.AC_CURRENT, Units.ELECTRIC_CURRENT_AMPERE): SensorEntityDescription( + key=VictronSensor.AC_CURRENT, + device_class=SensorDeviceClass.CURRENT, + native_unit_of_measurement=Units.ELECTRIC_CURRENT_AMPERE, + state_class=SensorStateClass.MEASUREMENT, + ), + (VictronSensor.AC_APPARENT_POWER, Units.POWER_VOLT_AMPERE): SensorEntityDescription( + key=VictronSensor.AC_CURRENT, + device_class=SensorDeviceClass.APPARENT_POWER, + native_unit_of_measurement=Units.POWER_VOLT_AMPERE, + state_class=SensorStateClass.MEASUREMENT, + ), }