Fetch free electricity sessions from Octopus Energy using email scraping and the GraphQL API.
pip install -r requirements.txt
export OCTOPUS_API_KEY="sk_live_your_key_here"
# Optional: export OCTOPUS_ACCOUNT_NUMBER="A-12345678"
# Optional: export OCTOPUS_MPAN="1234567890123"
Get your API key from: https://octopus.energy/dashboard/new/accounts/personal-details/api-access
Account number is auto-discovered The script will automatically discover your account number from the authenticated API key. If you have multiple accounts, set OCTOPUS_ACCOUNT_NUMBER to specify which one to use.
MPAN is auto-discovered The script will automatically fetch your electricity meter point(s) from the account. If you have multiple properties, set OCTOPUS_MPAN to specify which one to use.
Note: The script automatically filters for IMPORT meters (electricity consumption) and ignores EXPORT meters (e.g., solar generation). If you have solar panels, you’ll have both types, but only the import meter is relevant for free electricity sessions.
The script uses the Octopus Energy GraphQL API with token-based authentication:
obtainKrakenToken mutationAuthorization header for subsequent requestsThe script requires only your API key! Account number and MPAN are auto-discovered.
export OCTOPUS_API_KEY="sk_live_your_key"
python fes_finder_graphql.py
Output:
Authenticating with Octopus Energy API using API key...
No account number provided, auto-discovering from authenticated user...
Auto-discovered account number: A-12345678
No MPAN provided, fetching from account...
Using MPAN: 1234567890123
Fetching free electricity sessions...
Found 15 free electricity session(s):
...
If you have multiple accounts or properties, you can specify which to use:
export OCTOPUS_API_KEY="sk_live_your_key"
export OCTOPUS_ACCOUNT_NUMBER="A-12345678" # Optional: specify account
export OCTOPUS_MPAN="1234567890123" # Optional: specify property
python fes_finder_graphql.py
export OUTPUT_FORMAT="json"
python fes_finder_graphql.py
The script automatically writes future sessions to a JSON file matching the Google Apps Script format:
free_electricity_session_graphql.json (at the repository root)start, end, and code fieldsend time in the futurestart time (earliest first)[{"start": null, "end": null, "code": null}]start: ISO 8601 timestamp (UTC) when the free electricity session beginsend: ISO 8601 timestamp (UTC) when the free electricity session endscode: Unique event identifier assigned by Octopus Energy (e.g., FREE_ELECTRICITY_EVENT_15_251025). This code is used internally by Octopus to track specific flexibility events and can be useful for logging, debugging, or correlating events with Octopus communicationsExample output with sessions:
[
{
"start": "2025-10-25T11:00:00+00:00",
"end": "2025-10-25T14:00:00+00:00",
"code": "FREE_ELECTRICITY_EVENT_15_251025"
},
{
"start": "2025-10-24T20:00:00+00:00",
"end": "2025-10-24T21:00:00+00:00",
"code": "FREE_ELECTRICITY_EVENT_14_241025"
}
]
Example output with no future sessions:
[
{
"start": null,
"end": null,
"code": null
}
]
This file is committed to the repository and automatically updated by GitHub Actions, so you can access the latest free electricity sessions at:
https://raw.githubusercontent.com/8none1/octopus_powerups/graphql/free_electricity_session_graphql.json
Add this secret to your repository:
OCTOPUS_API_KEY (required)Optional secrets (only if you have multiple accounts/properties):
OCTOPUS_ACCOUNT_NUMBER (optional - auto-discovered from API key)OCTOPUS_MPAN (optional - auto-discovered from account)The workflow will run every 6 hours automatically, or you can trigger it manually from the Actions tab.