Skip to content

This Repository includes a Flutter Package to handle the Tesla Owner API

License

Notifications You must be signed in to change notification settings

PlaxXOnline/tesla_owner_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tesla Owner API

Warning

Please note that this is an unofficial API, using https://www.teslaapi.io/, and therefore, we cannot guarantee its functionality. It's recommended to use it with caution as changes in the official API can break this library. Always ensure you're adhering to Tesla's terms of service while using this API.

pub package GitHub stars

The TeslaAPI is the main class for accessing the Tesla Owner API. It includes properties for authentication and for accessing different parts of the Tesla Owner API.

Properties

  • auth: An instance of the Auth class used for authentication.
  • energySites: An instance of the EnergySites class used for interacting with energy sites.
  • powerWalls: An instance of the PowerWalls class used for interacting with Powerwalls.
  • products: An instance of the Products class used for interacting with Tesla products.
  • user: An instance of the User class used for interacting with the user's account.
  • vehicles: An instance of the Vehicles class used for interacting with the user's Tesla vehicles.

Constructors

TeslaAPI.auth()

Creates a TeslaAPI instance with authentication. This constructor initializes the auth property for authentication purposes.

Usage

var teslaAPIAuth = TeslaAPI.auth();
String accessToken = teslaAPIAuth.getAccessToken(String email, String password,
    String clientId, String clientSecret);

TeslaAPI(String token)

Creates a TeslaAPI instance with an access token. This constructor initializes various properties for accessing different parts of the Tesla Owner API using the provided access token.

Parameters

  • token: The access token to authenticate requests.

Usage

var teslaAPI = TeslaAPI('your_access_token_here');

Now you can use all the Methods like

var user = teslaAPI.user;
var energysites = teslaAPI.energysites;
var powerwalls = teslaAPI.powerwalls;
var products = teslaAPI.products;

Features

User

Future getPowerwallOrderEntryData()

Fetches Powerwall order entry data for a user. Returns a Response object containing the data. Throws an Exception if the request fails.

var powerwallOrderEntryData = await teslaAPI.user.getPowerwallOrderEntryData();

Future getOnboardingData()

Fetches onboarding data for a user. Returns a Response object containing the data. Throws an Exception if the request fails.

var onboardingData = await teslaAPI.user.getOnboardingData();

Future getReferralData()

