A Home Assistant custom integration to monitor your Tenaga Nasional Berhad (TNB) smart meter energy usage and costs.
- Monitor energy usage (kWh) from your TNB smart meter
- Monitor energy costs (MYR)
- Automatic updates every 30 minutes
- Configurable via Home Assistant UI
- Supports HACS installation
- Install HACS if you haven't already
- Go to HACS → Integrations
- Click the three dots menu (⋮) → Custom repositories
- Add this repository URL:
https://github.com/feiming/homeassistant-MyTNB - Select category: Integration
- Click Add
- Search for "MyTNB" in HACS and install it
- Restart Home Assistant
- Copy the
mytnbfolder fromcustom_components/mytnbto your Home Assistantcustom_componentsdirectory:<config>/custom_components/mytnb/ - Restart Home Assistant
- Add the integration via Settings → Devices & Services → Add Integration
- Go to Settings → Devices & Services → Add Integration
- Search for "Tenaga Nasional" or "MyTNB"
- Enter your MyTNB account credentials:
- Username: Your MyTNB email address
- Password: Your MyTNB password
- Smart Meter URL: The full URL to your smart meter page (found in your MyTNB account dashboard)
- Log in to MyTNB
- Navigate to Account Management → Smart Meter
- Copy the full URL from your browser's address bar (it should look like:
https://myaccount.mytnb.com.my/AccountManagement/SmartMeter/Index/TRIL?caNo=...) - Paste it into the Smart Meter URL field during setup
The integration creates the following sensors:
sensor.energy_usage: Total energy consumption in kWh (state class: total_increasing)sensor.energy_cost: Total energy cost in MYR (state class: total_increasing)
Both sensors:
- Update every 30 minutes
- Show data from the last 7 days
- Include attributes:
sdpudcid,metric,view,granularity
If you encounter authentication errors:
- Verify your username and password are correct
- Ensure your Smart Meter URL is the complete URL including all query parameters
- Check that you can log in to the MyTNB website manually
- Try logging out and back in to MyTNB website to refresh your session
If you see connection errors:
- Check your internet connection
- Verify the Smart Meter URL is correct and accessible
- Check Home Assistant logs for more details
If sensors show "unknown" or no data:
- Wait a few minutes for the first update (up to 30 minutes)
- Check Home Assistant logs for API errors
- Verify your smart meter is active and reporting data on the MyTNB website
This integration was converted from a standalone Python script (get_smartmeter_data.py) into a Home Assistant custom integration.
homeassistant-MyTNB/
├── custom_components/
│ └── mytnb/
│ ├── __init__.py # Integration setup
│ ├── manifest.json # Integration metadata
│ ├── config_flow.py # UI configuration flow
│ ├── sensor.py # Sensor platform
│ ├── api.py # MyTNB API client
│ ├── const.py # Constants
│ ├── strings.json # UI strings
│ └── translations/ # Translation files
├── hacs.json # HACS metadata
├── info.md # HACS info page
└── README.md # This file
For issues and feature requests, please visit the GitHub repository.
See LICENSE file for details.