Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4.0.0 - Add Cloud Mode support via pyPowerwall v0.7.0 #414

Merged
merged 28 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a0ed67c
Stage updates for pypowerwall v0.7.0
jasonacox Dec 27, 2023
1ab975e
v4.0.0
jasonacox Dec 27, 2023
39462a1
Add auth and site file creation
jasonacox Dec 29, 2023
ad1958c
Add .auth folder
jasonacox Dec 30, 2023
252f335
Update powerwall.yml for .auth
jasonacox Dec 30, 2023
d5bc73e
Add PW_AUTH_PATH to Docker Compose config
mcbirse Dec 31, 2023
7c54343
Add CQ for nominal_full_pack_energy
jasonacox Jan 2, 2024
a2fff22
Merge branch 'v4.0.0' of https://github.com/jasonacox/Powerwall-Dashb…
jasonacox Jan 2, 2024
5aa5fcd
Capture SIGTERM when weather411 halts due to missing config
mcbirse Jan 10, 2024
e8817c5
Add auth files
mcbirse Jan 10, 2024
32b946f
Remove profiles
mcbirse Jan 10, 2024
666947a
Update setup scripts and remove profiles
mcbirse Jan 10, 2024
b9bd555
Update container versions and remove profiles
mcbirse Jan 10, 2024
7e1bd00
Update pypowerwall
jasonacox Jan 14, 2024
90c2d7e
Add v3.0.8
jasonacox Jan 14, 2024
f41de0d
v4.0.0 upgrade script
mcbirse Jan 14, 2024
fde66b2
Fix network scan ip addr in Windows Git Bash
mcbirse Jan 15, 2024
7e7d692
Merge branch 'main' into v4.0.0
jasonacox Jan 15, 2024
1d96c9a
Merge branch 'v4.0.0' of https://github.com/jasonacox/Powerwall-Dashb…
jasonacox Jan 15, 2024
fa1bd89
Get ip addr based on OS
mcbirse Jan 16, 2024
1b2aae4
Fix for missing cmd
mcbirse Jan 16, 2024
94c75f7
Update verify script
mcbirse Jan 16, 2024
253dffe
Add sample docker compose for tesla-history
mcbirse Jan 19, 2024
2e1c504
Update setup options, README and RELEASE notes
mcbirse Jan 19, 2024
2f58551
Update to latest pypowerwall and proxy
mcbirse Jan 21, 2024
a493e91
Update README
jasonacox Jan 21, 2024
910e627
Add animation to solar-only dashboard
jasonacox Jan 21, 2024
7807a8c
Add script descriptions
jasonacox Jan 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update setup scripts and remove profiles
  • Loading branch information
mcbirse committed Jan 10, 2024
commit 666947a68fdbd63ef555248d032d65e1d17bc738
2 changes: 1 addition & 1 deletion .auth/.keep
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This file stores the auth tokens and site cache files for pypowerwall
in cloudmode=True.
in cloudmode=True.
221 changes: 90 additions & 131 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,57 +68,6 @@ running() {
[[ $status == ${code} ]]
}

# Compose Profiles Helper Functions
get_profile() {
if [ ! -f ${COMPOSE_ENV_FILE} ]; then
return 1
else
unset COMPOSE_PROFILES
. "${COMPOSE_ENV_FILE}"
fi
# Check COMPOSE_PROFILES for profile
IFS=',' read -ra PROFILES <<< "${COMPOSE_PROFILES}"
for p in "${PROFILES[@]}"; do
if [ "${p}" == "${1}" ]; then
return 0
fi
done
return 1
}

add_profile() {
# Create default docker compose env file if needed.
if [ ! -f ${COMPOSE_ENV_FILE} ]; then
cp "${COMPOSE_ENV_FILE}.sample" "${COMPOSE_ENV_FILE}"
fi
if ! get_profile "${1}"; then
# Add profile to COMPOSE_PROFILES and save to env file
PROFILES+=("${1}")
if [ -z "${COMPOSE_PROFILES}" ]; then
if grep -q "^#COMPOSE_PROFILES=" "${COMPOSE_ENV_FILE}"; then
sed -i.bak "s@^#COMPOSE_PROFILES=.*@COMPOSE_PROFILES=$(IFS=,; echo "${PROFILES[*]}")@g" "${COMPOSE_ENV_FILE}"
else
echo -e "\nCOMPOSE_PROFILES=$(IFS=,; echo "${PROFILES[*]}")" >> "${COMPOSE_ENV_FILE}"
fi
else
sed -i.bak "s@^COMPOSE_PROFILES=.*@COMPOSE_PROFILES=$(IFS=,; echo "${PROFILES[*]}")@g" "${COMPOSE_ENV_FILE}"
fi
fi
}