Fetches referral data for a user. Returns a Response object containing the data. Throws an `Exception if the request fails.

var referralData = await teslaAPI.user.getReferralData();

Future sendDeviceKey(String deviceKey)

Sends a device key. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • deviceKey: The device key to be sent.
var response = await teslaAPI.user.sendDeviceKey('your_device_key_here');

Future sendCommandToken(String commandToken)

Sends a command token. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • commandToken: The command token to be sent.
var response = await teslaAPI.user.sendCommandToken('your_command_token_here');
EnergySites

State and Settings

Future siteStatusSummary(int siteId)

Fetches the status summary for a specific site. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • siteId: The ID of the site.
Response siteStatusSummary = await teslaAPI.energysites.siteStatusSummary('your_site_id_here');

Future siteLiveStatusData(int siteId)

Fetches the live status data for a specific site. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • siteId: The ID of the site.
Response siteLiveStatusData = await teslaAPI.energysites.siteLiveStatusData('your_site_id_here');

Future siteConfiguration(int siteId)

Fetches the configuration information for a specific site. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • siteId: The ID of the site.
Response siteConfiguration = await teslaAPI.energysites.siteConfiguration('your_site_id_here');

Future siteHistory(int siteId)

Fetches the historical data for a specific site. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • siteId: The ID of the site.
Response siteHistory = await teslaAPI.energysites.siteHistory('your_site_id_here');

Commands

Future backupEnergyReserve(int siteId)

Sets the backup energy reserve for a specific energy site. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • siteId: The ID of the site.
Response reserveResult = await teslaAPI.energysites.commands.backupEnergyReserve('your_site_id_here');

Future siteName(int siteId)

Fetches the historical data for a specific site. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • siteId: The ID of the site.
Response siteName = await teslaAPI.energysites.commands.siteName('your_site_id_here');

Future operationMode(int siteId)

Fetches the operation mode for a specific site. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • siteId: The ID of the site.
Response operationMode = await teslaAPI.energysites.commands.operationMode('your_site_id_here');

Future timeOfUseSettings(int siteId)

Fetches the time of use settings for a specific site. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • siteId: The ID of the site.
Response timeOfUseSettings = await teslaAPI.energysites.commands.timeOfUseSettings('your_site_id_here');

Future stormMode(int siteId)

Fetches the storm mode for a specific site. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • siteId: The ID of the site.
Response stormMode = await teslaAPI.energysites.commands.stormMode('your_site_id_here');
PowerWalls

State and Settings

Future getBatteryStatus(int batteryId)

Fetch the current Battery Status. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • batteryId: The ID of the battery.
Response batteryStatus = await teslaAPI.powerwalls.commands.getBatteryStatus('your_battery_id_here');

Future getBatteryData(int batteryId)

Fetch the current Battery Data. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • batteryId: The ID of the battery.
Response batteryData = await teslaAPI.powerwalls.commands.getBatteryData('your_battery_id_here');

Future getBatteryPowerTimeSeriesData(int batteryId)

Fetch the Battery Power Time-series Data. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • batteryId: The ID of the battery.
Response batteryPowerTimeSeriesData = await teslaAPI.powerwalls.commands.getBatteryPowerTimeSeriesData('your_battery_id_here');

Future getBatteryEnergyTimeSeriesData(int batteryId)

Fetch the Battery Power Time-series Data. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • batteryId: The ID of the battery.
Response batteryEnergyTimeSeriesData = await teslaAPI.powerwalls.commands.getBatteryEnergyTimeSeriesData('your_battery_id_here');

Commands

Future backupBatteryReserve(int batteryId)

Backup the Battery Reserve. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • batteryId: The ID of the battery.
Response backupBatteryReserve = await teslaAPI.powerwalls.commands.batterySiteName('your_battery_id_here');

Future batterySiteName(int batteryId)

Fetches the site name of a specific battery. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • batteryId: The ID of the battery.
Response batterySiteName = await teslaAPI.powerwalls.commands.backupBatteryReserve('your_battery_id_here');

Future batteryOperationMode(int batteryId)

Fetches the operation mode of a specific battery. Returns a Response object containing the data. Throws an `Exception if the request fails.

Parameters
  • batteryId: The ID of the battery.
Response batteryOperationMode = await teslaAPI.powerwalls.commands.batteryOperationMode('your_battery_id_here');
Products

Future getProducts()

Fetches a list of products. Returns a Response object containing the data. Throws an `Exception if the request fails.

var productsList = await teslaAPI.products.getProducts();
Vehicles

List

Future getAllVehicles()

Fetches a list of vehicles. Returns a VehicleList object containing the data. Throws an `Exception if the request fails.

VehicleList allVehicles = await teslaAPI.vehicles.getAllVehicles();

Future getSpecificVehicle(String id)

Fetches data for a specific vehicle. Returns a Vehicle object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
Vehicle specificVehicle = await teslaAPI.vehicles.getSpecificVehicle('your_vehicle_id_here');

State and Settings

Future getLegacyVehicleData(String id)

Fetches the legacy vehicle data. Returns a Vehicle object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
Vehicle legacyVehicleData = await teslaAPI.vehicles.getLegacyVehicleData('your_vehicle_id_here');

Future getVehicleData(String id)

Fetches the vehicle data. Returns a Vehicle object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
Vehicle vehicleData = await teslaAPI.vehicles.getVehicleData('your_vehicle_id_here');

Future getVehicleServiceData(String id)

Fetches the vehicle service data. Returns a Vehicle object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
Vehicle vehicleServiceData = await teslaAPI.vehicles.getVehicleServiceData('your_vehicle_id_here');

Future isMobileEnabled(String id)

Checks if mobile is enabled for the vehicle. Returns a bool indicating whether mobile is enabled. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
bool isMobileEnabled = await teslaAPI.vehicles.isMobileEnabled('your_vehicle_id_here');

Future getChargeState(String id)

Fetches the charge state of the vehicle. Returns a ChargeState object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ChargeState chargeState = await teslaAPI.vehicles.getChargeState('your_vehicle_id_here');

Future getClimateState(String id)

Fetches the climate state of the vehicle. Returns a ClimateState object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ClimateState climateState = await teslaAPI.vehicles.getClimateState('your_vehicle_id_here');

Future getDriveState(String id)

Fetches the drive state of the vehicle. Returns a DriveState object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
DriveState driveState = await teslaAPI.vehicles.getDriveState('your_vehicle_id_here');

