Skip to content

Commit

Permalink
Add support for inverters
Browse files Browse the repository at this point in the history
  • Loading branch information
j9brown committed Feb 24, 2024
1 parent 93a475f commit 8e9eca8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 38 additions & 0 deletions custom_components/victron_ble/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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):
Expand Down Expand Up @@ -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
26 changes: 25 additions & 1 deletion custom_components/victron_ble/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
),
}


Expand Down

0 comments on commit 8e9eca8

Please sign in to comment.