Lite, open-source version of teslarpi.com.
Compresses Tesla dashcam and sentry clips, uploads to S3, notifies of events via email (or Telegram, along with a copy of each clip) and allows remote streaming while parked or driving!
TeslaBox is also capable to run TeslaMate.
- Raspberry Pi 4 with at least 4GB ram, at least 64GB of storage and a card reader (Like this kit)
- Compatible case with fan (Like this. Note Argon cases are not recommended)
- Some form of WiFi access, preferably in-car (Like this 4G USB dongle)
- Extra short, all males USB-A to USB-C or USB-C to USB-C cable
For paid (priority) support please contact teslabox@payymail.com
- Sign into your AWS account
- Create a new S3 bucket:
- Bucket name: however you'd like (must be globally unique)
- AWS region: either us-east-1 or the one closest to you
- ACL Disabled
- Block all public access
- Bucket versioning: Disable
- Default encryption: Disable
- Click "Create Bucket"
- Add a new IAM user:
- User name: whatever you'd like (i.e teslabox)
- Select AWS credential type: Access key: - Programmatic access
- Click "Next: Permissions"
- Under "Attach existing policies directly" click "Create Policy"
- Service: S3
- Actions: GetObject and PutObject
- Resource: Add ARN to restrict access
- Enter your Bucket name from 2.1 and tick "any" on Object name
- Click "Add"
- Click "Next: Tags"
- Click "Next: Review"
- Name: "teslabox"
- Click "Create Policy"
- Back on the IAM user page, refresh the list of policies and check "teslabox"
- Click "Next: Tags"
- Click "Next: Review"
- Click "Create User"
- Copy both the Access key ID and Secret access key
- If you want to be notified by email:
- Edit the policy you just created
- Click "Add additional permissions"
- Service: SES v2
- Actions: SendEmail
- Identity: Any in this account
- Click "Review Policy" and "Save Changes"
- Under SES > Verified identities click "Create Identity"
- Choose either Domain or Email address with the address(es) you want to notify
- Verify the identity as per the instructions
- Sign up for a free account
- Add the device(s) you wish to connect from
- Under DNS > Enable MagicDNS
- Sign into your Telegram account
- Search and contact @Botfather user
- Enter /newbot and follow the wizard to create a new bot and retrieve your secret HTTP API token
- Contact the new bot you just created and click "Start"
- Search and contact @getmyid_bot user
- Enter anything to retrieve your Chat ID
- Download and run Raspberry Pi Imager
- Under Operating System, choose Raspberry Pi OS Lite (64-bit)
- Under Storage, choose the SD card you wish to format
- Under settings:
- Set hostname to whatever you like (i.e model3.local)
- Enable SSH and "Use password authentication"
- Set username (i.e pi) and password to whatever you like
- Configure wireless LAN, SSID, Password and country. This should be your home WiFi for now
- Set local settings with your Time zone
- Check "Eject media when finished"
- Click SAVE
- Click WRITE and wait for the process to complete and verify
- Eject the SD card, insert to your Raspberry Pi and boot it up
- SSH to the hostname you have setup with the credentials you chose (i.e ssh pi@model3.local)
- Switch to root:
sudo -i
- Run these commands:
echo dtoverlay=dwc2 >> /boot/config.txt
echo dtoverlay=disable-bt >> /boot/config.txt
echo hdmi_blanking=2 >> /boot/config.txt
sed -i 's/fsck.repair=yes/fsck.repair=no/g' /boot/cmdline.txt
sed -i 's/rootwait/rootwait modules-load=dwc2/g' /boot/cmdline.txt
- Add one or more WiFi networks with increasing priority:
- First, edit your WiFi configuration file:
nano /etc/wpa_supplicant/wpa_supplicant.conf
- If you want TeslaBox to prefer your home network, then your USB access point, then your mobile hotspot, configuration should be:
network={
ssid="my_home_wifi_name"
psk="my_home_wifi_password"
priority=3
id_str="home"
}
network={
ssid="my_usb_ap_wifi_name"
psk="my_usb_ap_wifi_password"
priority=2
id_str="ap"
}
network={
ssid="my_hotspot_wifi_name"
psk="my_hotspot_wifi_password"
priority=1
id_str="hotspot"
}
- Allocate USB space with all available storage (minus 10GB, or more if you plan on using TeslaMate):
size="$(($(df -B1G --output=avail / | tail -1) - 10))"
fallocate -l "$size"G /usb.bin
mkdosfs /usb.bin -F 32 -I
echo "/usb.bin /mnt/usb vfat auto,noexec,nouser,ro,sync 0 0" >> /etc/fstab
echo "options g_mass_storage file=/usb.bin removable=1 ro=0 stall=0 iSerialNumber=123456" > /etc/modprobe.d/g_mass_storage.conf
- Allocate RAM drive with 80% of available memory:
echo "tmpfs /mnt/ram tmpfs nodev,nosuid,size=80% 0 0" >> /etc/fstab
- Update system packages, upgrade and install required software:
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
apt update && apt upgrade -y
apt install -y nodejs ffmpeg
sed -i 's/exit 0//g' /etc/rc.local
echo "/usr/sbin/modprobe g_mass_storage >> /var/log/syslog 2>&1" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
- Install Tailscale and click the authorize link to add this machine to your network. If you get an error, reboot the box, run ```sudo -i`` and try this step again.
curl -fsSL https://tailscale.com/install.sh | sh
tailscale up
- Download and install TeslaBox and packages:
cd /root
mkdir -p /root/teslabox
curl -o main.zip https://codeload.github.com/VirtualL/teslabox/zip/refs/heads/main
unzip -o main.zip
cp -r teslabox-main/* teslabox
rm -rf teslabox-main
cd teslabox
npm install --production
npm prune
- Finalize the TeslaBox service:
- First, create the service file:
nano /lib/systemd/system/teslabox.service
- Paste this, with each Environment variable appended with its =value (if needed):
[Unit]
Description=TeslaBox
After=network.target
[Service]
Environment="NODE_ENV=production"
# To enable archive and/or email, enter these
Environment="LINODE_ACCESS_KEY_ID="
Environment="LINODE_SECRET_ACCESS_KEY="
Environment="LINODE_DEFAULT_REGION="
Environment="LINODE_S3_BUCKET="
Environment="LINODE_S3_ENDPOINT="
# To enable telegram notification, enter this
Environment="TELEGRAM_ACCESS_TOKEN="
# If your run other projects, like Tesla Android, change the port number to avoid conflict
Environment="ADMIN_PORT=80"
Type=simple
User=root
ExecStart=/usr/bin/node /root/teslabox/src/index.js
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
- Install the service to start at every boot as follows:
systemctl daemon-reload
systemctl enable teslabox
systemctl start teslabox
systemctl status teslabox
If the status is Green and shows active (running), continue to setup.
- Install Docker and Docker Compose
apt install -y docker docker-compose
- Create a docker compose file:
nano /root/docker-compose.yml
- Paste this, with the environments variables ENCRYPTION_KEY and DATABASE_PASS/POSTGRES_PASSWORD/DATABASE_PASS replaced with actual secrets:
version: "3" services: teslamate: image: teslamate/teslamate:latest restart: always environment: - ENCRYPTION_KEY= - DATABASE_USER=teslamate - DATABASE_PASS= - DATABASE_NAME=teslamate - DATABASE_HOST=database - MQTT_HOST=mosquitto ports: - 4000:4000 volumes: - ./import:/opt/app/import cap_drop: - all dns: - 1.1.1.1 - 1.0.0.1 - 8.8.8.8 - 8.8.4.4 - 9.9.9.9 - 149.112.112.112 database: image: postgres:14 restart: always environment: - POSTGRES_USER=teslamate - POSTGRES_PASSWORD= - POSTGRES_DB=teslamate volumes: - teslamate-db:/var/lib/postgresql/data grafana: image: teslamate/grafana:latest restart: always environment: - DATABASE_USER=teslamate - DATABASE_PASS= - DATABASE_NAME=teslamate - DATABASE_HOST=database - GF_AUTH_ANONYMOUS_ENABLED=true - GF_AUTH_ANONYMOUS_ORG_ROLE=Editor ports: - 3000:3000 volumes: - teslamate-grafana-data:/var/lib/grafana mosquitto: image: eclipse-mosquitto:2 restart: always command: mosquitto -c /mosquitto-no-auth.conf # ports: # - 1883:1883 volumes: - mosquitto-conf:/mosquitto/config - mosquitto-data:/mosquitto/data volumes: teslamate-db: teslamate-grafana-data: mosquitto-conf: mosquitto-data:
- Run docker
docker-compose up -d
- Connect (or Re-connect) TeslaBox to your computer via USB cable and wait for it to appear as drive
- Create an empty
TeslaCam
under the root folder of the drive - Make sure TeslaBox is connected to your home network via ethernet cable or home WiFi
- Browse to the hostname you have setup to change these settings if needed:
- Car name (associates with each upload and notification. Default: My Tesla)
- Log level (log verbosity. Default: Warn)
- Email recipients (comma seperated list of email addresses to notify)
- Telegram recipients (comma seperated list of Telegram Chat IDs to notify)
- Notifications (notifications to send. Low storage to alert when the box has little to no space. Early warning to send an immediate text on each event (~10 seconds). Early warning video to send a short video on each event (~30 seconds). Full video to send the entire video (~10 minutes), with Telegram declining files > 20MB (Default: Low storage & Early warning video)
- Create dashcam clips (uploads and notifies of dashcam/track events. Default: Enabled)
- Quality (the higher you set this, the more space each clip would take. Default: Medium)
- Duration (the longer you set this, the more time and space each clip would take. Default: 45)
- Create sentry clips (uploads and notifies of sentry events. Default: Enabled)
- Cinematic mode (create a single, moving angle view based on simple motion detection. Default: Disabled)
- Quality (the higher you set this, the more space each clip would take. Default: High)
- Duration (the longer you set this, the more time and space each clip would take. Default: 30)
- Ignore angles (do not upload or notify of sentry events from these angles. Note this will reset to default on every run. Default: none)
- Stream (enables streaming. Default: Disabled)
- Copy streams (uploads streams to remote location. Default: Disabled)
- Quality (the higher you set this, the more space each clip would take. Default: High)
- Stream angles (angles to process. Default: front)
- Under DNS -> Nameservers, note the hostname suffix MagicDNS has generated (something like tailnet-1234.ts.net). Your magic {hostname} is the machine name followed by this suffix (i.e model3.tailnet-1234.ts.net)
- Under DNS -> Nameservers -> Global nameservers, enable "Override local DNS" and add Google, CloudFlare & Quad9 Public DNS
- Configure TeslaMate under http://{hostname}:4000
- Add an access and refresh token from a secondary Tesla account using 3rd party token generator
- Set your Home Geo-Fence and charging rate
- Under settings, set your language/units
- Under settings, set Web App URL as http://{hostname}:4000 and Dashboards as http://{hostname}:3000 with {hostname} replaced to your magic hostname
- Access Grafana dashboards through the TeslaMate Web App URL at http://{hostname}:4000
- Alternatively, setup and configure your dashboards under http://{hostname}:3000
TeslaBox works best with in-car WiFi. I personally use a 4G USB access point plugged into the main console with a short USB-A (female) to USB-C (male) cable. You can also use your mobile WiFi hotspot, or wait for the car to use your home WiFi as you park.
Settings are explained above under Initial setup and always available at: http://{hostname}
Tesla would recognize the TeslaBox as standard USB. You can click save, honk or use voice commands to capture dashcam clips as you would normally. Just make sure the TeslaBox is connected properly and the "Record/ing" has a Red dot on the car quick-settings screen.
If dashcam processing is enabled, clips will be uploaded to S3. If email and/or Telegram has been set up, you'll be notified there with a quick preview and a link to both the event location map and the full video.
The clip would start 0.9X seconds prior to the event ("red dot") and 0.1X seconds following the event. X is settable under Admin > Dashcam duration.
If sentry processing is enabled and sentry mode is activated in the car, then similarly to dashcam each event will be uploaded to S3 and notified.
The clip would start 0.4X seconds prior to the event ("red dot") and 0.6X seconds following the event. X is settable under Admin > Sentry duration.
The camera that sensed the event first will be enlarged compared to the others.
Dashcam and sentry videos are always available through the Dashcam app on your Tesla, or by connecting TeslaBox using USB cable to your computer.
This is similar to Tesla's Live Sentry, but has no time limit, can stream while driving plus available on any browser. To some extent, you can use it as a security camera.
There is, however, a 1 minute delay for each clip which is the time it takes to close and prepare the file. You can choose what angles to stream and switch between them. Video would automatically progress to the next minute when it is done playing.
If sentry mode is disabled or car is asleep, you may not see any new streams.
You can also request for each stream to automatically upload to S3.
TeslaBox neither use any Tesla API nor requires any Tesla token. It only replaces your Tesla's standard USB or SSD drive with Micro-SD card on a Raspberry Pi.
You can delete individual (or all) videos under "Safety" or through the Dashcam app on your Tesla, but do not format the drive. It will render the TeslaBox useless.
There might be risks involved with running TeslaBox under certain tempature conditions, TeslaBox not recording dashcam or sentry videos and/or TeslaBox not uploading, delivering or notifying you of such events. Always make sure Tesla recognizes a valid USB storage, and that videos are saved and viewable through the built-in Dashcam app.
There might be AWS costs associated with archiving (both storing and viewing clips). See S3 pricing.
There might be 3G/4G bandwidth costs associated with your WiFi connectivity. If you are worried you can have TeslaBox connect only to your home or public WiFi.
- You can now click "Upgrade" from the Admin console
- Alternatively, SSH to your Raspberry Pi and run the following to download the latest code, install and restart the service:
sh /root/teslabox/upgrade.sh
TeslaBox is for PRIVATE, NON-COMMERCIAL, NON-GOVERNMENTAL USE ONLY!
TeslaBox is not affiliated or supported by Tesla. There is no official support whatsoever. As per the license this is provided As-Is. Use at your own risk!
Please open an issue if things seems out of order and I'll attend them as time allows.
TeslaBox wouldn't be possible without the help of teslausb, tesla_dashcam and friends at TeslaFansIL.