Migrate to calendar_history API and fix data handling#102
Closed
gbassaragh wants to merge 1 commit intoMikeBishop:masterfrom
Closed
Migrate to calendar_history API and fix data handling#102gbassaragh wants to merge 1 commit intoMikeBishop:masterfrom
gbassaragh wants to merge 1 commit intoMikeBishop:masterfrom
Conversation
Tesla deprecated the /history endpoint in favor of /calendar_history. This commit migrates all API calls and fixes the resulting data handling issues. ## API Migration (node_helper.js) - Add `getCalendarHistoryDates()` helper for consistent date parameter formatting - Migrate all history endpoints to use calendar_history: - energy: /history?period=day&kind=energy → /calendar_history?kind=energy&period=day - power: /history?period=day&kind=power → /calendar_history?kind=power&period=day - backup: /history?kind=backup → /calendar_history?kind=backup - self_consumption: /history?kind=self_consumption&period=day → /calendar_history?kind=self_consumption&period=day - Add required start_date, end_date, and time_zone parameters ## Data Handling Fixes (MMM-Powerwall.js) ### SelfConsumption Handler The calendar_history API may return only today's data (1 entry) instead of yesterday + today (2 entries). Updated the handler to detect single-entry responses and gracefully default yesterday values to zero. ### generateDaystart Function The calendar_history energy endpoint returns granular time-series data (5-minute intervals, ~170+ entries per day) instead of daily aggregates. Rewrote the function to: - Aggregate all time-series entries to calculate today's cumulative totals - Handle variable response lengths gracefully - Set yesterday baseline to zero (API only provides today's granular data) This fixes the Energy To/From bar chart which was broken due to expecting only 2 daily aggregate entries. ## Testing - Self-powered ring: ✓ Displays correct solar/battery/grid percentages - Power To/From histogram: ✓ Shows real-time power flow - Energy To/From bar chart: ✓ Shows cumulative daily energy usage - Current Usage display: ✓ Shows live consumption data 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Owner
|
Largely duplicate of #100, other than staying on the owner-api endpoint. If you've tested that the same API works on the old API, I can add the option to retain it. |
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
Tesla deprecated the
/historyendpoint in favor of/calendar_history. This PR migrates all API calls and fixes the resulting data handling issues that were causing broken charts.Changes
API Migration (node_helper.js):
getCalendarHistoryDates()helper for consistent date parameter formattingcalendar_historywith requiredstart_date,end_date, andtime_zoneparametersData Handling Fixes (MMM-Powerwall.js):
Problem
The old
/historyendpoint returned daily aggregate values, but the new/calendar_historyendpoint returns:This caused:
payload.selfConsumption[1]but array only had 1 element)Testing
🤖 Generated with Claude Code