Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export CAM_SIZE=40G
# TeslaUSB.
#
# In order to keep the car awake, several methods have been implemented:
# TeslaFi, Tessie, and Bluetooth Low Energy (BLE). Please note that the previous
# TeslaFi, Tessie, Bluetooth Low Energy (BLE), and Webhooks. Please note that the previous
# implementation using the (unofficial) Tesla API was removed. Tesla had
# superseded it with their official Fleet API (a paid service for developers).
# Consequently, TeslaFi and Tessie now enforce request rate limits. As a result,
Expand All @@ -277,6 +277,12 @@ export CAM_SIZE=40G
# - Some security vulnerability
# - Requires paid 3rd-party service from TeslaFi or Tessie
#
# Webhook Pros/Cons:
# + Does not require teslausb to store credentials that can directly
# control your vehicle
# - Requires another service like home assistant be setup to receive
# webhooks and carry out the required actions to keep the vehicle awake
#
# DISCLAIMER:
# All 3 methods have some level of security implications. For BLE,
# key pair is stored on the device. For TeslaFi/Tessie, the API access token
Expand Down Expand Up @@ -317,7 +323,7 @@ export CAM_SIZE=40G
# compatibility notes. If applicable, also make a 1-time change (set and
# forget) to your in-car menu: Safety -> Sentry Mode.
#
# Case 1: [Compatible with TeslaFi, Tessie, or BLE]
# Case 1: [Compatible with TeslaFi, Tessie, BLE, or Webhook]
#
# You want Sentry Mode turned On everywhere, except when parked safely
# at home. Upon arriving home, Sentry Mode will already be ON
Expand All @@ -329,7 +335,7 @@ export CAM_SIZE=40G
# >>>> IMPORTANT: Verify your in-car Sentry Mode is set to ON, and
# 'Exclude Home' is UNCHECKED.
#
# Case 2: [Compatible with TeslaFi, Tessie, or BLE]
# Case 2: [Compatible with TeslaFi, Tessie, BLE, or Webhook]
#
# You DON'T want Sentry Mode turned on anywhere, unless archiving.
# Mode of operation: Upon arriving home, TeslaUSB will send a command
Expand All @@ -340,7 +346,7 @@ export CAM_SIZE=40G
#
# >>>> IMPORTANT: Verify your in-car Sentry Mode is set to OFF.
#
# Case 3: [Compatible with Tessie or BLE]
# Case 3: [Compatible with Tessie, BLE, or Webhook]
#
# Sentry Mode is not used by TeslaUSB. Instead a periodic command is
# sent to the car to keep it awake.
Expand Down Expand Up @@ -393,6 +399,16 @@ export CAM_SIZE=40G
# Note: This does not prevent the car from locking, nor does it allow
# someone to readily unlock or drive the car. An authroized key (card,
# phone, fob) is still required.
# . . . . . . . . . . . . . . . . . . . .
#
# For webhook, provide the URL of the webhook that will receive awake messages:
#export KEEP_AWAKE_WEBHOOK_URL=http://domain/path
#
# A webhook message with a JSON body will be sent. The shape of the JSON will be { "awake_command": "<command>" }
# Commands that will be sent to this webook:
# 1. start: Sent when SENTRY_CASE=2 and the archive process starts
# 2. stop: Sent when SENTRY_CASE=1 or 2 and the archive process stops
# 3. nudge: Sent when SENTRY_CASE=3 and the archive process is ongoing
################################################################################

# Temperature Monitor
Expand Down
41 changes: 40 additions & 1 deletion run/awake_start
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

if [[ ( -z "${TESLAFI_API_TOKEN:+x}" ) && ( -z "${TESSIE_API_TOKEN:+x}" ) && ( -z "${TESLA_BLE_VIN:+x}" ) ]]
if [[ ( -z "${TESLAFI_API_TOKEN:+x}" ) && ( -z "${TESSIE_API_TOKEN:+x}" ) && ( -z "${TESLA_BLE_VIN:+x}" ) && ( -z "${KEEP_AWAKE_WEBHOOK_URL:+x}" ) ]]
then
log "Not configured to keep car awake."
else
Expand Down Expand Up @@ -61,6 +61,26 @@ else
fi
fi
fi

elif [[ -n "${KEEP_AWAKE_WEBHOOK_URL:+x}" ]]
# Use webhook to send nudge message
then
http_response=$(curl -s -w "%{http_code}" POST \
-d "{\"awake_command\":\"nudge\"}" \
-H "Content-Type: application/json" \
"$KEEP_AWAKE_WEBHOOK_URL")

log "Awake Webhook: Command sent \"nudge\""

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

# Check if HTTP status code is not 200 (OK)
if [ "$http_status" -lt 200 ] || [ "$http_status" -ge 300 ]
then
# Log an error
log "Awake Webhook: Failed to send command \"nudge\". Check if your KEEP_AWAKE_WEBHOOK_URL is set correctly. If it is, check the service receiving webhooks for logs."
fi
fi

