mcpField
T
tesla-fleet-api

tesla-fleet-api

github.com/odrobnik其他0950 次安装30 周前更新
代码仓库

关于 tesla-fleet-api

通过 Tesla 官方 Fleet API 管理车辆的命令行工具,适合需要读取车辆状态或执行远程操作的 Tesla 车主。它还提供 OAuth 配置与令牌管理。

主要功能

  1. 01控制空调、座椅与方向盘加热
  2. 02管理充电、车门与安全操作
  3. 03读取车辆状态及位置数据
  4. 04管理 OAuth 认证与车辆列表

适用场景

  1. 01远程启动空调并设置温度
  2. 02查看电量、充电状态或车辆位置
  3. 03锁车、唤醒车辆或调整充电上限

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/odrobnik/tesla-fleet-api-skill --skill tesla-fleet-api

安装后在 Claude Code 中输入/tesla-fleet-api确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

.gitignore
.clawhubignore
SETUP.md
README.md
tesla-fleet-api
scripts/
stop_proxy.sh
command.py
start_proxy.sh
auth.py
store.py
tesla_fleet.py
tesla_oauth_local.py
vehicles.py
vehicle_data.py

详细介绍

Tesla Fleet API

通过官方 Fleet API 控制 Tesla 车辆。

脚本概览

脚本用途
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 - 车辆命令

在 Tesla 上执行命令。如果只有一辆车,将自动选择该车辆。

用法
command.py [VEHICLE] <command> [options]
  • VEHICLE - 车辆名称或 VIN(如果只有一辆车则可选)
  • 无需指定车辆即可运行命令:command.py honk
  • 或指定车辆名称:command.py flash honk(车辆为“flash”,命令为“honk”)

空调控制
启动 / 停止空调
command.py climate start
command.py climate stop
command.py flash climate start          # specific vehicle
设置温度
command.py climate temps <driver_temp> [passenger_temp]
command.py climate temps 21             # both seats 21°C
command.py climate temps 22 20          # driver 22°C, passenger 20°C
空调保持模式
command.py climate keeper <mode>

模式:off、keep、dog、camp


座椅加热器
command.py seat-heater --level <level> [--position <position>]
command.py seat-heater -l <level> [-p <position>]

档位:

值名称
0关闭
1低
2中
3高

位置:

值名称
0driver、front_left、fl
1passenger、front_right、fr
2rear_left、rl
3rear_left_back
4rear_center、rc
5rear_right、rr
6rear_right_back
7third_left
8third_right

示例:

command.py seat-heater -l high                    # driver (default)
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                  # medium, rear center
command.py seat-heater -l off -p driver           # turn off

座椅通风
command.py seat-cooler --level <level> [--position <position>]
command.py seat-cooler -l <level> [-p <position>]

档位和位置与座椅加热器相同。

示例:

command.py seat-cooler -l medium -p driver
command.py seat-cooler -l high -p passenger

座椅自动空调
command.py seat-climate [--position <position>] <mode>
command.py seat-climate [-p <position>] <mode>

模式:auto、on、off

示例:

command.py seat-climate auto                      # driver auto
command.py seat-climate -p passenger auto
command.py seat-climate -p driver off             # disable auto

方向盘加热器
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 <days>] [--id <id>] [--one-time] [--disabled]
command.py precondition add -t <HH:MM> [-d <days>] [--id <id>]

日期选项:

值说明
all每天(默认)
weekdays周一至周五
weekends周六和周日
mon,tue,wed,...指定日期(以逗号分隔)

日期名称:sun、mon、tue、wed、thu、fri、sat(或完整名称)

示例:

command.py precondition add -t 08:00              # every day at 8am
command.py precondition add -t 08:00 -d weekdays  # Mon-Fri
command.py precondition add -t 07:30 -d mon,wed,fri
command.py precondition add -t 09:00 --one-time   # one-time only
command.py precondition add -t 08:30 --id 123     # modify existing schedule
command.py precondition add -t 08:00 --disabled   # create but 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 <percent>

百分比必须为 50-100。

示例:

command.py charge limit 80
command.py charge limit 90
command.py flash charge limit 70                  # specific vehicle

车门与安全
command.py lock                   # lock all doors
command.py unlock                 # unlock all doors
command.py honk                   # honk the horn
command.py flash                  # flash the lights
command.py wake                   # wake vehicle from sleep

指定车辆名称:

command.py flash wake             # wake vehicle named "flash"
command.py flash flash            # flash lights on vehicle "flash"

vehicle_data.py - 读取车辆数据

