Page 1 of 1

Retrieve electricity spot price from AEMO Australia

Posted: Monday 24 August 2020 17:56
by ben53252642
Hey folks,

I've signed up with a new electricity retailer in Australia called PowerClub, I noticed they have an app to track the electricity spot price in kWh and alert if its above a set threshold.

I've written a bash script that gets the spot price for Victoria from the AEMO and loads it into Domoticz on a 290 seconds interval.

This lets me send alerts from Domoticz (to myself) when thresholds are exceeded, automate turning off heavy power use devices such as the air conditioner and have a verbal alert come over the speakers if I am in x room when the high spot price power event occurs.

From what I can see from the JSON feed its possible to pick other states, values I can see include:
VIC1
TAS1
SA1
QLD1
NSW1

Requirements: apt-get install bc jq screen curl

spotprice.sh

Code: Select all

#!/bin/bash

# Domoticz Configuration
domoticzserver="192.168.0.5"
domoticzport="443"
domoticzuser="USER"
domoticzpass="PASSWORD"
domoticzsensoridx="1600" # Virtual Sensor Type: Custom

# Sleep for 30 seconds before initial start
echo "Delaying startup for 30 seconds..."
sleep 30

while true; do

# Get data
url=$(curl -s 'https://aemo.com.au/aemo/apps/api/report/ELEC_NEM_SUMMARY')

# Sort data to find the price
data=$(echo "$url" | jq '.ELEC_NEM_SUMMARY | map(select(.REGIONID == "VIC1"))[0].PRICE')

# Convert from MWh to KWh and only display to 2 decimal places
price=$(echo "scale=2;$data / 1000" | bc -l)

# Check if data is an integer or float
if echo "$price" | grep -qE '^[0-9]+$' || [[ $price =~ ^[+-]?[0-9]*\.[0-9]+$ ]]; then
 echo "Spot price: \$$price"
 # Send data to Domoticz
 curl --max-time 60 -k -s "https://{$domoticzuser}:{$domoticzpass}@{$domoticzserver}:{$domoticzport}/json.htm?type=command&param=udevice&idx={$domoticzsensoridx}&nvalue=0&svalue={$price}"
else
 echo "There appears to a problem with the data"
fi

sleep 290
done
I am running spotprice.sh in the background at startup using screen (edit as needed):
/usr/bin/screen -S spotprice -d -m nice -17 ionice -c2 -n6 /scripts/power/spotprice/spotprice.sh

The script gets publicly available data that can be found on this web page:
https://aemo.com.au/en/energy-systems/e ... hboard-nem

Please note this script is intended for advanced users, you are responsible for ensuring it does what you need it to do. The script is released under license GPL 3.0 which can be viewed here:
https://www.gnu.org/licenses/gpl-3.0.en.html