Skip to content
TelsaPi is a security alarm project that integrates an outdoor motion sensor with the headlights and horn of a Tesla car.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
TeslaPi.py
gps.py
vars.py Add files via upload Jun 18, 2019

README.md

TeslaPi

TelsaPi is a security alarm project that integrates an outdoor motion sensor with the headlights and horn of a Tesla car. It works with all models. The project uses a Raspberry Pi, an outdoor PIR motion detector, and the Tesla API. The code is written in the Python programming language.

Written by Mike Haldas

Video Demo

Tesla API Security Alarm Priject with Raspberry Pi

Watch this YouTube video to see a demo of the Tesla Pi project.


Project Files

  • TeslaPi.py - this is the main project file that runs all of the alarm code.
  • vars.py - I wanted to keep the Tesla API login and password in a separate file so I would not accidentally upload updates to TelsaPi.py with my login credentials in it.
  • gps.py - simple script that logs into the Tesla API and gets the current GPS longitute and lattitute location of your car. I will use this in the future when I implement GPS location checking into the TeslaPi project.

Installation

Integration with the Telsa API is done using the TeslaJSON API wrapper written by Greg Glockner. (https://github.com/gglockner/teslajson).

Greg's library is a pleasure to work with and made it very easy to develop TeslaPi quickly.

Open the terminal program on your Raspbery Pi run the following commands. Please note that before you run the program, you should also complete the wiring setup in the next section.

  1. wget https://github.com/gglockner/teslajson/archive/master.zip
  2. unzip master.zip
  3. cd teslajson-master
  4. sudo python setup.py install
  5. cd ..
  6. rm master.zip
  7. wget https://github.com/mikehaldas/TeslaPi/archive/master.zip
  8. unzip master.zip
  9. cd TeslaPi-master
  10. Edit the vars.py file. You should enter your user ID and password that you use on the teslamotors.com website for the USERID and PASS variables, then save the file and exit.
  11. To start the program, python TeslaPi.py

If you want to test the API communication with your Tesla before you wire the motion detector to your Raspberry Pi, you can run the following command: python gps.py

This will connect to your car and print the GPS longitute and lattitute. If the program gives you an error the first time you run it, try to run it again. If you car is sleeping the first time it is run and takes a while to wake up, there may be an error. This is a bug that needs to be fixed. Try to run it again.

The gps.py script will be used in the future to setup GPS location verification of your Tesla to determine if it should be used in the alarm. For example, you may not want to flash your lights and sound your horn unless the car is parked in the lcoation to be effective for the alarm.

Raspberry Pi / Motion Sensor Wiring

Raspberry Pi Motion Sensor Alarm

Here is a link to the outdoor motion sensor that was used to test this project. Please note that it is shown in the above wiring diagram with the front cover removed to show the location of the power and output terminals. https://www.cctvcamerapros.com/PIR-Outdoor-Motion-Sensor-p/takex-ms-100e.htm
This is how it is wired.
  1. The outputs of the motion sensor are wired to GPIO 16 pin and a ground pin on the Raspberry Pi.
  2. A 12V DC power supply is used to power the motion detector.
  3. Although not pictured, the Raspberry Pi obviously also needs to be connected to a power source.
  4. The Raspberry Pi must be connected to an Internet connection, so that it can communicate with the Tesla API.

TelsaPi Alarm System Logic

There are a lot of comments in the TeslaPi.py program that explain the logic of the application. The program basically works as follows.
  • After you run TeslaPi.py, a connection is initiated to your Tesla.
  • The program waits for the motion detector to sense motion.
  • When motion is detected, an alarm cycle begins.
  • An alarm cycle consists of a duration and 5 escalation levels.
  • Each escalation level has it's own set of alarm actions that can be easily modified. For example: level 1 - flash headlight 3x, level 2, flash headlights 3x and beep horn 1x, level 3 - flash lights 5x and beep horn 2x, etc.
  • If motion is continuous or occurs again within the alarm cycle threshold, the escalation level is incremented.
  • The escalation level resets after level 5 or if the alarm cycle threshold time has passed.

Disclosure and Use

Please note that I would not consider this a production ready security application by any means. I created this project for fun shortly after I took delivery of my Model 3 Tesla. Please use it with that in mind and at your own risk.

This software is provided as-is. This software is not supported by or endorsed by Tesla Inc. Tesla Inc. does not publicly support the underlying JSON API, so this software may stop working at any time. The author makes no guarantee to release an updated version to fix any incompatibilities.

You can’t perform that action at this time.