forked from mihailescu2m/powerwall_monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): fixes for tesla 20.49 API changes
With the 20.49 firmware update by Tesla, the endpoints that previously were open are no longer without authentication. Unfortuantely, the mechanism used for authentication is not HTTP basic, rather it's cookie based. This makes it so a process runs in the background to ensure that you always stay logged in and then executes the queries against the endpoints with the login cookie. However, for some reason cURL was just ignoring the cookie file on my machine, so I had to do some extra hacks to make it pass the cookies in on the command line. Also, this requires cron, which means by that point I might as well build a new docker container for this process. Fixes mihailescu2m#14 DCO 1.1 Signed-off-by: Patrick Wagstrom <[email protected]>
- Loading branch information
Showing
8 changed files
with
130 additions
and
83 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM telegraf:1.17 | ||
|
||
RUN apt-get update | ||
RUN apt-get install -y cron | ||
|
||
COPY entrypoint.sh get_aggregates.sh get_soe.sh / |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
# this file supersedes the original entrypoint.sh for telegraf containers | ||
# mainly because we need to fire off a cron job that runs every 20 minutes | ||
|
||
# see: https://github.com/mihailescu2m/powerwall_monitor/issues/14#issuecomment-778478572 | ||
|
||
mkdir -p /tmp/cookies | ||
CURL_CMD="curl -s -k -i -c /tmp/cookies/pw.txt -X POST -H 'Content-Type: application/json' -d '{\"username\":\"customer\",\"password\":\"$POWERWALL_PASSWORD\",\"force_sm_off\":false}' https://powerwall/api/login/Basic" | ||
CRON_CMD="*/20 * * * * $CURL_CMD" | ||
eval $CURL_CMD | ||
|
||
( crontab -l 2>/dev/null | grep -Fv powerwall ; printf -- "$CRON_CMD\n" ) | crontab | ||
|
||
set -e | ||
|
||
if [ "${1:0:1}" = '-' ]; then | ||
set -- telegraf "$@" | ||
fi | ||
|
||
exec "$@" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
curl -k --cookie $(cat /tmp/cookies/pw.txt | tail -n 2 | cut -d $'\t' -f 6,7 | sed -e 's/\t/=/g' | tr '\n' ';') 'https://powerwall/api/meters/aggregates' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
curl -k --cookie $(cat /tmp/cookies/pw.txt | tail -n 2 | cut -d $'\t' -f 6,7 | sed -e 's/\t/=/g' | tr '\n' ';') 'https://powerwall/api/system_status/soe' |