How tinohox/iona-ha works
Purpose and runtime
This is a HACS-distributed custom integration for Home Assistant 2024.11+. It exposes iONA smart-meter readings as Home Assistant entities, preferentially polling an iONA Box on the local network and falling back to enviaM web services. It optionally supports dynamic “mein Strom Vision” tariff pricing and scheduling optimization.
Core integration metadata and HA loading are rooted in manifest.json, __init__.py, and const.py.
Setup and lifecycle entry points
Home Assistant discovers the integration through its manifest and initializes it through the integration module. UI-driven onboarding and runtime option changes are handled by the config-flow layer; credentials are stored in Home Assistant’s ConfigEntry storage rather than ordinary integration configuration.
• __init__.py
• config_flow.py
• const.py
Configuration controls local-box address/credentials, LAN and web polling intervals, and optional Vision features.
Acquisition and source failover
Meter acquisition has two explicit adapters: LAN access to the physical iONA Box and a web/API path. The intended control flow is LAN-first at a short interval; connection failures cause web polling at a longer interval; recovery returns the active source to LAN. Token modules isolate authentication for the respective remote/local API interactions.
• app/get_lan_data.py
• app/get_web_data.py
• app/get_lan_token.py
• app/get_web_token.py
This is the primary reliability boundary: local-network availability affects live data, while web access is an external-service fallback.
Central data coordination and persistence
data_manager.py is the likely integration-level coordination boundary between acquisition, entity updates, source state, and optional tariff data. Runtime files appear to be kept under app/data and app/env; environment backup/restore utilities protect token/configuration files from HACS overwrites.
• data_manager.py
• env_backup.py
• env_utils.py
• app/data/.gitkeep
• app/env/.gitkeep
The Home Assistant ConfigEntry remains the authoritative credential/configuration boundary; filesystem state supports tokens and recoverable integration-local data.
Home Assistant entity surface
Platform modules map coordinated readings and optimization state into HA entities. Sensors provide meter totals, instantaneous power, data source, and tariff/optimization outputs; number, switch, and button entities provide the Vision Tools controls and recalculation trigger.
• sensor.py
• number.py
• switch.py
• button.py
This boundary makes energy data compatible with Home Assistant’s Energy Dashboard and gives automations timestamp-oriented optimization results rather than directly controlling appliances.
Vision tariff and optimization pipeline
The optional Vision path retrieves quarter-hour spot prices and contract tariff inputs, calculates end-user prices, then searches available future intervals for the lowest-average contiguous window. It is separate from core meter operation, so tariff-service failures should not prevent LAN/web meter updates.
• app/get_spot_prices.py
• app/get_tariff_data.py
• app/calc_preise.py
• app/vision.py
External dependencies are enviaM tariff/web APIs and the iONA Box; the optimization consumes derived price series and user-configured duration, horizon, delay, and night-only constraints.
Frontend delivery
The integration bundles Lovelace custom cards for power/meter visualization and Vision Tools control. These are browser-side Home Assistant dashboard resources, distinct from the Python entity and polling runtime.
• www/iona-card.js
• www/iona-vision-card.js
Localization for the HA configuration/UI is supplied through strings.json and translations/.
Main entry points: data_manager.py Data manager · get_lan_data.py iONA Box LAN adapter · get_web_data.py enviaM web adapter · calc_preise.py End-user price calculation
Components 20
Home Assistant integration
- Integration lifecycle · Manifest-driven setup and runtime lifecycle.
__init__.py - Config flow · Collects connection settings and Vision options.
config_flow.py - Integration constants
const.py - ConfigEntry storage · Authoritative credentials and user configuration.
- Data manager · Coordinates readings, source state, entity updates, and optional tariff data.
data_manager.py - HA entity platforms · Publishes meter, source, tariff, and optimization entities.
sensor.py - Vision controls · Accepts optimization constraints and recalculation requests.
number.py
Meter acquisition
- iONA Box LAN adapter · Preferred short-interval local polling path.
app/get_lan_data.py - LAN token
app/get_lan_token.py - iONA Box
- enviaM web adapter · Longer-interval fallback when LAN access fails.
app/get_web_data.py - Web token
app/get_web_token.py - enviaM web APIs
Vision pricing
Optional tariff and scheduling pipeline.
- Spot price retrieval
app/get_spot_prices.py - Contract tariff retrieval
app/get_tariff_data.py - End-user price calculation
app/calc_preise.py - Vision optimizer · Finds the lowest-average future contiguous interval.
app/vision.py
Runtime state
- Runtime files · Recoverable integration-local tokens and data.
app/data/.gitkeep - Environment backup · Backs up and restores runtime files across HACS updates.
env_backup.py
Dashboard delivery
- Lovelace cards · Custom power, meter, and Vision Tools interfaces.
www/iona-card.js
Connections 22
- Integration lifecycle → Config flow: starts setup
- Config flow → ConfigEntry storage: stores settings
- Integration lifecycle → Data manager: initializes
- Integration constants → Data manager: defines shared settings
- ConfigEntry storage → Data manager: provides configuration
- Data manager → iONA Box LAN adapter: polls first
- LAN token → iONA Box LAN adapter: authenticates
- iONA Box LAN adapter → iONA Box: reads meter
- Data manager → enviaM web adapter: falls back on LAN failure
- Web token → enviaM web adapter: authenticates
- enviaM web adapter → enviaM web APIs: retrieves readings
- Data manager → HA entity platforms: updates entities
- Vision controls → Data manager: supplies constraints and triggers
- Data manager → Spot price retrieval: requests optional prices
- Data manager → Contract tariff retrieval: requests tariff inputs
- Spot price retrieval → End-user price calculation: price series
- Contract tariff retrieval → End-user price calculation: contract inputs
- End-user price calculation → Vision optimizer: derived prices
- Vision optimizer → Data manager: optimization result
- Data manager → Runtime files: persists local state
- Environment backup → Runtime files: backs up and restores
- HA entity platforms → Lovelace cards: dashboard state and controls