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

Update awake_start #928

Closed
wants to merge 1 commit into from
Closed

Update awake_start #928

wants to merge 1 commit into from

Conversation

jjermany
Copy link

@jjermany jjermany commented Feb 7, 2025

This is for using TeslaFi to keep your car awake with sentry mode.

This is for using TeslaFi to keep your car awake with sentry mode.
Copy link
Owner

@marcone marcone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be combined into a single PR with #927 and include a change to the sample config file that explains the new TESLAFI_WAKE_MODE setting

Comment on lines +41 to +75
http_response=$(curl -s -w "%{http_code}" \
-H "Authorization: Bearer $TESSIE_API_TOKEN" \
-H "Accept: application/json" \
-H "User-Agent: github.com/marcone/teslausb" \
"https://api.tessie.com/$TESSIE_VIN/wake")

# Extract HTTP status code
http_status="${http_response: -3}"

# Extract response body (excluding status code)
response_body="${http_response:0:${#http_response}-3}"

# Check if HTTP status code is not 200 (OK)
if [ "$http_status" != "200" ]
then
# Log an error
log "Failed to wake car with Tessie API. Check your TESSIE_API_TOKEN and TESSIE_VIN are set correctly. If they are, your car may not have a good connection. Retrying in 1 minute..."
sleep 60
else
# Check if the response is in JSON format
if ! jq -e . >/dev/null 2>&1 <<<"$response_body"
then
# Log an error
log "Failed to wake car with Tessie API. Check your TESSIE_API_TOKEN and TESSIE_VIN are set correctly. If they are, your car may not have a good connection. Retrying in 1 minute..."
sleep 60
log "Failed to wake car with Tessie API. Retrying in 1 minute. Response data: $response_body"
sleep 60
else
# Check if the response is in JSON format
if ! jq -e . >/dev/null 2>&1 <<<"$response_body"
then
log "Failed to wake car with Tessie API. Retrying in 1 minute. Response data: $response_body"
sleep 60
else
# Parse JSON and check if "result" is true
result=$(jq -r '.result' <<<"$response_body")
if [[ "$result" != "true" ]]
then
log "Failed to wake car with Tessie API. Retrying in 1 minute. Response data: $response_body"
sleep 60
else
# Sleep for 5 minutes on successful wake-up call
sleep 300
fi
fi
# Parse JSON and check if "result" is true
result=$(jq -r '.result' <<<"$response_body")
if [[ "$result" != "true" ]]
then
log "Failed to wake car with Tessie API. Retrying in 1 minute. Response data: $response_body"
sleep 60
else
# Sleep for 5 minutes on successful wake-up call
sleep 300
fi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

large whitespace changes should go in a separate PR.

touch /tmp/disable_sentry_after_archiving
/root/bin/tesla_api.py enable_sentry_mode &>> "${LOG_FILE}"
# Check if TESLAFI_WAKE_MODE is set to sentry
if [ "$TESLAFI_WAKE_MODE" == "sentry" ]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeslaUSB coding style is to put "then" on the next line.

# Check if TESLAFI_WAKE_MODE is set to sentry
if [ "$TESLAFI_WAKE_MODE" == "sentry" ]; then
log "Turning on Sentry Mode to keep car awake (via TeslaFI)."
set_sentry_mode true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only be called if TESLA_WAKE_MODE is also set to "sentry", and the condition on line 85 is true, which makes no sense because:

  • it will always be true because the API that that uses no longer works
  • even if it did, it would then require configuring the Tesla API variables in the config file, and the config specifically says to only use one of the APIs

This new TeslaFi code should be separate, and should use the TeslaFi API to determine whether sentry mode is already on.

fi
;;
stream)
log "Starting background task to keep car awake."
log "Starting background tasks to keep TeslaUSB powered on during archiving."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this log message, and specifically why did you pluralize "task" to "tasks" when there's only one background task?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There does need to be some changes. I do hope that people more knowledgeable like yourself can incorporate those changes. I do appreciate you looking further at this.

@jjermany
Copy link
Author

jjermany commented Feb 20, 2025

@marcone I just created a a new pull request for this. It's very simple now. You do not need to specify the sentry mode now. It uses it by default since that is the only way to keep the car USB powered anyway. I removed any redundancy. #934

@marcone
Copy link
Owner

marcone commented Feb 26, 2025

superseded by #936

@marcone marcone closed this Feb 26, 2025
@miles267
Copy link

superseded by #936

@marcone does this mean it has already been merged into main branch and I can re-run the Teslausb upgrade script?

@jjermany
Copy link
Author

jjermany commented Feb 26, 2025

superseded by #936

@marcone does this mean it has already been merged into main branch and I can re-run the Teslausb upgrade script?

You can use my repo in the config file.
https://github.com/jjermany/teslausb-1

I believe you just change it to "jjermany/teslausb-1".

It's towards the bottom of the teslausb_setup_variables.conf file. Once you change it to my fork of the repo you can run the upgrade command and it should update it to my awake scripts.

@marcone
Copy link
Owner

marcone commented Feb 27, 2025

superseded by #936

@marcone does this mean it has already been merged into main branch and I can re-run the Teslausb upgrade script?

No

@jjermany
Copy link
Author

@miles267 nevermind. I tried using my own repo and it failed every single time. I do not think that functionality works.

@marcone
Copy link
Owner

marcone commented Feb 27, 2025

@miles267 nevermind. I tried using my own repo and it failed every single time. I do not think that functionality works.

It should work, what exactly did you set the REPO and/or BRANCH variables to in the config file?

@miles267
Copy link

Is there a reason not to merge this PR into the main branch? I’m glad to help test it.

@jjermany
Copy link
Author

@miles267 nevermind. I tried using my own repo and it failed every single time. I do not think that functionality works.

It should work, what exactly did you set the REPO and/or BRANCH variables to in the config file?

Got it to work by just using jjermany
I renamed my repo to teslausb to match and I guess it picks up on it now.

@jjermany
Copy link
Author

I may end up having to ditch this project. My Tesla Dashcam keeps switching to unavailable and is just not reliable. 2020 Model 3. Driving me nuts not being able to even rely on it. So I suppose ill fork some cash and just buy a decent 3rd party dash cam. No fault to the project, just my tesla sucks. Can drive itself but cannot mount storage properly, crazy stuff..

My repo should be good for people who want to utilize TeslaFi to keep the car awake. Ill keep it there for those want to go that route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants