From d3e86f616ac6f40f94e458c05b4df08a79977fa4 Mon Sep 17 00:00:00 2001 From: Andrii Ganzevych Date: Fri, 3 Nov 2023 00:20:01 +0200 Subject: [PATCH] Single config entry setup (#2) - now integration setups with single sensor entry - global code refactoring --- README.md | 28 +- custom_components/ina219_ups_hat/__init__.py | 2 +- .../ina219_ups_hat/binary_sensor.py | 56 ---- custom_components/ina219_ups_hat/const.py | 25 ++ .../ina219_ups_hat/coordinator.py | 93 ++++++ custom_components/ina219_ups_hat/entity.py | 31 ++ .../ina219_ups_hat/ina219_wrapper.py | 4 +- .../ina219_ups_hat/manifest.json | 2 +- custom_components/ina219_ups_hat/sensor.py | 304 +++++++++--------- examples/packages/ina219_ups_hat.yaml | 59 ---- 10 files changed, 316 insertions(+), 288 deletions(-) delete mode 100644 custom_components/ina219_ups_hat/binary_sensor.py create mode 100644 custom_components/ina219_ups_hat/coordinator.py create mode 100644 custom_components/ina219_ups_hat/entity.py delete mode 100644 examples/packages/ina219_ups_hat.yaml diff --git a/README.md b/README.md index e3a1d1a..a948552 100644 --- a/README.md +++ b/README.md @@ -31,18 +31,6 @@ In the end your file structure should look like that: ``` ## Configuration -### Example configuration package -You can use preconfigured integration package if your HA instance is configured to use packages. -You can check it by presence of `packages` directory in config folder and such code in `configuration.yaml`: -```yaml -homeassistant: - packages: !include_dir_merge_named packages -``` -After that you can copy file [ina219_ups_hat.yaml](/examples/packages/ina219_ups_hat.yaml) to your `packages` folder & customize it. - -### Example automations -Copy contents of [examples/automations.yaml](/examples/automations.yaml) to your `automations.yaml`. Customize. - ### Sensor Create a new sensor entry in your `configuration.yaml` @@ -55,16 +43,17 @@ sensor: batteries_count: 3 # Optional max_soc: 91 # Optional battery_capacity: 9000 # Optional + sma_samples: 5 # Optional ``` Following data can be read: - SoC (State of Charge) - - PSU Voltage - - Shunt Voltage + - Voltage - Current - Power - Charging Status - Online Status - - Is Low Battery (< 20%) + - Remaining Capacity + - Remaining Time If you consistently experience capacity below 100% when the device is fully charged, you can adjust it using the `max_soc` property. @@ -89,13 +78,8 @@ sensor: #### Batteries Count The original Waveshare UPS Hat has 2 batteries in series (8.4V), but some versions of the UPS Hats may have 3 batteries (12.6V). If you have more than 2 batteries in series, use the `batteries_count` parameter. -### Binary Sensor -In addition to the sensor devices, you may also create a device which is simply “on” when the UPS status is online and “off” at all other times. - -```yaml -binary_sensor: - - platform: ina219_ups_hat -``` +### Example automations +Copy contents of [examples/automations.yaml](/examples/automations.yaml) to your `automations.yaml`. Customize. ## Directions for installing smbus support on Raspberry Pi diff --git a/custom_components/ina219_ups_hat/__init__.py b/custom_components/ina219_ups_hat/__init__.py index 6fa9ab7..f5b515e 100644 --- a/custom_components/ina219_ups_hat/__init__.py +++ b/custom_components/ina219_ups_hat/__init__.py @@ -1 +1 @@ -"""Waveshare INA219 UPS Hat""" +"""INA219 UPS Hat""" diff --git a/custom_components/ina219_ups_hat/binary_sensor.py b/custom_components/ina219_ups_hat/binary_sensor.py deleted file mode 100644 index 8394a09..0000000 --- a/custom_components/ina219_ups_hat/binary_sensor.py +++ /dev/null @@ -1,56 +0,0 @@ -"""Support for tracking the online status of a Waveshare UPS Hat""" - -import voluptuous as vol - -from homeassistant.components.binary_sensor import BinarySensorEntity -import homeassistant.helpers.config_validation as cv -from .ina219 import INA219 -from homeassistant.const import DEVICE_CLASS_POWER - -DEFAULT_NAME = "ina219_ups_hat_online" -from .const import MIN_ONLINE_CURRENT - - -def setup_platform( - hass, - config, - add_entities, - discovery_info=None, -): - """Set up an Online Status binary sensor.""" - - add_entities([OnlineStatus(config, {})], True) - - -class OnlineStatus(BinarySensorEntity): - - """Representation of an UPS online status.""" - - def __init__(self, config, data): - """Initialize the UPS online status binary device.""" - - self._name = DEFAULT_NAME - self._ina219 = INA219(addr=0x42) - self._state = True - - @property - def name(self): - """Return the name of the UPS online status sensor.""" - - return self._name - - @property - def device_class(self): - """Return the device class of the binary sensor.""" - return DEVICE_CLASS_POWER - - @property - def is_on(self): - """Return true if the UPS is online, else false.""" - - return self._state - - def update(self): - """Get the status from UPS online status and set this entity's state.""" - - self._state = self._ina219.getCurrent_mA() > MIN_ONLINE_CURRENT diff --git a/custom_components/ina219_ups_hat/const.py b/custom_components/ina219_ups_hat/const.py index ee35a9e..a353e6e 100644 --- a/custom_components/ina219_ups_hat/const.py +++ b/custom_components/ina219_ups_hat/const.py @@ -2,3 +2,28 @@ MIN_CHARGING_CURRENT = 1 MIN_BATTERY_CONNECTED_CURRENT = 0.1 LOW_BATTERY_PERCENTAGE = 20 + +DOMAIN = "ina219_ups_hat" +DEFAULT_NAME = "ina219_ups_hat" + +CONF_BATTERY_CAPACITY = "battery_capacity" +CONF_MAX_SOC = "max_soc" +CONF_SMA_SAMPLES = "sma_samples" +CONF_BATTERIES_COUNT = "batteries_count" +CONF_SCAN_INTERVAL = "scan_interval" + +ATTR_CAPACITY = "capacity" +ATTR_SOC = "soc" +ATTR_REAL_SOC = "real_soc" +ATTR_PSU_VOLTAGE = "psu_voltage" +ATTR_SHUNT_VOLTAGE = "shunt_voltage" +ATTR_LOAD_VOLTAGE = "load_voltage" +ATTR_CURRENT = "current" +ATTR_POWER = "power" +ATTR_CHARGING = "charging" +ATTR_ONLINE = "online" +ATTR_BATTERY_CONNECTED = "battery_connected" +ATTR_LOW_BATTERY = "low_battery" +ATTR_POWER_CALCULATED = "power_calculated" +ATTR_REMAINING_BATTERY_CAPACITY = "remaining_battery_capacity" +ATTR_REMAINING_TIME = "remaining_time_min" diff --git a/custom_components/ina219_ups_hat/coordinator.py b/custom_components/ina219_ups_hat/coordinator.py new file mode 100644 index 0000000..6243224 --- /dev/null +++ b/custom_components/ina219_ups_hat/coordinator.py @@ -0,0 +1,93 @@ +import logging +from .const import CONF_BATTERIES_COUNT, CONF_BATTERY_CAPACITY, CONF_MAX_SOC, CONF_SMA_SAMPLES, MIN_CHARGING_CURRENT, MIN_ONLINE_CURRENT +from .ina219 import INA219 +from .ina219_wrapper import INA219Wrapper +from homeassistant import core +from homeassistant.const import CONF_NAME, CONF_UNIQUE_ID +from homeassistant.helpers.typing import ConfigType +from homeassistant.helpers.update_coordinator import ( + DataUpdateCoordinator, + UpdateFailed, +) +import random + +_LOGGER = logging.getLogger(__name__) + + +class INA219UpsHatCoordinator(DataUpdateCoordinator): + def __init__(self, hass: core.HomeAssistant, config: ConfigType) -> None: + """Initialize coordinator""" + + self.name_prefix = config.get(CONF_NAME) + self.id_prefix = config.get(CONF_UNIQUE_ID) + + self._max_soc = config.get(CONF_MAX_SOC) + self._battery_capacity = config.get(CONF_BATTERY_CAPACITY) + self._batteries_count = config.get(CONF_BATTERIES_COUNT) + self._sma_samples = config.get(CONF_SMA_SAMPLES) + + self._ina219 = INA219(addr=0x41) + self._ina219_wrapper = INA219Wrapper(self._ina219, self._sma_samples) + + super().__init__( + hass, + _LOGGER, + name="ina219_ups_hat", + update_method=self._update_data, + ) + + async def _update_data(self): + try: + ina219_wrapper = self._ina219_wrapper + ina219_wrapper.measureINAValues() + + bus_voltage = ina219_wrapper.getBusVoltageSMA_V() # voltage on V- (load side) + shunt_voltage = (ina219_wrapper.getShuntVoltageSMA_mV() / 1000) # voltage between V+ and V- across the shunt + current = ina219_wrapper.getCurrentSMA_mA() # current in mA + power = ina219_wrapper.getPowerSMA_W() # power in W + + smooth_bus_voltage = ina219_wrapper.getBusVoltageSMAx2_V() + smooth_current = ina219_wrapper.getCurrentSMAx2_mA() + + soc_c1 = 3 * self._batteries_count + soc_c2 = 1.2 * self._batteries_count + real_soc = (smooth_bus_voltage - soc_c1) / soc_c2 * 100 + soc = ( + (smooth_bus_voltage - soc_c1) / + (soc_c2 * (self._max_soc / 100.0)) * 100 + ) + if soc > 100: + soc = 100 + if soc < 0: + soc = 0 + + power_calculated = bus_voltage * (current / 1000) + + online = bool(current > MIN_ONLINE_CURRENT) + charging = bool(current > MIN_CHARGING_CURRENT) + + if self._battery_capacity is None: + remaining_battery_capacity = None + remaining_time = None + else: + remaining_battery_capacity = ( + real_soc / 100.0) * self._battery_capacity + if not online: + remaining_time = round( + (remaining_battery_capacity / -smooth_current) * 60.0, 0 + ) + else: + remaining_time = None + + return { + "voltage": round(bus_voltage + shunt_voltage, 2), + "current": round(current / 1000, 5), + "power": round(power_calculated, 2), + "soc": round(soc, 1), + "remaining_battery_capacity": round(remaining_battery_capacity, 0), + "remaining_time": remaining_time, + "online": online, + "charging": charging, + } + except Exception as e: + raise UpdateFailed(f"Error updating data: {e}") diff --git a/custom_components/ina219_ups_hat/entity.py b/custom_components/ina219_ups_hat/entity.py new file mode 100644 index 0000000..a896895 --- /dev/null +++ b/custom_components/ina219_ups_hat/entity.py @@ -0,0 +1,31 @@ + +from .const import DOMAIN +from .coordinator import INA219UpsHatCoordinator +from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo + + +class INA219UpsHatEntity(): + def __init__(self, coordinator: INA219UpsHatCoordinator) -> None: + self._coordinator = coordinator + self._device_id = self._coordinator.id_prefix + + @property + def name(self): + return self._coordinator.name_prefix + ' ' + self._name + + @property + def unique_id(self): + return self._coordinator.id_prefix + '_' + self._name + + @property + def device_info(self) -> DeviceInfo: + """Return the device_info of the device.""" + return DeviceInfo( + identifiers={(DOMAIN, self._coordinator.id_prefix)}, + name=self._coordinator.name_prefix, + manufacturer="Some Chinese factory", + sw_version="0.3.0", + ) + + async def async_update(self): + await self._coordinator.async_request_refresh() diff --git a/custom_components/ina219_ups_hat/ina219_wrapper.py b/custom_components/ina219_ups_hat/ina219_wrapper.py index 9b0b0aa..f068dd1 100644 --- a/custom_components/ina219_ups_hat/ina219_wrapper.py +++ b/custom_components/ina219_ups_hat/ina219_wrapper.py @@ -52,7 +52,7 @@ def _getSMMValue(self, buf:deque, divider:int=1): return np.median(self._getBufTail(buf, divider)) return np.median(buf) - def _getBufTail(self, buf:deque, divider:int): - slice_start = len(buf) - int(len(buf) / divider) + def _getBufTail(self, buf: deque, divider: int): + slice_start = len(buf) - int(len(buf) / divider) - 1 slice_end = len(buf) return list(buf)[slice_start:slice_end] diff --git a/custom_components/ina219_ups_hat/manifest.json b/custom_components/ina219_ups_hat/manifest.json index a65806a..0766562 100644 --- a/custom_components/ina219_ups_hat/manifest.json +++ b/custom_components/ina219_ups_hat/manifest.json @@ -8,5 +8,5 @@ "iot_class": "local_polling", "issue_tracker": "https://github.com/odya/hass-ina219-ups-hat/issues", "requirements": ["smbus2>=0.4.2","numpy>=1.23.2"], - "version": "0.2.1" + "version": "0.3.0" } diff --git a/custom_components/ina219_ups_hat/sensor.py b/custom_components/ina219_ups_hat/sensor.py index a4891ad..c7f4b9b 100644 --- a/custom_components/ina219_ups_hat/sensor.py +++ b/custom_components/ina219_ups_hat/sensor.py @@ -1,52 +1,40 @@ """Details about the INA219 UPS Hat sensor""" -import logging -import os - -import voluptuous as vol +from homeassistant.components.binary_sensor import BinarySensorDeviceClass, BinarySensorEntity +from homeassistant.components.sensor.const import SensorDeviceClass, SensorStateClass +from homeassistant import core from homeassistant.components.sensor import SensorEntity, PLATFORM_SCHEMA from homeassistant.const import ( - DEVICE_CLASS_BATTERY, - PERCENTAGE, CONF_NAME, CONF_UNIQUE_ID, + PERCENTAGE, + UnitOfElectricCurrent, + UnitOfElectricPotential, + UnitOfPower, + UnitOfTime, ) -import homeassistant.helpers.config_validation as cv +import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType +from homeassistant.helpers.event import async_track_time_interval +from homeassistant.helpers.entity_platform import AddEntitiesCallback +import logging +import voluptuous as vol -_LOGGER = logging.getLogger(__name__) - -from .ina219 import INA219 -from .ina219_wrapper import INA219Wrapper +from .entity import INA219UpsHatEntity +from .coordinator import INA219UpsHatCoordinator from .const import ( - MIN_CHARGING_CURRENT, - MIN_ONLINE_CURRENT, - MIN_BATTERY_CONNECTED_CURRENT, - LOW_BATTERY_PERCENTAGE, + CONF_BATTERIES_COUNT, + CONF_BATTERY_CAPACITY, + CONF_MAX_SOC, + CONF_SCAN_INTERVAL, + CONF_SMA_SAMPLES, + DEFAULT_NAME, ) -ATTR_CAPACITY = "capacity" -ATTR_SOC = "soc" -ATTR_REAL_SOC = "real_soc" -ATTR_PSU_VOLTAGE = "psu_voltage" -ATTR_SHUNT_VOLTAGE = "shunt_voltage" -ATTR_LOAD_VOLTAGE = "load_voltage" -ATTR_CURRENT = "current" -ATTR_POWER = "power" -ATTR_CHARGING = "charging" -ATTR_ONLINE = "online" -ATTR_BATTERY_CONNECTED = "battery_connected" -ATTR_LOW_BATTERY = "low_battery" -ATTR_POWER_CALCULATED = "power_calculated" - -ATTR_REMAINING_BATTERY_CAPACITY = "remaining_battery_capacity" -ATTR_REMAINING_TIME = "remaining_time_min" - -CONF_BATTERY_CAPACITY = "battery_capacity" -CONF_MAX_SOC = "max_soc" -CONF_SMA_SAMPLES = "sma_samples" -CONF_BATTERIES_COUNT = "batteries_count" -DEFAULT_NAME = "ina219_ups_hat" + +_LOGGER = logging.getLogger(__name__) + PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { @@ -60,125 +48,147 @@ ) -def setup_platform(hass, config, add_entities, discovery_info=None): - """Set up the INA219 UPS Hat sensor.""" - name = config.get(CONF_NAME) - unique_id = config.get(CONF_UNIQUE_ID) - max_soc = config.get(CONF_MAX_SOC) - battery_capacity = config.get(CONF_BATTERY_CAPACITY) - batteries_count = config.get(CONF_BATTERIES_COUNT) - sma_samples = config.get(CONF_SMA_SAMPLES) - add_entities([INA219UpsHat(name, unique_id, max_soc, battery_capacity, batteries_count, sma_samples)], True) - - -class INA219UpsHat(SensorEntity): - """Representation of a INA219 UPS Hat.""" - - def __init__(self, name, unique_id=None, max_soc=None, battery_capacity=None, batteries_count=None, sma_samples=None): - """Initialize the sensor.""" - self._name = name - self._unique_id = unique_id - if max_soc > 100: - max_soc = 100 - elif max_soc < 1: - max_soc = 1 - self._max_soc = max_soc - self._battery_capacity = battery_capacity - self._batteries_count = batteries_count - self._ina219 = INA219(addr=0x41) - self._ina219_wrapper = INA219Wrapper(self._ina219, sma_samples) - self._attrs = {} +async def async_setup_platform( + hass: core.HomeAssistant, + config: ConfigType, + async_add_entities: AddEntitiesCallback, + discovery_info: DiscoveryInfoType | None = None, +) -> None: + coordinator = INA219UpsHatCoordinator(hass, config) + await coordinator.async_refresh() + + sensors = [ + VoltageSensor(coordinator), + CurrentSensor(coordinator), + PowerSensor(coordinator), + SocSensor(coordinator), + RemainingCapacitySensor(coordinator), + RemainingTimeSensor(coordinator), + OnlineBinarySensor(coordinator), + ChargingBinarySensor(coordinator), + ] + async_add_entities(sensors) + + async def async_update_data(now): + await coordinator.async_request_refresh() + + async_track_time_interval(hass, async_update_data, + config.get(CONF_SCAN_INTERVAL)) + + +# SENSORS + + +class INA219UpsHatSensor(INA219UpsHatEntity, SensorEntity): + """Base sensor""" + + def __init__(self, coordinator: INA219UpsHatCoordinator) -> None: + super().__init__(coordinator) + self._attr_suggested_display_precision = 2 + + +class VoltageSensor(INA219UpsHatSensor): + def __init__(self, coordinator) -> None: + super().__init__(coordinator) + self._name = "Voltage" + self._attr_native_unit_of_measurement = UnitOfElectricPotential.VOLT + self._attr_device_class = SensorDeviceClass.VOLTAGE @property - def name(self): - """Return the name of the sensor.""" - return self._name + def native_value(self): + return self._coordinator.data["voltage"] + + +class CurrentSensor(INA219UpsHatSensor): + def __init__(self, coordinator) -> None: + super().__init__(coordinator) + self._name = "Current" + self._attr_native_unit_of_measurement = UnitOfElectricCurrent.AMPERE + self._attr_device_class = SensorDeviceClass.CURRENT + + @property + def native_value(self): + return self._coordinator.data["current"] + + +class PowerSensor(INA219UpsHatSensor): + def __init__(self, coordinator) -> None: + super().__init__(coordinator) + self._name = "Power" + self._attr_native_unit_of_measurement = UnitOfPower.WATT + self._attr_device_class = SensorDeviceClass.POWER @property - def device_class(self): - """Return the device class of the sensor.""" - return DEVICE_CLASS_BATTERY + def native_value(self): + return self._coordinator.data["power"] + + +class SocSensor(INA219UpsHatSensor): + def __init__(self, coordinator) -> None: + super().__init__(coordinator) + self._name = "SoC" + self._attr_native_unit_of_measurement = PERCENTAGE + self._attr_device_class = SensorDeviceClass.BATTERY + self._attr_suggested_display_precision = 1 @property - def state(self): - """Return the state of the sensor.""" - return self._attrs.get(ATTR_SOC) + def native_value(self): + return self._coordinator.data["soc"] + + +class RemainingCapacitySensor(INA219UpsHatSensor): + def __init__(self, coordinator) -> None: + super().__init__(coordinator) + self._name = "Remaining Capacity" + self._attr_native_unit_of_measurement = "mAh" + self._attr_suggested_display_precision = 0 @property - def unit_of_measurement(self): - """Return the unit the value is expressed in.""" - return PERCENTAGE + def native_value(self): + return self._coordinator.data["remaining_battery_capacity"] + + +class RemainingTimeSensor(INA219UpsHatSensor): + def __init__(self, coordinator) -> None: + super().__init__(coordinator) + self._name = "Remaining Time" + self._attr_native_unit_of_measurement = UnitOfTime.SECONDS + self._attr_device_class = SensorDeviceClass.DURATION + self._attr_state_class = SensorStateClass.TOTAL_INCREASING + self._attr_suggested_display_precision = 0 @property - def extra_state_attributes(self): - """Return the state attributes of the sensor.""" - return self._attrs + def native_value(self): + return self._coordinator.data["remaining_time"] + + +# BINARY SENSORS + + +class INA219UpsHatBinarySensor(INA219UpsHatEntity, BinarySensorEntity): + """Base binary sensor""" + + def __init__(self, coordinator: INA219UpsHatCoordinator) -> None: + super().__init__(coordinator) + + +class OnlineBinarySensor(INA219UpsHatBinarySensor): + def __init__(self, coordinator) -> None: + super().__init__(coordinator) + self._name = "Online" + self._attr_device_class = BinarySensorDeviceClass.PLUG + + @property + def is_on(self): + return self._coordinator.data["online"] + + +class ChargingBinarySensor(INA219UpsHatBinarySensor): + def __init__(self, coordinator) -> None: + super().__init__(coordinator) + self._name = "Charging" + self._attr_device_class = BinarySensorDeviceClass.BATTERY_CHARGING @property - def unique_id(self): - """Return the unique id of the sensor.""" - return self._unique_id - - def update(self): - """Get the latest data and updates the states.""" - ina219_wrapper = self._ina219_wrapper - ina219_wrapper.measureINAValues() - - bus_voltage = ina219_wrapper.getBusVoltageSMA_V() # voltage on V- (load side) - shunt_voltage = (ina219_wrapper.getShuntVoltageSMA_mV() / 1000) # voltage between V+ and V- across the shunt - current = ina219_wrapper.getCurrentSMA_mA() # current in mA - power = ina219_wrapper.getPowerSMA_W() # power in W - - smooth_bus_voltage = ina219_wrapper.getBusVoltageSMAx2_V() - smooth_current = ina219_wrapper.getCurrentSMAx2_mA() - - soc_c1 = 3 * self._batteries_count - soc_c2 = 1.2 * self._batteries_count - real_soc = (smooth_bus_voltage - soc_c1) / soc_c2 * 100 - soc = (smooth_bus_voltage - soc_c1) / (soc_c2 * (self._max_soc / 100.0)) * 100 - - if soc > 100: - soc = 100 - if soc < 0: - soc = 0 - - # battery_connected = current > MIN_BATTERY_CONNECTED_CURRENT - - online = bool(current > MIN_ONLINE_CURRENT) - charging = bool(current > MIN_CHARGING_CURRENT) - - low_battery = bool(online and (soc < LOW_BATTERY_PERCENTAGE)) - power_calculated = bus_voltage * (current / 1000) - - if self._battery_capacity is None: - remaining_battery_capacity = None - remaining_time = None - else: - remaining_battery_capacity = (real_soc / 100.0) * self._battery_capacity - if not online: - remaining_time = round( - (remaining_battery_capacity / -smooth_current) * 60.0, 0 - ) - else: - remaining_time = None - - # if not battery_connected: - # capacity = 0.0 # no battery no capacity - - self._attrs = { - ATTR_CAPACITY: round(soc, 0), - ATTR_SOC: round(soc, 0), - ATTR_REAL_SOC: real_soc, - ATTR_PSU_VOLTAGE: round(bus_voltage + shunt_voltage, 5), - ATTR_LOAD_VOLTAGE: round(bus_voltage, 5), - ATTR_SHUNT_VOLTAGE: round(shunt_voltage, 5), - ATTR_CURRENT: round(current / 1000, 5), - ATTR_POWER: round(power, 5), - ATTR_POWER_CALCULATED: round(power_calculated, 5), - ATTR_CHARGING: charging, - ATTR_ONLINE: online, - ATTR_REMAINING_BATTERY_CAPACITY: remaining_battery_capacity, - ATTR_REMAINING_TIME: remaining_time, - # ATTR_BATTERY_CONNECTED: battery_connected, - ATTR_LOW_BATTERY: low_battery, - } + def is_on(self): + return self._coordinator.data["charging"] diff --git a/examples/packages/ina219_ups_hat.yaml b/examples/packages/ina219_ups_hat.yaml deleted file mode 100644 index 03a3f45..0000000 --- a/examples/packages/ina219_ups_hat.yaml +++ /dev/null @@ -1,59 +0,0 @@ -ina219_ups_hat: - sensor: - - platform: ina219_ups_hat - name: Hassio UPS SoC - unique_id: hassio_ups - scan_interval: 30 - batteries_count: 3 - max_soc: 91 - battery_capacity: 9000 - sma_samples: 5 - - - platform: filter - name: "Hassio UPS SMA Load Voltage" - entity_id: sensor.hassio_ups_raw_load_voltage - unique_id: waveshare_ups_hat_sma_load_voltage - filters: - - filter: time_simple_moving_average - window_size: "00:01" - precision: 2 - - template: - - sensor: - - name: "Hassio UPS Raw PSU Voltage" - state: "{{ state_attr('sensor.hassio_ups', 'psu_voltage') | round(2) }}" - unit_of_measurement: "V" - state_class: measurement - - name: "Hassio UPS Raw Current" - state: "{{ state_attr('sensor.hassio_ups', 'current') * 1000 | round(1) }}" - unit_of_measurement: "mA" - state_class: measurement - - name: "Hassio UPS Raw Power" - state: "{{ state_attr('sensor.hassio_ups', 'power') | round(1) }}" - unit_of_measurement: "W" - state_class: measurement - - name: "Hassio UPS Raw Calculated Power" - state: "{{ state_attr('sensor.hassio_ups', 'power_calculated') | round(1) }}" - unit_of_measurement: "W" - state_class: measurement - - name: "Hassio UPS Raw Remaining Capacity" - state: "{{ state_attr('sensor.hassio_ups', 'remaining_battery_capacity') | round(0) }}" - unit_of_measurement: "mAh" - state_class: measurement - - name: "Hassio UPS Raw Remaining Time" - state: > - {% if is_state_attr('sensor.hassio_ups', 'remaining_time_min', '') %} - {{ state_attr('sensor.hassio_ups', 'remaining_time_min') }} - {% else %} - {{ state_attr('sensor.hassio_ups', 'remaining_time_min') | float(default='0') | round | int }} - {% endif %} - unit_of_measurement: "min" - - name: "Hassio UPS Raw Load Voltage" - state: "{{ state_attr('sensor.hassio_ups', 'load_voltage') | round(2) }}" - unit_of_measurement: "V" - - - binary_sensor: - - name: "Hassio UPS Online" - state: "{{ state_attr('sensor.hassio_ups', 'online') }}" - device_class: plug -