Tesla Smart Charge Optimizer
Schedule Tesla charging to reach target battery % by a specific time. Runs daily via cron to check a schedule file and only charges on configured dates.
Security & Dependencies
Required:
- - Environment variable:
TESLA_EMAIL (your Tesla account email) - Skill dependency:
tesla skill must be installed and properly configured with Tesla API credentials
Security improvements (v1.1.0+):
- - ✅ No shell injection risk: Uses argument lists instead of shell=True
- ✅ Email validation: TESLA_EMAIL is validated before use
- ✅ Input validation: Charge limits are validated (0-100% range)
- ✅ Secure env passing: Credentials passed via environment variables, not string interpolation
- ✅ Explicit dependencies: Metadata declares required env vars and skill dependencies
Quick Start
1. Set Up Schedule
Copy the example schedule file:
CODEBLOCK0
Edit memory/tesla-charge-schedule.json with your planned charge dates:
CODEBLOCK1
Cron Setup (Recommended)
Option 1: Daily Check at Midnight (Simple)
CODEBLOCK2
Option 2: Daily Check + Session Management (Recommended)
For better charge limit management, run both:
At midnight (initialize daily charge):
CODEBLOCK3
Every 30 minutes during active hours (manage session limits):
CODEBLOCK4
The second job ensures charge limits are properly updated throughout the day:
- - ✅ During session: Maintains 100% (or user-specified) limit
- ✅ After session: Applies 80% (or user-specified) limit for battery health
How It Works
Each day at midnight (or whenever cron runs):
- 1. Script checks INLINECODE3
- If today's date is in the charges array → executes charge plan
- Fetches current battery level
- Calculates optimal start time
-
Sets charge limit to session limit (default 100%)
- Displays charge details
- Shows
next scheduled charge date
- 3. If today is NOT scheduled → applies post-charge limit
-
Sets charge limit to default 80% (or user-specified)
- Still displays
next scheduled charge date
Session Management:
- - During charge session: Charge limit =
charge_limit_percent (default 100%) - After charge session expires: Charge limit =
post_charge_limit_percent (default 80%)
Result: One cron job that handles both charging and limit management — no need to create new jobs for each date!
Schedule File Format
CODEBLOCK5
Fields:
- -
date: YYYY-MM-DD format (when to charge) - INLINECODE7 : Target battery % (default: 100)
- INLINECODE8 : HH:MM when charging should complete (default: 08:00)
- INLINECODE9 : Charge limit during session (default: 100%, optional)
- INLINECODE10 : Charge limit after session ends (default: 80%, optional)
Environment Setup
Tesla Email
CODEBLOCK6
Optional: Customize Charger Power
Default: 2.99 kW (home charger, ~13A @ 230V)
Adjust in cron task or when calling manually:
CODEBLOCK7
Commands
Check Schedule for Today
CODEBLOCK8
Output:
- - ✅ If scheduled: Shows charge plan + charge limits + next date
- ❌ If not scheduled: Shows next scheduled date + applies default 80% limit
Manage Active Session (Run During or After Charge)
CODEBLOCK9
This command:
- - Checks if today's charge session is active
- During session: Sets charge limit to session limit (default 100%)
- After session: Sets charge limit to post-charge limit (default 80%)
- No session: Applies default 80% limit
Tip: Run this hourly or every 30 minutes during active charging days for real-time limit management.
Show All Scheduled Charges
CODEBLOCK10
Show Last Charge Plan
CODEBLOCK11
Examples
Daily 100% Charge (Mon-Fri)
CODEBLOCK12
Smart 80% for Battery Health (Every 3 Days)
CODEBLOCK13
Variable Targets
CODEBLOCK14
Charge Time Estimation
Charge time is calculated as:
CODEBLOCK15
Where:
- -
battery_capacity: Vehicle battery size (kWh, default: 75) - INLINECODE12 : Your charger's power (kW, default: 2.99)
- INLINECODE13 : ~0.92 (typical AC charging)
- INLINECODE14 : Buffer before target (default: 5 min)
Example: 75 kWh battery at 50%, charging to 100% by 08:00 with 2.99 kW:
- - Energy needed: (75 × 50% / 100) / 0.92 = 40.8 kWh
- Charge time: 40.8 / 2.99 ≈ 13.6 hours
- Start time: 08:00 - 13.6h - 5min ≈ 18:25 previous day
Workflow Tips
Add new charges: Edit memory/tesla-charge-schedule.json — cron picks up changes on next run
Plan ahead: Add weeks of charges in advance, script handles date logic
One cron job: No need to create separate jobs — one daily check does it all
See what's next: Each run displays the next scheduled charge date
Parameters
When calling manually with --target-time:
CODEBLOCK16
For schedule-based operation, use --check-schedule (reads from JSON file).
References
- - CRONSETUP.md - Full cron integration guide
- APIREFERENCE.md - Advanced parameters and formulas
- tesla-charge-schedule-example.json - Schedule file template
Tesla 智能充电优化器
安排特斯拉充电,在特定时间前达到目标电池百分比。通过 cron 每日运行,检查计划文件,仅在配置的日期充电。
安全性与依赖项
必需项:
- - 环境变量:TESLA_EMAIL(您的特斯拉账户邮箱)
- 技能依赖项:必须安装 tesla 技能并正确配置特斯拉 API 凭据
安全性改进(v1.1.0+):
- - ✅ 无 shell 注入风险:使用参数列表而非 shell=True
- ✅ 邮箱验证:使用前验证 TESLA_EMAIL
- ✅ 输入验证:验证充电限制(0-100% 范围)
- ✅ 安全的环境变量传递:凭据通过环境变量传递,而非字符串插值
- ✅ 显式依赖项:元数据声明所需的环境变量和技能依赖项
快速开始
1. 设置计划
复制示例计划文件:
bash
cp skills/tesla-smart-charge/references/tesla-charge-schedule-example.json \
memory/tesla-charge-schedule.json
编辑 memory/tesla-charge-schedule.json,填入您的计划充电日期:
json
{
charges: [
{
date: 2026-02-01,
target_battery: 100,
target_time: 08:00
},
{
date: 2026-02-03,
target_battery: 80,
target_time: 07:00
}
]
}
Cron 设置(推荐)
选项 1:每日午夜检查(简单)
bash
clawdbot cron add \
--name 特斯拉每日充电检查 \
--schedule 0 0 * \
--task TESLA_EMAIL=your@email.com python3 /path/to/skills/tesla-smart-charge/scripts/tesla-smart-charge.py --check-schedule
选项 2:每日检查 + 会话管理(推荐)
为更好地管理充电限制,同时运行以下两项:
在午夜(初始化每日充电):
bash
clawdbot cron add \
--name 特斯拉每日充电检查 \
--schedule 0 0 * \
--task TESLA_EMAIL=your@email.com python3 /path/to/skills/tesla-smart-charge/scripts/tesla-smart-charge.py --check-schedule
在活跃时段每 30 分钟运行一次(管理会话限制):
bash
clawdbot cron add \
--name 特斯拉会话管理 \
--schedule /30 8-23 \
--task TESLA_EMAIL=your@email.com python3 /path/to/skills/tesla-smart-charge/scripts/tesla-smart-charge.py --manage-session
第二个任务确保全天正确更新充电限制:
- - ✅ 会话期间:维持 100%(或用户指定)限制
- ✅ 会话结束后:应用 80%(或用户指定)限制以保护电池健康
工作原理
每天午夜(或 cron 运行时):
- 1. 脚本检查 memory/tesla-charge-schedule.json
- 如果今天的日期在充电数组中 → 执行充电计划
- 获取当前电池电量
- 计算最佳开始时间
-
将充电限制设置为会话限制(默认 100%)
- 显示充电详情
- 显示
下一个计划充电日期
- 3. 如果今天未计划 → 应用充电后限制
-
将充电限制设置为默认 80%(或用户指定)
- 仍显示
下一个计划充电日期
会话管理:
- - 充电会话期间: 充电限制 = chargelimitpercent(默认 100%)
- 充电会话结束后: 充电限制 = postchargelimit_percent(默认 80%)
结果: 一个 cron 任务处理充电和限制管理 — 无需为每个日期创建新任务!
计划文件格式
json
{
charges: [
{
date: 2026-02-01,
target_battery: 100,
target_time: 08:00,
chargelimitpercent: 100,
postchargelimit_percent: 80
},
{
date: 2026-02-03,
target_battery: 80,
target_time: 07:00,
chargelimitpercent: 100,
postchargelimit_percent: 80
}
]
}
字段说明:
- - date:YYYY-MM-DD 格式(充电日期)
- targetbattery:目标电池百分比(默认:100)
- targettime:充电完成时间 HH:MM(默认:08:00)
- chargelimitpercent:会话期间的充电限制(默认:100%,可选)
- postchargelimit_percent:会话结束后的充电限制(默认:80%,可选)
环境设置
特斯拉邮箱
bash
export TESLA_EMAIL=your@email.com
可选:自定义充电器功率
默认值:2.99 kW(家用充电器,~13A @ 230V)
在 cron 任务或手动调用时调整:
bash
--charger-power 3.7 # 16A @ 230V
--charger-power 7.4 # 32A @ 230V(双相)
命令
检查今日计划
bash
TESLA_EMAIL=your@email.com python3 scripts/tesla-smart-charge.py --check-schedule
输出:
- - ✅ 如果已计划:显示充电计划 + 充电限制 + 下一个日期
- ❌ 如果未计划:显示下一个计划日期 + 应用默认 80% 限制
管理活跃会话(充电期间或之后运行)
bash
TESLA_EMAIL=your@email.com python3 scripts/tesla-smart-charge.py --manage-session
此命令:
- - 检查今日充电会话是否活跃
- 会话期间: 将充电限制设置为会话限制(默认 100%)
- 会话结束后: 将充电限制设置为充电后限制(默认 80%)
- 无会话: 应用默认 80% 限制
提示: 在活跃充电日每小时或每 30 分钟运行一次,实现实时限制管理。
显示所有计划充电
bash
python3 scripts/tesla-smart-charge.py --show-schedule
显示上次充电计划
bash
python3 scripts/tesla-smart-charge.py --show-plan
示例
每日 100% 充电(周一至周五)
json
{
charges: [
{date: 2026-02-02, targetbattery: 100, targettime: 08:00},
{date: 2026-02-03, targetbattery: 100, targettime: 08:00},
{date: 2026-02-04, targetbattery: 100, targettime: 08:00},
{date: 2026-02-05, targetbattery: 100, targettime: 08:00},
{date: 2026-02-06, targetbattery: 100, targettime: 08:00}
]
}
智能 80% 保护电池健康(每 3 天)
json
{
charges: [
{date: 2026-02-01, targetbattery: 80, targettime: 07:00},
{date: 2026-02-04, targetbattery: 80, targettime: 07:00},
{date: 2026-02-07, targetbattery: 80, targettime: 07:00}
]
}
可变目标
json
{
charges: [
{date: 2026-02-01, targetbattery: 100, targettime: 08:00},
{date: 2026-02-02, targetbattery: 80, targettime: 07:00},
{date: 2026-02-03, targetbattery: 60, targettime: 06:00}
]
}
充电时间估算
充电时间计算如下:
所需电量_kwh = (电池容量 × (目标 - 当前) / 100) / 充电效率
充电时间小时 = 所需电量kwh / 充电器功率_kw
开始时间 = 目标时间 - 充电时间小时 - 缓冲时间分钟
其中: