Skip to main content

Async library for accessing Dominion Energy SC API

Project description

dominion-sc-power

A Python library for accessing historical and forecasted energy usage and cost data for Dominion Energy South Carolina customers.

This library is used by the custom Home Assistant Integration for Dominion Energy SC.

Features

  • Retrieve historical energy usage data (electric and gas)
  • Get current bill forecasts with cost projections
  • Support for two-factor authentication (TFA)
  • Async/await architecture using aiohttp
  • Support for multiple energy sources (electric and gas)

Limitations

  • Only one service address per Dominion account is currently supported (mainly because I do not know what the API responses look like for users with multiple service addresses) - you will get an error if this applies to you - please report the error under issues which should include the relevant API response
  • TFA is required (again mainly because I do not know what the flow without TFA looks like) - report this error under issues if it applies to you
  • No explicit support for solar (grid export)
  • Data is delayed by 24-48 hours as this is when it is reported by Dominion
  • Some of the current implementation is a little clunky - will probably be refactored in a future update

Installation

  • Not yet available on PyPi (will be eventually) - for now see development environment instructions below.
pip install dominion-sc-power

Development

Setup Development Environment

# Clone and setup
git clone https://github.com/sctigercat1/dominion-sc-power.git
cd dominion-sc-power
./scripts/setup

Code Validation

After each change, please run the following scripts to format/check your code with ruff and run unit tests.

./scripts/lint
./scripts/test

Contributing

Contributions are welcome! Please submit a pull request with your proposed changes.

Command Line Interface

The library includes a CLI for quick data retrieval:

# Basic usage (will prompt for credentials)
python -m dominionsc

# With credentials
python -m dominionsc --username your_username --password your_password

# Get historical data and save to CSV
python -m dominionsc --start_date 2025-02-01 --end_date 2025-02-08 --csv output.csv

# Store TFA token for reuse
python -m dominionsc --login_data_file data.json

# Verbose logging
python -m dominionsc -vv

CLI Arguments

  • --username: Username for the utility website
  • --password: Password for the utility website
  • --login_data_file: JSON file to store/load TFA tokens
  • --start_date: Start date for historical data (ISO format, default: 7 days ago)
  • --end_date: End date for historical data (ISO format, default: now)
  • --csv: Output CSV file path for usage data
  • -v, --verbose: Enable verbose logging (use multiple times for more verbosity)

Sample Implementation

import asyncio
import aiohttp
from dominionsc import DominionSC, create_cookie_jar
from datetime import datetime, timedelta

async def main():
    username = "your_username"
    password = "your_password"
    
    async with aiohttp.ClientSession(cookie_jar=create_cookie_jar()) as session:
        client = DominionSC(session, username, password)
        
        # Login
        await client.async_login()
        
        # ** Handle TFA (see below) **
        
        # Get forecast
        forecast = await client.async_get_forecast()
        print(f"Forecasted cost: ${forecast.forecasted_cost}")
        
        # Get usage data
        accounts = await client.async_get_accounts()
        for account in accounts[0]:
            # accounts[1] is the service address
            # each account is in ['ELECTRIC' or 'GAS']
            usage = await client.async_get_usage_reads(
                account,
                start_date=datetime.now() - timedelta(days=7),
                end_date=datetime.now()
            )
            for reading in usage:
                print(f"{reading.start_time}: {reading.consumption} Wh")

asyncio.run(main())

Handling two-Factor Authentication (TFA)

If your account has TFA enabled (see limitations above), you'll need to handle the MfaChallenge exception:

from dominionsc import MfaChallenge, InvalidAuth

try:
    await client.async_login()
except MfaChallenge as e:
    handler = e.handler
    
    # Get available TFA options
    options = await handler.async_get_tfa_options()
    print("Available TFA methods:", options)
    
    # Select an option (e.g., SMS or email)
    option_id = list(options.keys())[0]
    await handler.async_select_tfa_option(option_id)
    
    # Get code from user
    code = input("Enter the security code: ")
    
    # Submit code and get login data for future use
    login_data = await handler.async_submit_tfa_code(code)
    
    # Save login_data to skip TFA next time
    # Pass it as: DominionSC(session, username, password, login_data)
    
    # Retry login
    client.login_data = login_data
    await client.async_login()

Credits

This project was inspired by Opower. Much appreciated!

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Disclaimer

This is an unofficial integration and is not affiliated with, endorsed by, or connected to Dominion Energy SC. Use at your own risk. The authors are not responsible for any issues that may arise from using this integration.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dominion_sc_power-0.0.1.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dominion_sc_power-0.0.1-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file dominion_sc_power-0.0.1.tar.gz.

File metadata

  • Download URL: dominion_sc_power-0.0.1.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dominion_sc_power-0.0.1.tar.gz
Algorithm Hash digest
SHA256 54d3fb1385291a40533e9b51e3d3c1ef3ca4f4c106d6d793af1c6a5c260cb291
MD5 6e8cde2ae27a0c5a45acfc2ba2e38af7
BLAKE2b-256 08b3deffb7b31b2bc01d8f161a80a096af5592421afaf14ef322f699c46e3e65

See more details on using hashes here.

Provenance

The following attestation bundles were made for dominion_sc_power-0.0.1.tar.gz:

Publisher: python-publish.yaml on sctigercat1/dominion-sc-power

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dominion_sc_power-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dominion_sc_power-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b471fcfd388f1996594e93a6e6b7d5b375042f58b50166030a145c15d8a8aa8
MD5 363db8b3d3865e2448e9712c56384094
BLAKE2b-256 8f098a6a9807e431d3f9104b947ce61f7086199396351d95992320510be7e81d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dominion_sc_power-0.0.1-py3-none-any.whl:

Publisher: python-publish.yaml on sctigercat1/dominion-sc-power

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page