/
Amber Electric Android Shortcut

Amber Electric Android Shortcut

So Amber Electric has an API. It’s difficult to use, but it’s got no authentication and once you get the gist of it it’s workable.

But I’m not a coder. So when tweep @RossPoulton shared his iOS code for the Scriptable widget it really looked easy enough to understand.

Now I would LOVE a widget, but I know Amber are planning new features for their app in the next few months, and the API will change after the wholesale pricing model changes in 2021 so I’m not particularly fussed right now.

What I DO want right now is real pricing.

Real Pricing

See, I’m on a two tier rate. After 11pm and before 7am and on the weekends my pricing pretty much matches what is on the Amber app, but during peak times, it’s more.

So, based on a lot of calculation, and only two months of data, I have worked out on average it’s 9.71c over and above the Amber rate in peak hours and pretty spot on in off peak hours. This is the “real rate” that takes into account the daily fees for Amber, Metering and Fixed Network Fees and the extra 6.2c per kWH for the tariff for Peak times. It’s all pretty much a guess right now. But I reckon if I add 10c to peak time and leave off peak the same it might be enough to give me an indication as to the real pricing.

(Hopefully when we get the update app it will show the two tier tariff and I will only have to add on the average per day extras for Amber, Metering and Fixed Network fees).

Note, I don’t have solar so I’m not factoring that into anything to do with the API or the pricing.

An App

So I found an Android App HTTP Shortcuts that will at least do the API call and display the rates on in a Toast notification or Dialog on my screen. I have to push a button but that is OK, it’s still way faster than opening the app, and I can modify the rates coming back to give me the Real Price.

One other cool thing it can do is change the Name and Icon of the app shortcut based on data returned from the API call.

Now, I’m not a Javascript coder so it took me a bit of time and a bit of fiddling around in Postman to take just the API bits from Ross’s code and produce something that worked in Postman. Then a bit more fiddling to get it to work in HTTP Shortcuts. And gee trying to write code on a phone is hugely difficult, so copy it from Postman to a google doc, modify it there, and paste it into your phone from the Google doc. (but watch the ' symbol in Google Docs).

Note, I used the cool feature to use Tests in Postman to run the Javascript after the REST call to set environment variables for the data to be returned. It is a complete hack, and there may be a better way, but it gets me the info I need.

Postman Code

POST https://api.amberelectric.com.au/prices/listprices Headers Content-Type application/json Body { "postcode": "3000" }

Tests

var jsonData = pm.response.json(); var currentPrice = 0 var nextPrice = 0 var currentRenewables = 0 var amberPrice = 0 // Static per-kwh prices: these include supply charges, the Amber fee, green energy rates, etc. var staticKwhPrice = parseFloat(jsonData.data.staticPrices.E1.totalfixedKWHPrice) var lossFactor = parseFloat(jsonData.data.staticPrices.E1.lossFactor) // Variable prices: This is a list of 30-minute intervals of past/current (ACTUAL) and future (FORECAST) // power prices. for (i = 0; i < jsonData.data.variablePricesAndRenewables.length; i++) { var thisPeriod = jsonData.data.variablePricesAndRenewables[i] if (thisPeriod.periodType == 'ACTUAL') { // We push the actual figures into currentPrice/currentRenewables. These are in time order so we'll end up // using the last one for 'current'. currentPrice = Math.round((parseFloat(thisPeriod.wholesaleKWHPrice) * lossFactor) + staticKwhPrice, 4) / 100 currentRenewables = Math.round(parseFloat(thisPeriod.renewablesPercentage) * 100) } else if (thisPeriod.periodType == 'FORECAST' && nextPrice == 0) { // the first 'FORECAST' becomes the next period price. nextPrice = Math.round((parseFloat(thisPeriod.wholesaleKWHPrice) * lossFactor) + staticKwhPrice, 4) / 100 } } var dt = new Date(); var h = dt.getHours(); var d = dt.getDay(); amberPrice = currentPrice; if(d >= 1 && d < 6 && h >= 7 && h <= 23) { currentPrice = (currentPrice + .10).round(2); nextPrice = (nextPrice + .10).round(2); } pm.environment.set("h", h); pm.environment.set("d", d); pm.environment.set("amber", amberPrice); pm.environment.set("price", currentPrice); pm.environment.set("renew", currentRenewables); pm.environment.set("next", nextPrice);

HTTP Shortcuts Setup

Shortcut Icon

Whatever you want - it will change

Shortcut Name

Whatever you want - it will change

Basic Request Settings

POST https://api.amberelectric.com.au/prices/listprices

Request Headers

Content-Type application/json

Request Body / Parameters

Custom Text Content-Type application/json Request Body { "postcode": "3000" }

Authentication

No authentication

Response Handling

On Success -Show nothing (run silently)

Scripting

Run on Success

Export

I exported the final code with the new “power” icon here

https://drive.google.com/file/d/1G9QPQRMD0VbcwdgbZtfkTbl5BZbznGhT/view?usp=sharing

A note about the icons

I found the icon names here on the HTTP Shortcuts github repo

https://github.com/Waboodoo/HTTP-Shortcuts/blob/develop/HTTPShortcuts/app/src/main/kotlin/ch/rmy/android/http_shortcuts/icons/Icons.kt

and the bitsies icons here https://www.recepkutuk.com/bitsies/

Shortcut

Add a shortcut via your home screen's widget menu (usually accessed by long pressing on the home screen), and when prompted by the app about which method to use for placement, select the "Legacy" option.

Click the shortcut. The Toast will show and the shortcut icon and text will change.

You can set HTTP Shortcuts to work from the Notification shade, but that’s just extra clicks.

However the changing of the shortcut icons is just not working, so I am going to remove it. See here https://drive.google.com/file/d/1FOUnjL_LCeWfX0YUx8rD-oJVLG1s-vtw/view?usp=sharing

Video

https://photos.app.goo.gl/c2B8pKbC1GCnWgC66

(it doesn’t look like much because it was done on a weekend, and it should have shown cheap, but I fixed my code after that).

Your suggestions

No guarantees that this will continue working or will work for you, but if you have any suggestions please let me know via twitter @jodiem.

 

Related content

Auto Convert Leads Apps
Auto Convert Leads Apps
More like this
Eventbrite
Eventbrite
More like this
Amazon Honeycode
Amazon Honeycode
More like this
Multiple ways to run Flows for multiple records
Multiple ways to run Flows for multiple records
More like this
Percentage Fields in Flows
Percentage Fields in Flows
More like this
Object Converter
Object Converter
More like this