Created
December 10, 2023 06:47
-
-
Save rawiriblundell/b029edd4c35bdd490b702fae515996cf to your computer and use it in GitHub Desktop.
Modelling the potential bill for switching from Electric Kiwi to Octopus Energy. Requires data dump from Electric Kiwi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 7am-9am,5pm-9pm | |
ek_peak_current="0.2213" | |
# 9am-5pm, 9pm-11pm | |
ek_off_peak_shoulder_current="0.1372" | |
# 11pm to 7am | |
ek_off_peak_night_current="0.1107" | |
ek_daily_current="1.99" | |
ek_peak_future="0.2613" | |
ek_off_peak_shoulder_future="0.1830" | |
ek_off_peak_night_future="0.1307" | |
ek_daily_future="1.99" | |
# Mon to Fri: 7am-11am, 5pm to 9pm | |
octopus_peak="0.208" | |
# Mon to Fri: 11am-5pm, 9pm-11pm | |
# Sat and Sun: 7am to 11pm | |
octopus_off_peak_shoulder="0.158" | |
# 11pm to 7am | |
octopus_off_peak_night="0.104" | |
octopus_daily="1.8475" | |
add() { | |
LANG=C; printf -- '%1.3f\n' "$(bc <<< "${1}+${2}")" | |
} | |
multiply() { | |
LANG=C; printf -- '%1.3f\n' "$(bc <<< "${1}*${2}")" | |
} | |
is_weekend() ( | |
case "$(date -d "${1:?No date given}" +%a)" in | |
(Sat|Sun) return 0 ;; | |
(*) return 1 ;; | |
esac | |
) | |
# I have two channels in my smart meter data | |
# this function merges the usage data for both | |
channel_merge() { | |
local i j | |
j=47 | |
for ((i=0;i<=47;i++)); do | |
(( j++ )) | |
add "${MAPFILE[i]}" "${MAPFILE[j]}" | |
done | |
} | |
peak_total() { | |
local i ek_units octopus_units | |
ek_units=0 | |
octopus_units=0 | |
# EK: 7am to 9am | |
for (( i=14;i<=17;i++ )); do | |
ek_units=$(add "${ek_units}" "${merged[i]}") | |
done | |
# EK: 5pm to 9pm | |
for (( i=34;i<=41;i++ )); do | |
ek_units=$(add "${ek_units}" "${merged[i]}") | |
done | |
# For Octopus, we test if it's a weekend. If so, skip out | |
is_weekend "${day}" && return 0 | |
# Octopus: 7am to 11am, 5pm to 9pm | |
# This means adding 9am to 11am to $ek_units | |
octopus_units=$(add "${ek_units}" "${merged[18]}") | |
octopus_units=$(add "${octopus_units}" "${merged[19]}") | |
octopus_units=$(add "${octopus_units}" "${merged[20]}") | |
octopus_units=$(add "${octopus_units}" "${merged[21]}") | |
printf -- '%s;Electric Kiwi Current : $%s\n' "${day}" "$(multiply "${ek_units}" "${ek_peak_current}")" | |
printf -- '%s;Electric Kiwi Future : $%s\n' "${day}" "$(multiply "${ek_units}" "${ek_peak_future}")" | |
printf -- '%s;Octopus Energy : $%s\n' "${day}" "$(multiply "${octopus_units}" "${octopus_peak}")" | |
} | |
night_total() { | |
local i sum | |
sum=0 | |
for (( i=0;i<=13;i++ )); do | |
sum=$(add "${sum}" "${merged[i]}") | |
done | |
sum=$(add "${sum}" "${merged[46]}") | |
sum=$(add "${sum}" "${merged[47]}") | |
printf -- '%s;Electric Kiwi Current : $%s\n' "${day}" "$(multiply "${sum}" "${ek_off_peak_night_current}")" | |
printf -- '%s;Electric Kiwi Future : $%s\n' "${day}" "$(multiply "${sum}" "${ek_off_peak_night_future}")" | |
printf -- '%s;Octopus Energy : $%s\n' "${day}" "$(multiply "${sum}" "${octopus_off_peak_night}")" | |
} | |
shoulder_total() { | |
local i ek_units octopus_units | |
ek_units=0 | |
octopus_units=0 | |
# Mon to Fri: 11am-5pm, 9pm-11pm | |
# Sat and Sun: 7am to 11pm | |
octopus_off_peak_shoulder="0.158" | |
# EK: 9am to 5pm | |
for (( i=18;i<=33;i++ )); do | |
ek_units=$(add "${ek_units}" "${merged[i]}") | |
done | |
# EK: 9pm to 11pm | |
for (( i=42;i<=45;i++ )); do | |
ek_units=$(add "${ek_units}" "${merged[i]}") | |
done | |
# Octopus, test if it's a weekend | |
if is_weekend "${day}"; then | |
# Octopus: Sat and Sun: 7am to 11pm | |
for (( i=14;i<=45;i++ )); do | |
octopus_units=$(add "${octopus_units}" "${merged[i]}") | |
done | |
else | |
# Octopus: # Mon to Fri: 11am-5pm | |
for (( i=22;i<=33;i++ )); do | |
octopus_units=$(add "${octopus_units}" "${merged[i]}") | |
done | |
# Octopus: # Mon to Fri: 9pm-11pm | |
for (( i=42;i<=45;i++ )); do | |
octopus_units=$(add "${octopus_units}" "${merged[i]}") | |
done | |
fi | |
printf -- '%s;Electric Kiwi Current : $%s\n' "${day}" "$(multiply "${ek_units}" "${ek_off_peak_shoulder_current}")" | |
printf -- '%s;Electric Kiwi Future : $%s\n' "${day}" "$(multiply "${ek_units}" "${ek_off_peak_shoulder_future}")" | |
printf -- '%s;Octopus Energy : $%s\n' "${day}" "$(multiply "${octopus_units}" "${octopus_off_peak_shoulder}")" | |
} | |
while read -r day; do | |
# Read each day into an array | |
mapfile -d ',' -t < <(grep "${day}" electrickiwi.csv | cut -d ',' -f6-53 | tr '\n' ',') | |
# Read our merged channels into an array named merged | |
mapfile -t merged < <(channel_merge) | |
peak_total | |
night_total | |
shoulder_total | |
done < <(awk -F ',' '/2022/{print $1}' electrickiwi.csv | sort | uniq) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment