tesla_owner_api 1.0.0 tesla_owner_api: ^1.0.0 copied to clipboard
Unleash the power of your Tesla products with the Tesla Owner API package. Interact with vehicles, Powerwalls, energy sites, and more. Ideal for Tesla owners and enthusiasts.
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.
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 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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 desiredSunRoofStates
.
ResponseModel response = await teslaAPI.vehicles.commands.setSunRoof('your_vehicle_id_here', SunRoofStates.open);
Future
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
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
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
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
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
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
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
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
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
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
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
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');