upd_profile() {
# Update existing profile in COMPOSE_PROFILES and save to env file
if get_profile "${1}"; then
for i in "${!PROFILES[@]}"; do
if [ "${PROFILES[$i]}" == "${1}" ]; then
PROFILES[$i]="${2}"
sed -i.bak "s@^COMPOSE_PROFILES=.*@COMPOSE_PROFILES=$(IFS=,; echo "${PROFILES[*]}")@g" "${COMPOSE_ENV_FILE}"
break
fi
done
fi
}

# Docker Dependency Check
if ! docker info > /dev/null 2>&1; then
echo "ERROR: docker is not available or not running."
Expand All @@ -134,61 +83,62 @@ if ! docker-compose version > /dev/null 2>&1; then
fi
fi

# Check COMPOSE_PROFILES for existing configuration profile
if get_profile "default"; then
PROFILE="default"
current="[1] "
profdesc="Local Access"
elif get_profile "solar-only"; then
PROFILE="solar-only"
current="[2] "
profdesc="Tesla Cloud"
# Check PW_ENV_FILE for existing configuration
if [ ! -f ${PW_ENV_FILE} ]; then
choice=""
config="None"
elif grep -qE "^PW_HOST=.+" "${PW_ENV_FILE}"; then
choice="[1] "
config="Local Access"
else
PROFILE="none"
current=""
profdesc="None"
choice="[2] "
config="Tesla Cloud"
fi

# Prompt for configuration profile
echo "Select configuration profile:"
# Prompt for configuration
echo "Select configuration mode:"
echo ""
echo "Current: ${profdesc}"
echo "Current: ${config}"
echo ""
echo " 1 - Local Access (Powerwall 1, 2, or + using extended data from Tesla Gateway on LAN) - Default"
echo " 2 - Tesla Cloud (Solar-only, Powerwall 1, 2, +, or 3 using data from Tesla Cloud)"
echo ""
while :
do
read -r -p "Select profile: ${current}" response
while :; do
read -r -p "Select mode: ${choice}" response
if [ "${response}" == "1" ]; then
NEW_PROFILE="default"
selected="Local Access"
elif [ "${response}" == "2" ]; then
NEW_PROFILE="solar-only"
elif [ -z "${response}" ] && [ ! -z "${current}" ]; then
NEW_PROFILE="${PROFILE}"
selected="Tesla Cloud"
elif [ -z "${response}" ] && [ ! -z "${choice}" ]; then
selected="${config}"
else
continue
fi
if [ ! -z "${current}" ] && [ "${NEW_PROFILE}" != "${PROFILE}" ]; then
if [ ! -z "${choice}" ] && [ "${selected}" != "${config}" ]; then
echo ""
read -r -p "You are already using the ${profdesc} configuration, are you sure you wish to change? [y/N] " response
read -r -p "You are already using the ${config} configuration, are you sure you wish to change? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
config="${selected}"
rm ${PW_ENV_FILE}
echo ""
break
else
echo "Cancel"
exit 1
fi
else
# Add selected profile to COMPOSE_PROFILES
PROFILE="${NEW_PROFILE}"
add_profile "${PROFILE}"
config="${selected}"
echo ""
break
fi
done

# Create default docker compose env file if needed.
if [ ! -f ${COMPOSE_ENV_FILE} ]; then
cp "${COMPOSE_ENV_FILE}.sample" "${COMPOSE_ENV_FILE}"
fi

# Check if running as non-default user (not required for Windows Git Bash)
if ! type winpty > /dev/null 2>&1; then
notset=0
Expand Down Expand Up @@ -261,51 +211,50 @@ echo "Timezone (leave blank for ${CURRENT})"
read -p 'Enter Timezone: ' TZ
echo ""