sleep 300
Expand Down Expand Up @@ -160,6 +180,25 @@ else
else
log "Tesla BLE: Failed to set Sentry Mode."
fi
elif [[ -n "${KEEP_AWAKE_WEBHOOK_URL:+x}" ]]
# Use webhook to send start command
then
http_response=$(curl -s -w "%{http_code}" POST \
-d "{\"awake_command\":\"start\"}" \
-H "Content-Type: application/json" \
"$KEEP_AWAKE_WEBHOOK_URL")

log "Awake Webhook: Command sent \"start\""

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

# Check if HTTP status code is not 200 (OK)
if [ "$http_status" -lt 200 ] || [ "$http_status" -ge 300 ]
then
# Log an error
log "Awake Webhook: Failed to send command \"start\". Check if your KEEP_AWAKE_WEBHOOK_URL is set correctly. If it is, check the service receiving webhooks for logs."
fi
fi
;;
3)
Expand Down
22 changes: 21 additions & 1 deletion run/awake_stop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

if [[ ( -z "${TESLAFI_API_TOKEN:+x}" ) && ( -z "${TESSIE_API_TOKEN:+x}" ) && ( -z "${TESLA_BLE_VIN:+x}" ) ]]
if [[ ( -z "${TESLAFI_API_TOKEN:+x}" ) && ( -z "${TESSIE_API_TOKEN:+x}" ) && ( -z "${TESLA_BLE_VIN:+x}" ) && ( -z "${KEEP_AWAKE_WEBHOOK_URL:+x}" ) ]]
then
exit
fi
Expand Down Expand Up @@ -94,6 +94,26 @@ case "${SENTRY_CASE}" in
else
log "Tesla BLE: Failed to set Sentry Mode."
fi

elif [[ -n "${KEEP_AWAKE_WEBHOOK_URL:+x}" ]]
# Use webhook to send stop message
then
http_response=$(curl -s -w "%{http_code}" POST \
-d "{\"awake_command\":\"stop\"}" \
-H "Content-Type: application/json" \
"$KEEP_AWAKE_WEBHOOK_URL")

log "Awake Webhook: Command sent \"stop\""

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

# Check if HTTP status code is not 200 (OK)
if [ "$http_status" -lt 200 ] || [ "$http_status" -ge 300 ]
then
# Log an error
log "Awake Webhook: Failed to send command \"stop\". Check if your KEEP_AWAKE_WEBHOOK_URL is set correctly. If it is, check the service receiving webhooks for logs."
fi
fi
;;
3)
Expand Down
21 changes: 20 additions & 1 deletion setup/pi/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ function pip3_install () {
function check_at_most_one_wake_api () {
if [[ ( -n "${TESSIE_API_TOKEN:+x}" && -n "${TESLAFI_API_TOKEN:+x}" ) ||
( -n "${TESSIE_API_TOKEN:+x}" && -n "${TESLA_BLE_VIN:+x}" ) ||
( -n "${TESLAFI_API_TOKEN:+x}" && -n "${TESLA_BLE_VIN:+x}" ) ]]
( -n "${TESLAFI_API_TOKEN:+x}" && -n "${TESLA_BLE_VIN:+x}" ) ||
( -n "${KEEP_AWAKE_WEBHOOK_URL:+x}" && -n "${TESLAFI_API_TOKEN:+x}" ) ||
( -n "${KEEP_AWAKE_WEBHOOK_URL:+x}" && -n "${TESLA_BLE_VIN:+x}" ) ||
( -n "${KEEP_AWAKE_WEBHOOK_URL:+x}" && -n "${TESSIE_API_TOKEN:+x}" )]]
then
log_progress "STOP: You're trying to set up multiple control providers at the same time."
log_progress "Only 1 can be enabled at a time."
Expand Down Expand Up @@ -305,6 +308,21 @@ function check_and_configure_tesla_ble () {
fi
}

function check_awake_webhook () {
if [[ ( -n "${KEEP_AWAKE_WEBHOOK_URL:+x}" ) ]]
then
check_variable "SENTRY_CASE"
if [[ "$SENTRY_CASE" != 1 && "$SENTRY_CASE" != 2 && "$SENTRY_CASE" != 3 ]]; then
log_progress "STOP: invalid SENTRY_CASE for Webhook."
exit 1
fi

log_progress "Awake Webhook enabled."
else
log_progress "Awake Webhook not enabled because no webhook URL was provided."
fi
}

function check_and_install_temperature_monitor () {
local install_path="$1"

Expand Down Expand Up @@ -757,6 +775,7 @@ then
check_teslafi_api
check_tessie_api
check_and_configure_tesla_ble /root/bin
check_awake_webhook
fi
check_and_install_temperature_monitor /root/bin
check_and_configure_pushover
Expand Down