Skip to content

Commit

Permalink
TeslaFi API Wake & Sleep Tweaks (#798)
Browse files Browse the repository at this point in the history
For TeslaFi, switched to using full 'wake_up' command to keep the car awake, instead of the passive 'wake' command that proved to be less effective.
  • Loading branch information
THX723 committed Oct 31, 2023
1 parent 463f382 commit eac41ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 4 additions & 9 deletions run/awake_start
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ function ping {
fi

if [[ ( -n "${TESLAFI_API_TOKEN:+x}" ) ]]
# Use TeslaFi API to keep car awake
# Use TeslaFi API to keep car awake.
then
if [[ $(curl -s -H "Authorization: Bearer $TESLAFI_API_TOKEN" "https://www.teslafi.com/feed.php?command=wake") = "Wake command received" ]]
then
# TeslaFi's default sleep timer is 15min (900s). No need to contact too often to prevent API lockout (max 3 calls/min).
sleep 600
else
log "Failed to contact car using TeslaFi API, retrying in 90s..."
sleep 90
fi
curl -s -H "Authorization: Bearer $TESLAFI_API_TOKEN" "https://www.teslafi.com/feed.php?command=wake_up"
# No need to contact TeslaFi too often to prevent API lockout (max 3 calls/min).
sleep 600
fi
done
}
Expand Down
7 changes: 7 additions & 0 deletions run/awake_stop
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ then
log "Stopping wake car background task."
kill "$(cat /tmp/keep_awake_task_pid)" || true
rm -f /tmp/keep_awake_task_pid

if [[ ( -n "${TESLAFI_API_TOKEN:+x}" ) ]]
# TeslaFi Sleep command suspends its polling for the next 15 minutes (by default) to faciliate car's sleep.
then
curl -H "Authorization: Bearer $TESLAFI_API_TOKEN" "https://www.teslafi.com/feed.php?command=sleep"
log "also initiated TeslaFi Sleep Mode to give the car a chance to fall asleep."
fi
fi

0 comments on commit eac41ee

Please sign in to comment.