Skip to content

Commit

Permalink
v0.3.9 (#19)
Browse files Browse the repository at this point in the history
fix: Config format changed to single platform
  • Loading branch information
odya authored Jul 7, 2024
1 parent 3d27662 commit 00cffcc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
35 changes: 16 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@ In the end your file structure should look like that:
Create a new sensor entry in your `configuration.yaml`

```yaml
sensor:
- platform: ina219_ups_hat
name: Hassio UPS # Optional
unique_id: hassio_ups # Optional
scan_interval: 60 # Optional
addr: 0x41 # Required
batteries_count: 3 # Optional
max_soc: 91 # Optional
battery_capacity: 9000 # Optional
sma_samples: 5 # Optional
min_online_current: -100 # Optional, mA
min_charging_current: 55 # Optional, mA
ina219_ups_hat:
name: Hassio UPS # Optional
unique_id: hassio_ups # Optional
addr: 0x41 # Required
scan_interval: 60 # Optional
batteries_count: 3 # Optional
max_soc: 91 # Optional
battery_capacity: 9000 # Optional
sma_samples: 5 # Optional
min_online_current: -100 # Optional, mA
min_charging_current: 50 # Optional, mA
```
Following data can be read:
Expand All @@ -69,20 +68,18 @@ Following data can be read:
If you consistently experience capacity below 100% when the device is fully charged, you can adjust it using the `max_soc` property.

```yaml
sensor:
- platform: ina219_ups_hat
max_soc: 91
ina219_ups_hat:
max_soc: 91
```

#### SMA Filtering

By default, the SMA5 filter is applied to the measurements from INA219. That's necessary to filter out noise from the switching power supply and provide smoother readings. You can control the window size with the `sma_samples` property.

```yaml
sensor:
- platform: ina219_ups_hat
max_soc: 91
sma_samples: 10
ina219_ups_hat:
max_soc: 91
sma_samples: 10
```

*Tip:* Doubled window size is used for calculation of SoC, Remaining Battery Capacity and Remaining Time
Expand Down
12 changes: 10 additions & 2 deletions custom_components/ina219_ups_hat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""INA219 UPS Hat"""
from __future__ import annotations
from datetime import timedelta
import json

from homeassistant.core import HomeAssistant
Expand All @@ -15,8 +16,14 @@
async def async_setup(hass: HomeAssistant, config: ConfigType):
"""Your controller/hub specific code."""

c = config.get("sensor")[0]
sensor_config: ConfigType = ConfigType(c)
if DOMAIN not in config:
return False

sensor_config: ConfigType = config[DOMAIN]

if CONF_SCAN_INTERVAL not in sensor_config:
return False
sensor_config[CONF_SCAN_INTERVAL] = timedelta(seconds=sensor_config[CONF_SCAN_INTERVAL])

coordinator = INA219UpsHatCoordinator(hass, sensor_config)
await coordinator.async_refresh()
Expand All @@ -32,6 +39,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType):
async def async_update_data(now):
await coordinator.async_request_refresh()

i = sensor_config.get(CONF_SCAN_INTERVAL)
async_track_time_interval(hass, async_update_data,
sensor_config.get(CONF_SCAN_INTERVAL))

Expand Down
2 changes: 1 addition & 1 deletion custom_components/ina219_ups_hat/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.8"
"version": "0.3.9"
}

0 comments on commit 00cffcc

Please sign in to comment.