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.
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.
auth
: An instance of theAuth
class used for authentication.energySites
: An instance of theEnergySites
class used for interacting with energy sites.powerWalls
: An instance of thePowerWalls
class used for interacting with Powerwalls.products
: An instance of theProducts
class used for interacting with Tesla products.user
: An instance of theUser
class used for interacting with the user's account.vehicles
: An instance of theVehicles
class used for interacting with the user's Tesla vehicles.
Creates a TeslaAPI
instance with authentication. This constructor initializes the auth
property for authentication purposes.
var teslaAPIAuth = TeslaAPI.auth();
String accessToken = teslaAPIAuth.getAccessToken(String email, String password,
String clientId, String clientSecret);
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.
token
: The access token to authenticate requests.
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;
User
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();
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();
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();
Sends a device key. Returns a Response
object containing the data. Throws an `Exception if the request fails.
deviceKey
: The device key to be sent.
var response = await teslaAPI.user.sendDeviceKey('your_device_key_here');
Sends a command token. Returns a Response
object containing the data. Throws an `Exception if the request fails.
commandToken
: The command token to be sent.
var response = await teslaAPI.user.sendCommandToken('your_command_token_here');
EnergySites
Fetches the status summary for a specific site. Returns a Response
object containing the data. Throws an `Exception if the request fails.
siteId
: The ID of the site.
Response siteStatusSummary = await teslaAPI.energysites.siteStatusSummary('your_site_id_here');
Fetches the live status data for a specific site. Returns a Response
object containing the data. Throws an `Exception if the request fails.
siteId
: The ID of the site.
Response siteLiveStatusData = await teslaAPI.energysites.siteLiveStatusData('your_site_id_here');
Fetches the configuration information for a specific site. Returns a Response
object containing the data. Throws an `Exception if the request fails.
siteId
: The ID of the site.
Response siteConfiguration = await teslaAPI.energysites.siteConfiguration('your_site_id_here');
Fetches the historical data for a specific site. Returns a Response
object containing the data. Throws an `Exception if the request fails.
siteId
: The ID of the site.
Response siteHistory = await teslaAPI.energysites.siteHistory('your_site_id_here');
Sets the backup energy reserve for a specific energy site. Returns a Response
object containing the data. Throws an `Exception if the request fails.
siteId
: The ID of the site.
Response reserveResult = await teslaAPI.energysites.commands.backupEnergyReserve('your_site_id_here');
Fetches the historical data for a specific site. Returns a Response
object containing the data. Throws an `Exception if the request fails.
siteId
: The ID of the site.
Response siteName = await teslaAPI.energysites.commands.siteName('your_site_id_here');
Fetches the operation mode for a specific site. Returns a Response
object containing the data. Throws an `Exception if the request fails.
siteId
: The ID of the site.
Response operationMode = await teslaAPI.energysites.commands.operationMode('your_site_id_here');
Fetches the time of use settings for a specific site. Returns a Response
object containing the data. Throws an `Exception if the request fails.
siteId
: The ID of the site.
Response timeOfUseSettings = await teslaAPI.energysites.commands.timeOfUseSettings('your_site_id_here');
Fetches the storm mode for a specific site. Returns a Response
object containing the data. Throws an `Exception if the request fails.
siteId
: The ID of the site.
Response stormMode = await teslaAPI.energysites.commands.stormMode('your_site_id_here');
PowerWalls
Fetch the current Battery Status. Returns a Response
object containing the data. Throws an `Exception if the request fails.
batteryId
: The ID of the battery.
Response batteryStatus = await teslaAPI.powerwalls.commands.getBatteryStatus('your_battery_id_here');
Fetch the current Battery Data. Returns a Response
object containing the data. Throws an `Exception if the request fails.
batteryId
: The ID of the battery.
Response batteryData = await teslaAPI.powerwalls.commands.getBatteryData('your_battery_id_here');
Fetch the Battery Power Time-series Data. Returns a Response
object containing the data. Throws an `Exception if the request fails.
batteryId
: The ID of the battery.
Response batteryPowerTimeSeriesData = await teslaAPI.powerwalls.commands.getBatteryPowerTimeSeriesData('your_battery_id_here');
Fetch the Battery Power Time-series Data. Returns a Response
object containing the data. Throws an `Exception if the request fails.
batteryId
: The ID of the battery.
Response batteryEnergyTimeSeriesData = await teslaAPI.powerwalls.commands.getBatteryEnergyTimeSeriesData('your_battery_id_here');
Backup the Battery Reserve. Returns a Response
object containing the data. Throws an `Exception if the request fails.
batteryId
: The ID of the battery.
Response backupBatteryReserve = await teslaAPI.powerwalls.commands.batterySiteName('your_battery_id_here');
Fetches the site name of a specific battery. Returns a Response
object containing the data. Throws an `Exception if the request fails.
batteryId
: The ID of the battery.
Response batterySiteName = await teslaAPI.powerwalls.commands.backupBatteryReserve('your_battery_id_here');
Fetches the operation mode of a specific battery. Returns a Response
object containing the data. Throws an `Exception if the request fails.
batteryId
: The ID of the battery.
Response batteryOperationMode = await teslaAPI.powerwalls.commands.batteryOperationMode('your_battery_id_here');
Products
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
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();
Fetches data for a specific vehicle. Returns a Vehicle
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
Vehicle specificVehicle = await teslaAPI.vehicles.getSpecificVehicle('your_vehicle_id_here');
Fetches the legacy vehicle data. Returns a Vehicle
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
Vehicle legacyVehicleData = await teslaAPI.vehicles.getLegacyVehicleData('your_vehicle_id_here');
Fetches the vehicle data. Returns a Vehicle
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
Vehicle vehicleData = await teslaAPI.vehicles.getVehicleData('your_vehicle_id_here');
Fetches the vehicle service data. Returns a Vehicle
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
Vehicle vehicleServiceData = await teslaAPI.vehicles.getVehicleServiceData('your_vehicle_id_here');
Checks if mobile is enabled for the vehicle. Returns a bool indicating whether mobile is enabled. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
bool isMobileEnabled = await teslaAPI.vehicles.isMobileEnabled('your_vehicle_id_here');
Fetches the charge state of the vehicle. Returns a ChargeState
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ChargeState chargeState = await teslaAPI.vehicles.getChargeState('your_vehicle_id_here');
Fetches the climate state of the vehicle. Returns a ClimateState
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ClimateState climateState = await teslaAPI.vehicles.getClimateState('your_vehicle_id_here');
Fetches the drive state of the vehicle. Returns a DriveState
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
DriveState driveState = await teslaAPI.vehicles.getDriveState('your_vehicle_id_here');
Fetches the GUI settings of the vehicle. Returns a GuiSettings
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
GuiSettings guiSettings = await teslaAPI.vehicles.getGUISettings('your_vehicle_id_here');
Wakes up the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.wakeUp('your_vehicle_id_here');
Unlocks the doors of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.unlockDoors('your_vehicle_id_here');
Locks the doors of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.lockDoors('your_vehicle_id_here');
Honks the horn of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.honkHorn('your_vehicle_id_here');
Flashes the lights of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.flashLights('your_vehicle_id_here');
Starts the Air Conditioning of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.startHVACSystem('your_vehicle_id_here');
Stops the Air Conditioning of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.stopHVACSystem('your_vehicle_id_here');
Sets the temperature of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
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);
Sets the charge limit of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.limit
: The charge limit in percent.
ResponseModel response = await teslaAPI.vehicles.commands.setChargeLimit('your_vehicle_id_here', 80);
Sets the charge limit of the vehicle to MAX. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.setMAXChargeLimit('your_vehicle_id_here');
Sets the charge limit of the vehicle to Standard. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.setStandardChargeLimit('your_vehicle_id_here');
Sets the state of the sunroof of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.state
: The desiredSunRoofStates
.
ResponseModel response = await teslaAPI.vehicles.commands.setSunRoof('your_vehicle_id_here', SunRoofStates.open);
Opens or closes the trunk of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.openOrCloseTrunk('your_vehicle_id_here');
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.
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');
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.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.openChargePort('your_vehicle_id_here');
Closes the charge port of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.closeChargePort('your_vehicle_id_here');
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.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.startCharging('your_vehicle_id_here');
Stops vehicle charging. Vehicle must be charging. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.stopCharging('your_vehicle_id_here');
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.
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);
Resets vehicle valet PIN. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.resetValetPIN('your_vehicle_id_here');
Activates the speed limit of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.activateSpeedLimit('your_vehicle_id_here');
Deactivates the speed limit of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.deactivateSpeedLimit('your_vehicle_id_here');
Sets the speed limit of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.setSpeedLimit('your_vehicle_id_here');
Clears the speed limit PIN of the vehicle. Returns a ResponseModel
object containing the data. Throws an `Exception if the request fails.
id
: The ID of the vehicle.
ResponseModel response = await teslaAPI.vehicles.commands.clearSpeedLimitPIN('your_vehicle_id_here');