# Switch configuration profile
if [ "${NEW_PROFILE}" != "${PROFILE}" ]; then
echo "Changing configuration"
# Powerwall Credentials
if [ -f ${PW_ENV_FILE} ]; then
echo "Current Credentials:"
echo ""
./compose-dash.sh down
upd_profile "${PROFILE}" "${NEW_PROFILE}"
PROFILE="${NEW_PROFILE}"
cat ${PW_ENV_FILE}
echo ""
fi

if [ "${PROFILE}" == "default" ]
then
# Powerwall Credentials
if [ -f ${PW_ENV_FILE} ]; then
echo "Current Powerwall Credentials:"
read -r -p "Update these credentials? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
rm ${PW_ENV_FILE}
echo ""
cat ${PW_ENV_FILE}
echo ""
read -r -p "Update these credentials? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
rm ${PW_ENV_FILE}
else
echo "Using existing ${PW_ENV_FILE}."
fi
else
echo "Using existing ${PW_ENV_FILE}."
fi
fi

# Create Powerwall Settings
if [ ! -f ${PW_ENV_FILE} ]; then
# Create Powerwall Settings
if [ ! -f ${PW_ENV_FILE} ]; then
if [ "${config}" == "Local Access" ]; then
echo "Enter credentials for Powerwall..."
read -p 'Password: ' PASSWORD
read -p 'Email: ' EMAIL
read -p 'IP Address: ' IP
echo "PW_EMAIL=${EMAIL}" > ${PW_ENV_FILE}
echo "PW_PASSWORD=${PASSWORD}" >> ${PW_ENV_FILE}
echo "PW_HOST=${IP}" >> ${PW_ENV_FILE}
echo "PW_TIMEZONE=America/Los_Angeles" >> ${PW_ENV_FILE}
echo "TZ=America/Los_Angeles" >> ${PW_ENV_FILE}
echo "PW_DEBUG=no" >> ${PW_ENV_FILE}
echo "PW_STYLE=grafana-dark" >> ${PW_ENV_FILE}
while [ -z "${PASSWORD}" ]; do
read -p 'Password: ' PASSWORD
done
while [ -z "${EMAIL}" ]; do
read -p 'Email: ' EMAIL
done
read -p 'IP Address (leave blank to scan network): ' IP
else
echo "Enter email address for Tesla Account..."
while [ -z "${EMAIL}" ]; do
read -p 'Email: ' EMAIL
done
fi
echo "PW_EMAIL=${EMAIL}" > ${PW_ENV_FILE}
echo "PW_PASSWORD=${PASSWORD}" >> ${PW_ENV_FILE}
echo "PW_HOST=${IP}" >> ${PW_ENV_FILE}
echo "PW_TIMEZONE=America/Los_Angeles" >> ${PW_ENV_FILE}
echo "TZ=America/Los_Angeles" >> ${PW_ENV_FILE}
echo "PW_DEBUG=no" >> ${PW_ENV_FILE}
echo "PW_STYLE=grafana-dark" >> ${PW_ENV_FILE}
fi

# Create default telegraf local file if needed.
if [ ! -f ${TELEGRAF_LOCAL} ]; then
cp "${TELEGRAF_LOCAL}.sample" "${TELEGRAF_LOCAL}"
fi
# Create default telegraf local file if needed.
if [ ! -f ${TELEGRAF_LOCAL} ]; then
cp "${TELEGRAF_LOCAL}.sample" "${TELEGRAF_LOCAL}"
fi

# Create InfluxDB env file if missing (required in 3.0.7)
Expand Down Expand Up @@ -338,6 +287,30 @@ fi
./compose-dash.sh up -d
echo "-----------------------------------------"

# Run Local Access mode network scan
if [ "${config}" == "Local Access" ] && ! grep -qE "^PW_HOST=.+" "${PW_ENV_FILE}"; then
echo "Running network scan... (press Ctrl-C to interrupt)"
docker exec -it pypowerwall python3 -m pypowerwall scan -ip=$(ip route get 8.8.8.8 | awk '{ print $NF }')
echo "-----------------------------------------"
echo "Enter address for Powerwall... (or leave blank to switch to Tesla Cloud mode)"
read -p 'IP Address: ' IP
echo ""
if [ -z "${IP}" ]; then
config="Tesla Cloud"
fi
sed -i.bak "s@^PW_HOST=.*@PW_HOST=${IP}@g" "${PW_ENV_FILE}"
./compose-dash.sh up -d
echo "-----------------------------------------"
fi

