#!/bin/bash
#WARNING: FOR TESTING ONLY, VEHICLE SHOULD BE ACTIVELY SUPERVISED AT ALL TIMES, USE AT YOUR OWN RISK.
#infinite loop until script is killed
while :
do
#For logging timestamp
date
#Get HV battery SoC
hv_batt_soc=$(./voc -u <VoC-Username> -p <VoC-Password> -r na print | jq -r ".hvBattery" | jq -r ".hvBatteryLevel")
echo "HV Battery: $hv_batt_soc%"
#Get current climate status
climate_status=$(./voc -u <VoC-Username> -p <VoC-Password> -r na status | grep heater)
echo "$climate_status"
# Proceed w/ camper mode if HV battery SoC is Ok.
if (( "$hv_batt_soc" > 20 )); then
echo "Battery SoC is good, executing camper mode"
# Only invoke RPC to start preconditioning if it's off
# This is only tested w/ USA spec XC60 T8
if [[ $climate_status == *"off"* ]]; then
echo "Climate is off, starting heater"
#Preconditioning state appears to be linked to "heater"
./voc -u <VoC-Username> -p <VoC-Password> -r na heater start | grep heater
else
echo "Climate is on, checking back in 5 mins"
fi
else
# If battery is low the don't preoceed
echo "Battery SoC Low, disabling camper mode"
fi
# Wait 5 mins
sleep 5m
done