Future getGUISettings(String id)

Fetches the GUI settings of the vehicle. Returns a GuiSettings object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
GuiSettings guiSettings = await teslaAPI.vehicles.getGUISettings('your_vehicle_id_here');

Commands

Future wakeUp(String id)

Wakes up the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.wakeUp('your_vehicle_id_here');

Future unlockDoors(String id)

Unlocks the doors of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.unlockDoors('your_vehicle_id_here');

Future lockDoors(String id)

Locks the doors of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.lockDoors('your_vehicle_id_here');

Future honkHorn(String id)

Honks the horn of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.honkHorn('your_vehicle_id_here');

Future flashLights(String id)

Flashes the lights of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.flashLights('your_vehicle_id_here');

Future startHVACSystem(String id)

Starts the Air Conditioning of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.startHVACSystem('your_vehicle_id_here');

Future stopHVACSystem(String id)

Stops the Air Conditioning of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.stopHVACSystem('your_vehicle_id_here');

Future setTemperature(String id, int driverTemp, int passengerTemp)

Sets the temperature of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
  • driverTemp: The desired temperature for the driver in Celsius.
  • passengerTemp: The desired temperature for the passenger in Celsius.
ResponseModel response = await teslaAPI.vehicles.commands.setTemperature('your_vehicle_id_here', 22, 22);

Future setChargeLimit(String id, int limit)

Sets the charge limit of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
  • limit: The charge limit in percent.
ResponseModel response = await teslaAPI.vehicles.commands.setChargeLimit('your_vehicle_id_here', 80);

Future setMAXChargeLimit(String id)

Sets the charge limit of the vehicle to MAX. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.setMAXChargeLimit('your_vehicle_id_here');

Future setStandardChargeLimit(String id)

Sets the charge limit of the vehicle to Standard. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.setStandardChargeLimit('your_vehicle_id_here');

Future setSunRoof(String id, SunRoofStates state)

Sets the state of the sunroof of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
  • state: The desired SunRoofStates.
ResponseModel response = await teslaAPI.vehicles.commands.setSunRoof('your_vehicle_id_here', SunRoofStates.open);

Future openOrCloseTrunk(String id)

Opens or closes the trunk of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.openOrCloseTrunk('your_vehicle_id_here');

Future startRemoteDrive(String id, String password)

Starts vehicle key-less driving mode. The vehicle must be placed in drive within 2 minutes of the response. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
  • password: The password from my.teslamotors.com.
ResponseModel response = await teslaAPI.vehicles.commands.startRemoteDrive('your_vehicle_id_here', 'your_password_here');

Future openChargePort(String id)

Opens vehicle charge port. Also unlocks the charge port if it is locked. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.openChargePort('your_vehicle_id_here');

Future closeChargePort(String id)

Closes the charge port of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.closeChargePort('your_vehicle_id_here');

Future startCharging(String id)

Starts vehicle charging. Vehicle must be plugged in, have power available, and not at charge limit. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.startCharging('your_vehicle_id_here');

Future stopCharging(String id)

Stops vehicle charging. Vehicle must be charging. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.stopCharging('your_vehicle_id_here');

Future setValetMode(String id, bool on, int pin)

Sets vehicle valet mode on or off with a PIN to disable it from within the car. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
  • on: Valet Mode On or Off.
  • pin: The four-digit PIN.
ResponseModel response = await teslaAPI.vehicles.commands.setValetMode('your_vehicle_id_here', true, 1234);

Future resetValetPIN(String id)

Resets vehicle valet PIN. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.resetValetPIN('your_vehicle_id_here');

Future activateSpeedLimit(String id)

Activates the speed limit of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.activateSpeedLimit('your_vehicle_id_here');

Future deactivateSpeedLimit(String id)

Deactivates the speed limit of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.deactivateSpeedLimit('your_vehicle_id_here');

Future setSpeedLimit(String id)

Sets the speed limit of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.setSpeedLimit('your_vehicle_id_here');

Future clearSpeedLimitPIN(String id)

Clears the speed limit PIN of the vehicle. Returns a ResponseModel object containing the data. Throws an `Exception if the request fails.

Parameters
  • id: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.clearSpeedLimitPIN('your_vehicle_id_here');

About

This Repository includes a Flutter Package to handle the Tesla Owner API

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages