11# Open Octopus 🐙
22
3- Modern async Python client for the ** Octopus Energy GraphQL API** .
4-
5- Supports features not available in the REST API:
6- - ⚡ ** Live power consumption** (requires Home Mini)
7- - 🔌 ** Intelligent Octopus dispatch slots**
8- - 🎁 ** Saving Sessions** / Free Electricity events
9- - 💰 ** Account balance** and tariff info
10- - 🖥️ ** macOS menu bar app** for live monitoring
11- - 🤖 ** Claude AI agent** for natural language queries
12-
13- ## Installation
3+ Modern async Python client for the ** Octopus Energy API** .
144
155``` bash
16- # Core library
176pip install open-octopus
7+ ```
188
19- # With macOS menu bar app
20- pip install ' open-octopus[menubar]'
21-
22- # With Claude AI agent
23- pip install ' open-octopus[agent]'
9+ ## Features
2410
25- # Everything
26- pip install ' open-octopus[all]'
27- ```
11+ - ⚡ ** Live power** - Real-time consumption (Home Mini)
12+ - 🔌 ** Smart charging** - Intelligent Octopus dispatch slots
13+ - 🎁 ** Saving Sessions** - Free electricity events
14+ - 🔥 ** Dual fuel** - Electricity + gas support
15+ - 🤖 ** AI agent** - Natural language queries
16+ - 🖥️ ** Menu bar** - macOS status bar app
2817
2918## Quick Start
3019
@@ -37,245 +26,117 @@ async def main():
3726 api_key = " sk_live_xxx" ,
3827 account = " A-XXXXXXXX"
3928 ) as client:
40- # Get account balance
29+ # Account
4130 account = await client.get_account()
4231 print (f " Balance: £ { account.balance:.2f } " )
4332
44- # Get current rate
33+ # Current rate
4534 tariff = await client.get_tariff()
4635 rate = client.get_current_rate(tariff)
47- print (f " Rate: { rate.rate} p/kWh ( { ' off-peak' if rate.is_off_peak else ' peak' } ) " )
36+ print (f " Rate: { rate.rate} p ( { ' off-peak' if rate.is_off_peak else ' peak' } ) " )
4837
49- # Get live power (requires Home Mini)
38+ # Live power (requires Home Mini)
5039 power = await client.get_live_power()
5140 if power:
52- print (f " Current draw : { power.demand_kw:.2f } kW " )
41+ print (f " Power : { power.demand_kw:.2f } kW " )
5342
5443asyncio.run(main())
5544```
5645
57- ## CLI Usage
46+ ## Environment Variables
5847
5948``` bash
60- # Set environment variables
49+ # Required
6150export OCTOPUS_API_KEY=" sk_live_xxx"
6251export OCTOPUS_ACCOUNT=" A-XXXXXXXX"
63- export OCTOPUS_MPAN=" 1234567890123" # Optional, for consumption data
64- export OCTOPUS_METER_SERIAL=" 12A3456789" # Optional
65-
66- # Show account info
67- octopus account
68-
69- # Show current rate
70- octopus rate
71-
72- # Show dispatch status (Intelligent Octopus)
73- octopus dispatch
74-
75- # Show live power consumption
76- octopus power
77-
78- # Show upcoming saving sessions
79- octopus sessions
80-
81- # Show daily usage
82- octopus usage --days 7
83-
84- # Full status overview
85- octopus status
86-
87- # Watch live power (updates every 30s)
88- octopus watch
89- ```
90-
91- ## Features
92-
93- ### Account & Billing
94-
95- ``` python
96- account = await client.get_account()
97- print (f " Name: { account.name} " )
98- print (f " Balance: £ { account.balance:.2f } " )
99- print (f " Status: { account.status} " )
100- ```
101-
102- ### Tariff & Rates
103-
104- ``` python
105- tariff = await client.get_tariff()
106- print (f " Tariff: { tariff.name} " )
107- print (f " Standing charge: { tariff.standing_charge} p/day " )
108-
109- # Get current rate with time-of-use info
110- rate = client.get_current_rate(tariff)
111- print (f " Current: { rate.rate} p/kWh " )
112- print (f " Off-peak: { rate.is_off_peak} " )
113- print (f " Changes at: { rate.period_end} " )
114- ```
115-
116- ### Consumption Data
117-
118- ``` python
119- # Get last 48 half-hourly readings
120- consumption = await client.get_consumption(periods = 48 )
121- for c in consumption:
122- print (f " { c.start} : { c.kwh:.3f } kWh " )
123-
124- # Get daily totals
125- daily = await client.get_daily_usage(days = 7 )
126- for date, kwh in daily.items():
127- print (f " { date} : { kwh:.1f } kWh " )
128- ```
129-
130- ### Intelligent Octopus Dispatches
131-
132- ``` python
133- # Check if currently charging
134- status = await client.get_dispatch_status()
135- if status.is_dispatching:
136- print (f " Charging until { status.current_dispatch.end} " )
137- elif status.next_dispatch:
138- print (f " Next charge: { status.next_dispatch.start} " )
139-
140- # Get all scheduled dispatches
141- dispatches = await client.get_dispatches()
142- for d in dispatches:
143- print (f " { d.start} - { d.end} ( { d.duration_minutes} min) " )
144- ```
145-
146- ### Saving Sessions
14752
148- ``` python
149- sessions = await client.get_saving_sessions()
150- for s in sessions:
151- if s.is_active:
152- print (f " FREE POWER until { s.end} ! " )
153- else :
154- print (f " Upcoming: { s.start} - { s.end} " )
155- print (f " Reward: { s.reward_per_kwh} Octopoints/kWh " )
156- ```
53+ # Electricity meter (optional)
54+ export OCTOPUS_MPAN=" 1234567890123"
55+ export OCTOPUS_METER_SERIAL=" 12A3456789"
15756
158- ### Live Power (Home Mini)
57+ # Gas meter (optional)
58+ export OCTOPUS_GAS_MPRN=" 1234567890"
59+ export OCTOPUS_GAS_METER_SERIAL=" G4A12345"
15960
160- Requires a [ Home Mini] ( https://octopus.energy/blog/home-mini/ ) paired with your smart meter.
161-
162- ``` python
163- power = await client.get_live_power()
164- if power:
165- print (f " Demand: { power.demand_watts} W " )
166- print (f " Read at: { power.read_at} " )
167-
168- # Calculate cost per hour
169- tariff = await client.get_tariff()
170- rate = client.get_current_rate(tariff)
171- cost_per_hour = (power.demand_watts / 1000 ) * rate.rate
172- print (f " Cost: { cost_per_hour:.1f } p/hour " )
61+ # AI agent (optional)
62+ export ANTHROPIC_API_KEY=" sk-ant-xxx"
17363```
17464
175- ## macOS Menu Bar App
176-
177- Live energy monitoring in your menu bar:
65+ ## CLI
17866
17967``` bash
180- # Install with menubar support
181- pip install ' open-octopus[menubar]'
182-
183- # Run
184- octopus-menubar
68+ octopus status # Full overview
69+ octopus rate # Current rate
70+ octopus power # Live consumption
71+ octopus dispatch # Charging status
72+ octopus usage # Daily usage
73+ octopus gas # Gas usage
18574```
18675
187- Shows:
188- - ⚡ Live power consumption (with Home Mini)
189- - 🌙/☀️ Current rate (off-peak/peak)
190- - 🔌 Charging status (Intelligent Octopus)
191- - 🎁 Saving Sessions alerts
192- - 💰 Account balance
193-
194- ## Claude AI Agent
76+ ## AI Agent
19577
196- Ask questions about your energy in plain English:
78+ Ask questions in plain English:
19779
19880``` bash
199- # Install with agent support
20081pip install ' open-octopus[agent]'
20182
202- # Set your Anthropic API key
203- export ANTHROPIC_API_KEY=" sk-ant-xxx"
204-
205- # Ask questions
206- octopus-ask " What's my current power usage?"
83+ octopus-ask " What's my current rate?"
84+ octopus-ask " How much gas did I use yesterday?"
20785octopus-ask " When is my next charging window?"
208- octopus-ask " How much did I use yesterday?"
209- octopus-ask " Am I on off-peak rates right now?"
21086```
21187
212- Or use in Python:
88+ ## Gas Support
21389
21490``` python
215- from open_octopus import OctopusAgent
216- import asyncio
217-
218- async def main ():
219- agent = OctopusAgent()
220- response = await agent.ask(" What's my current rate?" )
221- print (response)
222-
223- asyncio.run(main())
91+ async with OctopusClient(
92+ api_key = " sk_live_xxx" ,
93+ account = " A-XXXXXXXX" ,
94+ gas_mprn = " 1234567890" ,
95+ gas_meter_serial = " G4A12345"
96+ ) as client:
97+ # Gas consumption
98+ gas = await client.get_gas_consumption(periods = 48 )
99+ for reading in gas:
100+ print (f " { reading.start} : { reading.kwh:.2f } kWh " )
101+
102+ # Gas tariff
103+ tariff = await client.get_gas_tariff()
104+ print (f " Rate: { tariff.unit_rate} p/kWh " )
105+
106+ # Daily gas usage
107+ daily = await client.get_daily_gas_usage(days = 7 )
108+ for date, kwh in daily.items():
109+ print (f " { date} : { kwh:.1f } kWh " )
224110```
225111
226- ## Configuration
227-
228- ### Environment Variables
229-
230- | Variable | Required | Description |
231- | ----------| ----------| -------------|
232- | ` OCTOPUS_API_KEY ` | Yes | API key from Octopus dashboard |
233- | ` OCTOPUS_ACCOUNT ` | Yes | Account number (e.g., A-FB05ED6C) |
234- | ` OCTOPUS_MPAN ` | No | Meter Point Admin Number (for consumption) |
235- | ` OCTOPUS_METER_SERIAL ` | No | Electricity meter serial number |
236- | ` ANTHROPIC_API_KEY ` | For agent | Anthropic API key (for octopus-ask) |
237-
238- ### Getting Your API Key
239-
240- 1 . Log in to [ Octopus Energy] ( https://octopus.energy/dashboard/ )
241- 2 . Go to ** Developer Settings**
242- 3 . Copy your API key (starts with ` sk_live_ ` )
243-
244- ### Finding Your MPAN
112+ ## Menu Bar (macOS)
245113
246- Your MPAN is on your electricity bill, or run:
247-
248- ``` python
249- # The API can discover your meter points
250- account = await client.get_account()
251- print (account) # Includes property info
114+ ``` bash
115+ pip install ' open-octopus[menubar]'
116+ octopus-menubar
252117```
253118
254- ## Comparison with Other Libraries
255-
256- | Feature | open-octopus | octopus-energy | Home Assistant |
257- | ---------| --------------| ----------------| ----------------|
258- | REST API | ✅ | ✅ | ✅ |
259- | GraphQL API | ✅ | ❌ | ✅ |
260- | Live power (Home Mini) | ✅ | ❌ | ✅ |
261- | Intelligent dispatches | ✅ | ❌ | ✅ |
262- | Saving sessions | ✅ | ❌ | ✅ |
263- | Account balance | ✅ | ❌ | ✅ |
264- | Standalone library | ✅ | ✅ | ❌ |
265- | CLI tool | ✅ | ❌ | ❌ |
266- | Async/await | ✅ | ✅ | ❌ |
267- | Typed models | ✅ | ❌ | ❌ |
268-
269- ## License
119+ Shows live power, current rate, charging status, and balance.
270120
271- MIT License - see [ LICENSE ] ( LICENSE ) for details.
121+ ## API Reference
272122
273- ## Contributing
123+ ### Client Methods
274124
275- Contributions welcome! Please read [ CONTRIBUTING.md] ( CONTRIBUTING.md ) first.
125+ | Method | Description |
126+ | --------| -------------|
127+ | ` get_account() ` | Account info and balance |
128+ | ` get_tariff() ` | Electricity tariff details |
129+ | ` get_current_rate(tariff) ` | Current rate with off-peak status |
130+ | ` get_consumption() ` | Half-hourly electricity readings |
131+ | ` get_daily_usage() ` | Daily electricity totals |
132+ | ` get_live_power() ` | Real-time power (Home Mini) |
133+ | ` get_dispatches() ` | Intelligent Octopus charge slots |
134+ | ` get_dispatch_status() ` | Current charging status |
135+ | ` get_saving_sessions() ` | Free electricity events |
136+ | ` get_gas_consumption() ` | Half-hourly gas readings |
137+ | ` get_daily_gas_usage() ` | Daily gas totals |
138+ | ` get_gas_tariff() ` | Gas tariff details |
276139
277- ## Links
140+ ## License
278141
279- - [ Octopus Energy Developer API] ( https://developer.octopus.energy/ )
280- - [ GraphQL API Documentation] ( https://developer.octopus.energy/graphql/ )
281- - [ Report Issues] ( https://github.com/abracadabra50/open-octopus/issues )
142+ MIT
0 commit comments