获取车辆数据,默认以易读格式输出。

用法
vehicle_data.py [VEHICLE] [flags] [--json]
  • VEHICLE - 车辆名称或 VIN(如果只有一辆车则可选)
  • 不加标志 = 所有数据
  • --json = 原始 JSON 输出
标志
标志长选项数据
-c--charge电池电量、充电上限、充电状态
-t--climate车内 / 车外温度、HVAC 状态
-d--drive挡位、速度、功率、朝向
-l--locationGPS 坐标
-s--state车锁、车门、车窗、里程表、软件
-g--guiGUI 设置(单位、24 小时制)
--config-data车辆配置(型号、颜色、车轮)
示例
# All data
vehicle_data.py
vehicle_data.py flash

# Specific data
vehicle_data.py -c                        # charge only
vehicle_data.py -c -t                     # charge + climate
vehicle_data.py flash -c -l               # charge + location

# Raw JSON
vehicle_data.py --json
vehicle_data.py -c --json
输出示例
🚗 My Tesla (online)
   VIN: 5YJ... (redacted)

⚡ Charge State
────────────────────────────────────────
  Battery:    [███████████████░░░░░] 78%
  Limit:      80%
  State:      Charging
  Power:      11 kW (16A × 234V × 3φ)
  Added:      37.2 kWh
  Remaining:  10m
  Range:      438 km (272 mi)
  Cable:      IEC

🌡️  Climate State
────────────────────────────────────────
  Inside:     11.9°C
  Outside:    6.0°C
  Set to:     20.5°C
  Climate:    Off

auth.py - 身份验证

管理 OAuth 令牌和配置。

用法
auth.py <command> [options]
命令
登录(OAuth 流程)
auth.py login

交互式操作:生成授权 URL,提示输入代码,并交换获取令牌。

交换授权码
auth.py exchange <code>

交换授权码以获取令牌(非交互式)。

刷新令牌
auth.py refresh

刷新访问令牌。注意:刷新令牌会轮换,新的令牌会自动保存。

注册域名
auth.py register --domain <domain>

向 Tesla 注册你的应用域名(签名命令所必需)。

注册后,注册你的虚拟密钥:

https://tesla.com/_ak/<domain>
显示配置
auth.py config

显示当前配置(机密信息已隐藏)。

设置配置
auth.py config set [options]

选项:

  • --client-id <id>
  • --client-secret <secret>
  • --redirect-uri <uri>
  • --audience <url>
  • --base-url <url>
  • --ca-cert <path>
  • --domain <domain>

示例:

# Initial setup
auth.py config set \
  --client-id "abc123" \
  --client-secret "secret" \
  --redirect-uri "http://localhost:18080/callback"

# Configure proxy
auth.py config set \
  --base-url "https://localhost:4443" \
  --ca-cert "/path/to/tls-cert.pem"

tesla_fleet.py - 列出车辆

以易读的格式列出车辆。

python3 scripts/tesla_fleet.py vehicles
python3 scripts/tesla_fleet.py vehicles --json
示例输出
🚗 Name:   My Tesla
🔖 VIN:    5YJ... (redacted)
🟢 Status: Online
👤 Access: Owner

配置 / 代理 / 文件布局

所有设置和配置信息均记录在 SETUP.md 中。


区域基础 URL

区域受众 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

故障排除

“vehicle unavailable: vehicle is offline or asleep”

先唤醒车辆:

command.py wake
“command not signed” / “vehicle rejected”

确保签名代理正在运行且已正确配置。请参阅 SETUP.md § 代理设置。

令牌已过期
auth.py refresh
多辆车

按名称或 VIN 指定车辆:

command.py flash climate start
command.py 5YJ... honk

完整命令参考

command.py
climate start|stop
climate temps <driver> [passenger]
climate keeper off|keep|dog|camp

seat-heater -l <level> [-p <position>]
seat-cooler -l <level> [-p <position>]
seat-climate [-p <position>] auto|on|off

steering-heater on|off

precondition add -t <HH:MM> [-d <days>] [--id <id>] [--one-time]
precondition remove --id <id>

charge start|stop
charge limit <percent>

lock
unlock
honk
flash
wake
vehicle_data.py
[VEHICLE] [-c] [-t] [-d] [-l] [-s] [-g] [--config-data] [--json]
auth.py
login
exchange <code>
refresh
register --domain <domain>
config
config set [--client-id] [--client-secret] [--redirect-uri] [--audience] [--base-url] [--ca-cert] [--domain]

评论

支持 Markdown