Skip to content

fix(teslemetry): assert optimization_strategy=economics on every tariff push - #4603

Merged
springfall2008 merged 1 commit into
mainfrom
fix/teslemetry-optimization-strategy-4600
Aug 19, 2026
Merged

fix(teslemetry): assert optimization_strategy=economics on every tariff push#4603
springfall2008 merged 1 commit into
mainfrom
fix/teslemetry-optimization-strategy-4600

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Summary

  • set_tariff() in teslemetry.py never sent the Fleet API's tou_settings.optimization_strategy, so Time-Based Control silently stayed in Balanced mode - which only discharges to offset house load and never exports stored energy for price, no matter how attractive the pushed sell rate is. Every device command still succeeded and Predbat reported "Exporting", but the battery exported nothing.
  • economics ("Cost Saving") is the strategy that actually exports for price; it's now asserted on every tariff push and included in the dedupe signature so a future change to the strategy forces a re-push.
  • Extended the standalone CLI test harness (teslemetry.py --key ...) with OAuth-mode support (--auth-method, --token-expires-at, --token-hash, --user-id, --supabase-url, --supabase-key, mirroring fox.py) and a new --apps <path> flag to load Teslemetry config straight from a Predbat apps.yaml instead of pasting every value (including a long OAuth token) onto the command line.

Testing

  • Added test_teslemetry_set_tariff_asserts_optimization_strategy_economics (RED confirmed the defect, GREEN confirms the fix).
  • Added CLI-harness wiring tests for the new OAuth args, the supabase env-var export, and the --apps loader.
  • ./run_all --quick and ./run_pre_commit both pass.
  • Confirmed live against a real Powerwall 2 site: fetched the currently-live tariff via site_info, re-pushed it unchanged plus optimization_strategy=economics through the actual fixed code path, and the Fleet API accepted it (Code: 201 "Updated") touching only the tariff endpoint - no other device setting was written.

Fixes #4600

Test plan

  • ./run_all --quick
  • ./run_pre_commit
  • Live confirmation against a real Powerwall (see above)

🤖 Generated with Claude Code

…ff push

Powerwall's Time-Based Control silently stays in Balanced mode - which only
offsets house load and never exports stored energy for price - because
set_tariff() never sent the Fleet API's optimization_strategy dial. Every
device command succeeded and Predbat reported "Exporting", but no energy
ever left the battery. "economics" is the strategy that actually exports
for price; it's now included in the dedupe signature so the standalone CLI
harness gained OAuth-mode support (auth_method/token_expires_at/token_hash/
user_id, mirroring fox.py) plus an --apps flag to load config straight from
a Predbat apps.yaml, which is what surfaced and let us confirm the fix live.

Fixes #4600

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 19, 2026 19:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Teslemetry tariff pushes so Powerwall Time-Based Control is explicitly driven into a price-exporting strategy by asserting tou_settings.optimization_strategy=economics on every tariff push, preventing silent drift to Balanced mode where export-for-price never occurs.

Changes:

  • Include optimization_strategy=economics in every time_of_use_settings tariff push and in the dedupe signature so strategy changes force a re-push.
  • Extend the standalone Teslemetry CLI harness with OAuth-mode wiring and --apps loading from a Predbat apps.yaml.
  • Add targeted tests covering the new optimization strategy assertion and the CLI-harness wiring (OAuth args, Supabase env export, apps.yaml loader).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/predbat/teslemetry.py Asserts optimization_strategy during tariff pushes; extends CLI harness for OAuth args + --apps config loading.
apps/predbat/tests/test_teslemetry.py Adds regression test for optimization_strategy=economics and tests for new CLI-harness wiring / apps.yaml extraction.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


args = parser.parse_args()
ok = asyncio.run(test_teslemetry_api(args.key, args.site_id, base_url=args.base_url, control=args.control))
file_args = load_teslemetry_args_from_apps_yaml(args.apps) if args.apps else {}
@springfall2008
springfall2008 merged commit d29c13d into main Aug 19, 2026
3 checks passed
@springfall2008
springfall2008 deleted the fix/teslemetry-optimization-strategy-4600 branch August 19, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Teslemetry: Powerwall never exports — tariff pushed without optimization_strategy, so TBC stays in Balanced

2 participants