How salihinsaealal/home-assistant-tnb-calculator works
TNB Calculator is a Home Assistant integration for estimating Malaysian electricity bills from household energy sensors. Users configure import/export entities and tariff options; the integration tracks usage, applies ToU or non-ToU billing and AFA/NEM adjustments, then exposes costs, history, optimization, and diagnostics as Home Assistant entities. A companion scraper serves AFA and tariff data. The excerpts show coordinator ownership, spike handling, and API routes, but not the full calculation or storage implementation; those links are limited accordingly.
Main entry points: sensor.py Usage coordinator · __init__.py Integration lifecycle and services · config_flow.py Integration setup · main.py AFA and tariff API
Components 16
Setup and Control
- Integration setup
custom_components/tnb_calculator/config_flow.py - Integration lifecycle and services
custom_components/tnb_calculator/__init__.py
Usage and Billing
- Usage coordinator
custom_components/tnb_calculator/sensor.py - Billing and optimization
custom_components/tnb_calculator/sensor.py - Persisted usage and tariff state
custom_components/tnb_calculator/sensor.py
Home Assistant Entities
- Tariff and spike controls
custom_components/tnb_calculator/button.py - Auto-fetch switch
custom_components/tnb_calculator/switch.py - AFA URL setting
custom_components/tnb_calculator/text.py - Billing and diagnostic sensors
custom_components/tnb_calculator/sensor.py - Dashboard
dashboards/tnb_calculator_dashboard.yaml - AFA update automation
blueprints/automation/tnb_calculator/auto_update_afa_rate.yaml
Rate Service
- AFA and tariff API
tnb-afa-scraper/main.py
Other components
- Home Assistant user
- Energy sensors
- Home Assistant
- TNB rate source
Connections 16
- Home Assistant user → Integration setup: configures
custom_components/tnb_calculator/config_flow.py - Integration setup → Integration lifecycle and services: creates entry
custom_components/tnb_calculator/config_flow.py - Integration lifecycle and services → Usage coordinator: initializes
custom_components/tnb_calculator/__init__.py - Integration lifecycle and services → Billing and diagnostic sensors: forwards platforms
custom_components/tnb_calculator/__init__.py - Energy sensors → Usage coordinator: provides readings
- Usage coordinator → Billing and optimization: calculates bills
custom_components/tnb_calculator/sensor.py - Usage coordinator → Persisted usage and tariff state: persists data
custom_components/tnb_calculator/sensor.py - Billing and optimization → Billing and diagnostic sensors: supplies sensor values
custom_components/tnb_calculator/sensor.py - Integration lifecycle and services → Usage coordinator: dispatches services
custom_components/tnb_calculator/__init__.py - Tariff and spike controls → Usage coordinator: accepts spike
custom_components/tnb_calculator/button.py - Auto-fetch switch → Usage coordinator: toggles fetching
custom_components/tnb_calculator/switch.py - AFA URL setting → Persisted usage and tariff state: saves URL
custom_components/tnb_calculator/text.py - Usage coordinator → AFA and tariff API: fetches tariffs
custom_components/tnb_calculator/sensor.py - AFA and tariff API → TNB rate source: scrapes rates
tnb-afa-scraper/main.py - Dashboard → Billing and diagnostic sensors: presents entities
README.md - AFA update automation → Integration lifecycle and services: updates AFA
README.md