fix(teslemetry): assert optimization_strategy=economics on every tariff push - #4603
Merged
Merged
Conversation
…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>
Contributor
There was a problem hiding this comment.
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=economicsin everytime_of_use_settingstariff push and in the dedupe signature so strategy changes force a re-push. - Extend the standalone Teslemetry CLI harness with OAuth-mode wiring and
--appsloading from a Predbatapps.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 {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
set_tariff()inteslemetry.pynever sent the Fleet API'stou_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.teslemetry.py --key ...) with OAuth-mode support (--auth-method,--token-expires-at,--token-hash,--user-id,--supabase-url,--supabase-key, mirroringfox.py) and a new--apps <path>flag to load Teslemetry config straight from a Predbatapps.yamlinstead of pasting every value (including a long OAuth token) onto the command line.Testing
test_teslemetry_set_tariff_asserts_optimization_strategy_economics(RED confirmed the defect, GREEN confirms the fix).--appsloader../run_all --quickand./run_pre_commitboth pass.site_info, re-pushed it unchanged plusoptimization_strategy=economicsthrough 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🤖 Generated with Claude Code