名称: tesla-fleet-api
描述: 用于与特斯拉官方车队 API 集成,以读取车辆/能源设备数据或执行远程命令(例如启动 HVAC 预调节、唤醒车辆、充电控制)。涵盖入门(开发者应用注册、区域/基础 URL)、OAuth 令牌流程(第三方 + 合作伙伴令牌、刷新轮换)、必需的域名/公钥托管,以及使用特斯拉官方的 vehicle-command/tesla-http-proxy 进行签名的车辆命令。
版本: 1.5.0
主页: https://github.com/odrobnik/tesla-fleet-api-skill
元数据:
openclaw:
emoji: "🚗"
requires:
bins: ["python3", "openssl"]
env: ["TESLA_CLIENT_ID", "TESLA_CLIENT_SECRET"]
optionalEnv: ["TESLA_AUDIENCE", "TESLA_REDIRECT_URI", "TESLA_DOMAIN", "TESLA_BASE_URL", "TESLA_CA_CERT", "TESLA_ACCESS_TOKEN", "TESLA_REFRESH_TOKEN", "TESLA_SCOPE"]
通过官方车队 API 控制特斯拉车辆。
| 脚本 | 用途 |
|---|---|
command.py |
车辆命令(空调、充电、锁等) |
vehicle_data.py |
读取车辆数据(电池、空调、位置等) |
vehicles.py |
列出车辆 + 刷新缓存 |
auth.py |
身份验证与配置 |
tesla_oauth_local.py |
带本地回调服务器的 OAuth 助手 |
start_proxy.sh |
启动签名代理(用于车辆命令) |
stop_proxy.sh |
停止签名代理 |
设置步骤记录在 SETUP.md 中:
状态目录:{workspace}/tesla-fleet-api/
- config.json(提供商凭据 + 非令牌配置)
- auth.json(令牌)
- vehicles.json(缓存的车辆列表)
- places.json(命名位置)
- proxy/(签名代理的 TLS 材料)
不加载 .env 文件 —— 凭据存储在 config.json 或环境变量中。
在您的特斯拉上执行命令。如果只有一辆车,车辆会自动被选中。
command.py [车辆] <命令> [选项]
车辆 - 车辆名称或 VIN(如果只有一辆车则为可选)command.py honkcommand.py flash honk(车辆 "flash",命令 "honk")command.py climate start
command.py climate stop
command.py flash climate start # 指定车辆
command.py climate temps <驾驶员温度> [乘客温度]
command.py climate temps 21 # 两个座位均为 21°C
command.py climate temps 22 20 # 驾驶员 22°C,乘客 20°C
command.py climate keeper <模式>
模式:off, keep, dog, camp
command.py seat-heater --level <级别> [--position <位置>]
command.py seat-heater -l <级别> [-p <位置>]
级别:
| 值 | 名称 |
|-------|------|
| 0 | off |
| 1 | low |
| 2 | medium |
| 3 | high |
位置:
| 值 | 名称 |
|-------|-------|
| 0 | driver, front_left, fl |
| 1 | passenger, front_right, fr |
| 2 | rear_left, rl |
| 3 | rear_left_back |
| 4 | rear_center, rc |
| 5 | rear_right, rr |
| 6 | rear_right_back |
| 7 | third_left |
| 8 | third_right |
示例:
command.py seat-heater -l high # 驾驶员(默认)
command.py seat-heater -l medium -p passenger
command.py seat-heater --level low --position rear_left
command.py seat-heater -l 2 -p 4 # 中等,后排中间
command.py seat-heater -l off -p driver # 关闭
command.py seat-cooler --level <级别> [--position <位置>]
command.py seat-cooler -l <级别> [-p <位置>]
级别和位置与座椅加热相同。
示例:
command.py seat-cooler -l medium -p driver
command.py seat-cooler -l high -p passenger
command.py seat-climate [--position <位置>] <模式>
command.py seat-climate [-p <位置>] <模式>
模式:auto, on, off
示例:
command.py seat-climate auto # 驾驶员自动
command.py seat-climate -p passenger auto
command.py seat-climate -p driver off # 禁用自动
command.py steering-heater <on|off>
示例:
command.py steering-heater on
command.py steering-heater off
用于安排出发预调节的现代 API(已弃用 set_scheduled_departure)。
command.py precondition add --time <HH:MM> [--days <天数>] [--id <ID>] [--one-time] [--disabled]
command.py precondition add -t <HH:MM> [-d <天数>] [--id <ID>]
天数选项:
| 值 | 描述 |
|-------|-------------|
| all | 每天(默认) |
| weekdays | 周一到周五 |
| weekends | 周六和周日 |
| mon,tue,wed,... | 特定日期(逗号分隔) |
日期名称:sun, mon, tue, wed, thu, fri, sat(或全称)
示例:
command.py precondition add -t 08:00 # 每天上午 8 点
command.py precondition add -t 08:00 -d weekdays # 周一至周五
command.py precondition add -t 07:30 -d mon,wed,fri
command.py precondition add -t 09:00 --one-time # 仅一次
command.py precondition add -t 08:30 --id 123 # 修改现有计划
command.py precondition add -t 08:00 --disabled # 创建但禁用
command.py precondition remove --id <ID>
示例:
command.py precondition remove --id 123
command.py precondition remove --id 1
command.py charge start
command.py charge stop
command.py charge limit <百分比>
百分比必须在 50-100 之间。
示例:
command.py charge limit 80
command.py charge limit 90
command.py flash charge limit 70 # 指定车辆
command.py lock # 锁上所有车门
command.py unlock # 解锁所有车门
command.py honk # 鸣喇叭
command.py flash # 闪烁车灯
command.py wake # 唤醒休眠车辆
指定车辆名称:
command.py flash wake # 唤醒名为 "flash" 的车辆
command.py flash flash # 对车辆 "flash" 闪烁车灯
默认以人类可读格式获取车辆数据。
vehicle_data.py [车辆] [标志] [--json]
车辆 - 车辆名称或 VIN(如果只有一辆车则为可选)--json = 原始 JSON 输出| 标志 | 长标志 | 数据 |
|---|---|---|
-c |
--charge |
电池电量、充电限制、充电状态 |
-t |
--climate |
车内/车外温度、HVAC 状态 |
-d |
--drive |
档位、速度、功率、航向 |
-l |
--location |
GPS 坐标 |
-s |
--state |
锁、车门、车窗、里程表、软件 |
-g |
--gui |
GUI 设置(单位、24 小时制) |
--config-data |
车辆配置(型号、颜色、轮毂) |
# 所有数据
vehicle_data.py
vehicle_data.py flash
# 特定数据
vehicle_data.py -c # 仅充电数据
vehicle_data.py -c -t # 充电 + 空调数据
vehicle_data.py flash -c -l # 充电 + 位置数据
# 原始 JSON
vehicle_data.py --json
vehicle_data.py -c --json
🚗 我的特斯拉 (在线)
VIN: 5YJ... (已脱敏)
⚡ 充电状态
────────────────────────────────────────
电池: [███████████████░░░░░] 78%
限制: 80%
状态: 充电中
功率: 11 kW (16A × 234V × 3φ)
已充入: 37.2 kWh
剩余时间: 10m
续航: 438 km (272 mi)
电缆: IEC
🌡️ 空调状态
────────────────────────────────────────
车内: 11.9°C
车外: 6.0°C
设定温度: 20.5°C
空调: 关闭
管理 OAuth 令牌和配置。
auth.py <命令> [选项]
auth.py login
交互式:生成认证 URL,提示输入代码,交换令牌。
auth.py exchange <代码>
将授权码交换为令牌(非交互式)。
auth.py refresh
刷新访问令牌。注意:刷新令牌会轮换 —— 新令牌会自动保存。
auth.py register --domain <域名>
向特斯拉注册您的应用域名(签名命令必需)。
注册后,注册您的虚拟钥匙:
https://tesla.com/_ak/<域名>
auth.py config
显示当前配置(敏感信息已脱敏)。
auth.py config set [选项]
选项:
- --client-id <ID>
- --client-secret <密钥>
- --redirect-uri <URI>
- --audience <URL>
- --base-url <URL>
- --ca-cert <路径>
- --domain <域名>
示例:
# 初始设置
auth.py config set \
--client-id "abc123" \
--client-secret "secret" \
--redirect-uri "http://localhost:18080/callback"
# 配置代理
auth.py config set \
--base-url "https://localhost:4443" \
--ca-cert "/path/to/tls-cert.pem"
以人类可读格式列出车辆。
python3 scripts/tesla_fleet.py vehicles
python3 scripts/tesla_fleet.py vehicles --json
🚗 名称: 我的特斯拉
🔖 VIN: 5YJ... (已脱敏)
🟢 状态: 在线
👤 访问权限: 所有者
所有设置 + 配置记录在 SETUP.md 中。
| 区域 | Audience URL |
|---|---|
| 欧洲 | https://fleet-api.prd.eu.vn.cloud.tesla.com |
| 北美 | https://fleet-api.prd.na.vn.cloud.tesla.com |
| 中国 | https://fleet-api.prd.cn.vn.cloud.tesla.cn |
OAuth 令牌端点(所有区域):
https://fleet-auth.prd.vn.cloud.tesla.com/oauth2/v3/token
先唤醒车辆:
command.py wake
确保签名代理正在运行且已配置。参见 SETUP.md § 代理设置。
auth.py refresh
通过名称或 VIN 指定车辆:
command.py flash climate start
command.py 5YJ... honk
climate start|stop
climate temps <驾驶员温度> [乘客温度]
climate keeper off|keep|dog|camp
seat-heater -l <级别> [-p <位置>]
seat-cooler -l <级别> [-p <位置>]
seat-climate [-p <位置>] auto|on|off
steering-heater on|off
precondition add -t <HH:MM> [-d <天数>] [--id <ID>] [--one-time]
precondition remove --id <ID>
charge start|stop
charge limit <百分比>
lock
unlock
honk
flash
wake
[车辆] [-c] [-t] [-d] [-l] [-s] [-g] [--config-data] [--json]
login
exchange <代码>
refresh
register --domain <域名>
config
config set [--client-id] [--client-secret] [--redirect-uri] [--audience] [--base-url] [--ca-cert] [--domain]