-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
330 lines (306 loc) · 17.8 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<?php
use Carbon\Carbon;
include('src/API.php');
include_once('vendor/autoload.php');
/**
* Edit this detail with your own from https://octopus.energy/dashboard/developer
*/
$api_key = '';
$account = 'A-';
$electricity_mpan = '';
$electricity_serial = '';
$gas_mprn = '';
$gas_serial = '';
$region = 'B';
$tz = "Europe/London";
$gas_unit_price = 2.9;
//===================================
$styles = [
'hourly_rates' => [
'cell' => "class='sm:w-1/4 lg:w-1/5 text-xs text-center justify-center align-middle'",
'cell_hideable' => "class='sm:w-1/4 lg:w-1/5 sm:hidden lg:block sm:text-md lg:text-xs text-center justify-center align-middle'",
],
'consumption' => [
'cell' => "class='sm:w-1/5 lg:w-1/6 text-xs text-center justify-center align-middle'",
'cell_hideable' => "class='sm:w-1/5 lg:w-1/6 sm:hidden lg:block sm:text-md lg:text-xs text-center justify-center align-middle'",
],
];
//create the API object
$api = new kayrah87\AgileOctopusAPI\API($account, $api_key, $tz);
//get the relevant data from the wrapper
$electricity_point = $api->getMeterPointDetails($electricity_mpan)['data'];
$electricity_consumption = $api->getMeterPointConsumption($electricity_mpan, $electricity_serial, Carbon::now($tz)
->subDays(3))['data'];
$gas_consumption = $api->getMeterPointConsumption($gas_mprn, $gas_serial, Carbon::now($tz)
->subDays(3))['data'];
?>
<head>
<title>Kayrah87/AgileOctopusAPI</title>
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-300">
<div class="flex flex-col w-full p-5">
<div class="mb-5 flex items-center p-3">
<h1 class="font-bold text-xl">Kayrah87/AgileOctopusAPI</h1>
</div>
<div class="mb-5 flex flex-col p-3">
<p>Welcome to the Agile Octopus API Wrapper.</p>
<p>This may be included in any PHP project and will soon be adapted for Laravel</p>
<h2 class="mt-3 mb-3 text-xl font-bold">Basic Usage</h2>
<p>installing Agile Octopus API is as simple as requiring it through composer</p>
<p class="bg-gray-400 p-3 rounded-md"><code>$ composer require kayrah87/agileoctopusapi</code></p>
<p>Once it is included in your project you can instantiate the API in your project thusly:</p>
<p class="bg-gray-400 p-3 rounded-md"><code>$api = new kayrah87\AgileOctopusAPI\API($account, $api_key,
$tz);</code></p>
<p><code>$account</code> is your Octopus account number</p>
<p><code>$api_key</code> is your Octopus API key</p>
<p><code>$tz</code> is your Timezone, most usually 'Europe/London' but Octopus is available in other countries
now, so might be worth checking.</p>
</div>
<h2 class="ml-3 mt-3 mb-3 text-xl font-bold">Examples</h2>
<div class="ml-3 mb-5 flex items-center mr-2">
<div class="lg:w-1/2 w-full">
<p class="bg-gray-400 p-3 rounded-md mt-3 mb-3"><code>$api->getElectricityPrice($region)</code></p>
<p class="mb-2"><code>$region</code> is the DNO code from the region you wish to get the price for. For more
information or if you are not sure, see <a
href="https://www.energy-stats.uk/dno-region-codes-explained/"
class="text-yellow-600 hover:text-yellow-500">energy-stats.uk</a></p>
<div class="widget w-full p-4 rounded-lg bg-white border border-gray-100 dark:bg-gray-900 dark:border-gray-800">
<div class="flex flex-row items-center justify-between">
<div class="flex flex-col">
<div class="text-xs uppercase font-light text-gray-500">
Current Electricity Price
</div>
<div class="text-xl font-bold">
<?php
echo $api->getElectricityPrice($region)['data']." p/Kwh";
?>
</div>
</div>
<svg class="stroke-current text-gray-500" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewbox="0 0 24 24" width="24"
xmlns="http://www.w3.org/2000/svg">
<polyline points="22 12 18 12 15 21 9 3 6 12 2 12">
</polyline>
</svg>
</div>
</div>
</div>
</div>
<div class="ml-3 flex w-full justify-between flex-wrap">
<div class="lg:w-1/2 sm:w-full">
<div class="items-center mr-2 mb-2 widget p-4 rounded-lg bg-white border border-gray-100 dark:bg-gray-900 dark:border-gray-800">
<div class="p-2 text-lg font-bold"><h1>⚡ Half-Hourly Electricity Prices</h1></div>
<div class="mb-2 p-2 border-4 border-purple-300 rounded-lg">
<p>The half hourly electricity prices can be called using</p>
<p class="bg-gray-400 p-3 rounded-md mt-3 mb-3"><code>$api->getHalfHourlyRates($region)</code></p>
<p>where <code>$region</code> is the DNO for the desired region.</p>
</div>
<table class="text-left w-full">
<thead class="bg-black flex text-white w-full">
<tr class="flex w-full text-sm">
<th <?php
echo $styles['hourly_rates']['cell_hideable']; ?>>Date
</th>
<th <?php
echo $styles['hourly_rates']['cell']; ?>>From
</th>
<th <?php
echo $styles['hourly_rates']['cell']; ?>>To
</th>
<th <?php
echo $styles['hourly_rates']['cell']; ?>>Price inc. VAT
</th>
<th <?php
echo $styles['hourly_rates']['cell']; ?>>Pice exc. VAT
</th>
</tr>
</thead>
<tbody class="bg-grey-light flex flex-col items-center justify-between overflow-y-scroll w-full h-64">
<?php
foreach ($api->getHalfHourlyRates($region)['data'] as $rate) {
echo "<tr class=\"flex w-full pl-2\">
<td {$styles['hourly_rates']['cell_hideable']}>".Carbon::parse($rate->valid_from)
->format('d/m/Y')."</td>
<td {$styles['hourly_rates']['cell']}>".Carbon::parse($rate->valid_from)
->format('H:i')."</td>
<td {$styles['hourly_rates']['cell']}>".Carbon::parse($rate->valid_to)
->format('H:i')."</td>
<td {$styles['hourly_rates']['cell']}>".round($rate->value_inc_vat, 1)."</td>
<td {$styles['hourly_rates']['cell']}>".round($rate->value_exc_vat, 1)."</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
<div class="lg:w-1/2 sm:w-full">
<div class="items-center mr-2 mb-2 widget p-4 rounded-lg bg-white border border-gray-100 dark:bg-gray-900 dark:border-gray-800">
<div class="p-2 text-lg font-bold"><h1>⚡ Electricity Meter Point Details</h1></div>
<div class="mb-2 p-2 border-4 border-purple-300 rounded-lg">
<p>The meter point details (for electric only) can be called using</p>
<p class="bg-gray-400 p-3 rounded-md mt-3 mb-3">
<code>$api->getMeterPointDetails($electricity_mpan)</code></p>
<p>where <code>$electricity_mpan</code> is the mpan from your electricity meter found under your
developer dashboard.</p>
</div>
<ul class="flex flex-col p-4">
<li class="border-gray-400 flex flex-row mb-2">
<div class="bg-gray-200 rounded-md flex flex-1 items-center p-4 transition duration-500 ease-in-out transform hover:-translate-y-1 hover:shadow-lg">
<div class="flex flex-col rounded-md w-10 h-10 bg-gray-300 justify-center items-center mr-4">
⚡
</div>
<div class="flex-1 pl-1 mr-16">
<div class="font-medium">GSP</div>
</div>
<div class="text-gray-600 text-xs"><?php
echo $electricity_point->gsp ?? '' ?></div>
</div>
</li>
<li class="border-gray-400 flex flex-row mb-2">
<div class="bg-gray-200 rounded-md flex flex-1 items-center p-4 transition duration-500 ease-in-out transform hover:-translate-y-1 hover:shadow-lg">
<div class="flex flex-col rounded-md w-10 h-10 bg-gray-300 justify-center items-center mr-4">
⚡
</div>
<div class="flex-1 pl-1 mr-16">
<div class="font-medium">MPAN</div>
</div>
<div class="text-gray-600 text-xs"><?php
echo $electricity_point->mpan ?? '' ?></div>
</div>
</li>
<li class="border-gray-400 flex flex-row mb-2">
<div class="bg-gray-200 rounded-md flex flex-1 items-center p-4 transition duration-500 ease-in-out transform hover:-translate-y-1 hover:shadow-lg">
<div class="flex flex-col rounded-md w-10 h-10 bg-gray-300 justify-center items-center mr-4">
⚡
</div>
<div class="flex-1 pl-1 mr-16">
<div class="font-medium">Profile Class</div>
</div>
<div class="text-gray-600 text-xs"><?php
echo $electricity_point->profile_class ?? '' ?></div>
</div>
</li>
</ul>
</div>
</div>
<div class="lg:w-1/2 sm:w-full">
<div class="items-center mr-2 mb-2 widget p-4 rounded-lg bg-white border border-gray-100 dark:bg-gray-900 dark:border-gray-800">
<div class="p-2 text-lg font-bold"><h1>⚡ Electricity Meter Point Consumption</h1></div>
<div class="mb-2 p-2 border-4 border-purple-300 rounded-lg">
<p>The electricity meter point half-hourly consumption can be called using</p>
<p class="bg-gray-400 p-3 rounded-md mt-3 mb-3"><code>$api->getMeterPointConsumption($electricity_mpan,
$electricity_serial, $date)</code></p>
<p><code>$electricity_mpan</code> is the mpan from your electricity meter found under your developer
dashboard.</p>
<p><code>$electricity_serial</code> is the serial number from your electricity meter found under
your developer dashboard.</p>
<p><code>$date</code> is the date you want to get the consumption for.</p>
</div>
<table class="text-left w-full">
<thead class="bg-black flex text-white w-full">
<tr class="flex w-full text-sm">
<th <?php
echo $styles['consumption']['cell_hideable']; ?>>Date
</th>
<th <?php
echo $styles['consumption']['cell']; ?>>From
</th>
<th <?php
echo $styles['consumption']['cell']; ?>>To
</th>
<th <?php
echo $styles['consumption']['cell']; ?>>Usage
</th>
<th <?php
echo $styles['consumption']['cell']; ?>>Cost exc. VAT
</th>
<th <?php
echo $styles['consumption']['cell']; ?>>Cost inc. VAT
</th>
</tr>
</thead>
<tbody class="bg-grey-light flex flex-col items-center justify-between overflow-y-scroll w-full h-64">
<?php
foreach (($electricity_consumption->results ?? []) as $key => $consumption_period) {
echo "<tr class=\"flex w-full pl-2\">
<td {$styles['consumption']['cell_hideable']}>".Carbon::parse($consumption_period->interval_start)
->format('d/m/Y')."</td>
<td {$styles['consumption']['cell']}>".Carbon::parse($consumption_period->interval_start)
->format('H:i')."</td>
<td {$styles['consumption']['cell']}>".Carbon::parse($consumption_period->interval_end)
->format('H:i')."</td>
<td {$styles['consumption']['cell']}>".round($consumption_period->consumption, 3)."</td>
<td {$styles['consumption']['cell']}>".round(($consumption_period->consumption * $api->getElectricityPrice($region,
false,
$consumption_period->interval_start)['data']),
1)." p</td>
<td {$styles['consumption']['cell']}>".round(($consumption_period->consumption * $api->getElectricityPrice($region, true,
$consumption_period->interval_start)['data']),
1)." p</td>
</tr>";
}
?>
</tbody>
</table>
</div>
</div>
<div class="lg:w-1/2 sm:w-full">
<div class="items-center mr-2 mb-2 widget p-4 rounded-lg bg-white border border-gray-100 dark:bg-gray-900 dark:border-gray-800">
<div class="p-2 text-lg font-bold"><h1>🔥 Gas Meter Point Consumption</h1></div>
<div class="mb-2 p-2 border-4 border-purple-300 rounded-lg">
<p>The gas meter point half-hourly consumption can be
called using</p>
<p class="bg-gray-400 p-3 rounded-md mt-3 mb-3"><code>$api->getMeterPointConsumption($gas_mprn,
$gas_serial, $date)</code></p>
<p><code>$gas_mprn</code> is the MPRN from your gas meter found under your developer dashboard.</p>
<p><code>$electricity_serial</code> is the serial number from your gas meter found under your
developer dashboard.</p>
<p><code>$date</code> is the date you want to get the consumption for.</p>
</div>
<table class="text-left w-full">
<thead class="bg-black flex text-white w-full">
<tr class="flex w-full text-sm">
<th <?php
echo $styles['consumption']['cell_hideable']; ?>>Date
</th>
<th <?php
echo $styles['consumption']['cell']; ?>>From
</th>
<th <?php
echo $styles['consumption']['cell']; ?>>To
</th>
<th <?php
echo $styles['consumption']['cell']; ?>>Usage
</th>
<th <?php
echo $styles['consumption']['cell']; ?>>Cost exc. VAT
</th>
<th <?php
echo $styles['consumption']['cell']; ?>>Cost inc. VAT
</th>
</tr>
</thead>
<tbody class="bg-grey-light flex flex-col items-center justify-between overflow-y-scroll w-full h-64">
<?php
foreach (($gas_consumption->results ?? []) as $key => $consumption_period) {
echo "<tr class=\"flex w-full pl-2\">
<td {$styles['consumption']['cell_hideable']}>".Carbon::parse($consumption_period->interval_start)
->format('d/m/Y')."</td>
<td {$styles['consumption']['cell']}>".Carbon::parse($consumption_period->interval_start)
->format('H:i')."</td>
<td {$styles['consumption']['cell']}>".Carbon::parse($consumption_period->interval_end)
->format('H:i')."</td>
<td {$styles['consumption']['cell']}>".round($consumption_period->consumption, 3)."</td>
<td {$styles['consumption']['cell']}>".round($consumption_period->consumption * $gas_unit_price, 1)." p</td>
<td {$styles['consumption']['cell']}>".round($consumption_period->consumption * $gas_unit_price, 1)." p</td>
</tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>