# Run Tesla Cloud mode setup
if [ "${config}" == "Tesla Cloud" ]; then
docker exec -it pypowerwall python3 -m pypowerwall setup -email=$(grep -E "^PW_EMAIL=.+" "${PW_ENV_FILE}" | cut -d= -f2)
echo "Restarting..."
docker restart pypowerwall
echo "-----------------------------------------"
fi

# Set up Influx
echo "Waiting for InfluxDB to start..."
until running http://localhost:8086/ping 204 2>/dev/null; do
Expand All @@ -361,27 +334,13 @@ done
cd ..

# Restart weather411 to force a sample
if [ -f weather/weather411.conf ] && get_profile "weather411"; then
if [ -f weather/weather411.conf ]; then
echo "Fetching local weather..."
docker restart weather411
fi

if [ "${PROFILE}" == "solar-only" ]
then
# Setup tesla-history
if [ -z "${TZ}" ]; then
TZ="${CURRENT}"
fi
echo "Setup tesla-history..."
docker exec -it tesla-history python3 tesla-history.py --setup --timezone "${TZ}"

# Restart tesla-history
echo "Restarting tesla-history..."
docker restart tesla-history
fi

# Display Final Instructions
if [ "${PROFILE}" == "solar-only" ]
if [ "${config}" == "Tesla Cloud" ]
then
DASHBOARD="'dashboard-solar-only.json' or 'dashboard-no-animation.json'"
else
Expand Down
46 changes: 2 additions & 44 deletions weather.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,44 +54,6 @@ if [ ! -f ${COMPOSE_ENV_FILE} ]; then
exit 1
fi

# Compose Profiles Helper Functions
get_profile() {
if [ ! -f ${COMPOSE_ENV_FILE} ]; then
return 1
else
unset COMPOSE_PROFILES
. "${COMPOSE_ENV_FILE}"
fi
# Check COMPOSE_PROFILES for profile
IFS=',' read -ra PROFILES <<< "${COMPOSE_PROFILES}"
for p in "${PROFILES[@]}"; do
if [ "${p}" == "${1}" ]; then
return 0
fi
done
return 1
}

add_profile() {
# Create default docker compose env file if needed.
if [ ! -f ${COMPOSE_ENV_FILE} ]; then
cp "${COMPOSE_ENV_FILE}.sample" "${COMPOSE_ENV_FILE}"
fi
if ! get_profile "${1}"; then
# Add profile to COMPOSE_PROFILES and save to env file
PROFILES+=("${1}")
if [ -z "${COMPOSE_PROFILES}" ]; then
if grep -q "^#COMPOSE_PROFILES=" "${COMPOSE_ENV_FILE}"; then
sed -i.bak "s@^#COMPOSE_PROFILES=.*@COMPOSE_PROFILES=$(IFS=,; echo "${PROFILES[*]}")@g" "${COMPOSE_ENV_FILE}"
else
echo -e "\nCOMPOSE_PROFILES=$(IFS=,; echo "${PROFILES[*]}")" >> "${COMPOSE_ENV_FILE}"
fi
else
sed -i.bak "s@^COMPOSE_PROFILES=.*@COMPOSE_PROFILES=$(IFS=,; echo "${PROFILES[*]}")@g" "${COMPOSE_ENV_FILE}"
fi
fi
}

# Configuration File
if [ -f ${CONF_FILE} ]; then
echo "Existing Configuration Found"
Expand All @@ -109,11 +71,8 @@ if [ -f ${CONF_FILE} ]; then
else
echo "Using existing ${CONF_FILE}."
echo ""
if ! get_profile "weather411"; then
add_profile "weather411"
if [ "${1}" != "setup" ]; then
. compose-dash.sh up -d
fi
if [ "${1}" != "setup" ]; then
. compose-dash.sh up -d
fi
exit 0
fi
Expand Down Expand Up @@ -177,7 +136,6 @@ if [ ! -f ${CONF_FILE} ]; then
break
done
cp "${CONF_SRC}" "${CONF_FILE}"
add_profile "weather411"
fi

# Replace configuration data with user input
Expand Down