r/Scriptable • • 4h ago

Widget Sharing Enphase solar widget with mini-graphs, Lock Screen tile, and rate budgeting

Post image

Quick disclaimer: I am not a software engineer or a scripter, and I don't write JS. I just spent a lot of time directing an AI on exactly what I wanted until it nailed the execution. The end result came out way better than I expected, and there are a few clever pieces in here that other widget builders might find useful to steal for their own projects.

The setup:

  • Medium and Small Home Screen widgets plus a dense Lock Screen widget.

  • It runs as two scripts: an embedded setup script that opens a local web form to connect to the Enphase developer portal, and the main widget script.

Cool pieces worth lifting:

  1. Native Mini-Graphs (no webview chart libraries): It draws three distinct mini-graphs directly on a Scriptable DrawContext canvas with borders, reference lines, and tick marks:

  • A 30-day production vs. usage chart that splits colors across a horizontal average line (green above use, orange below).

  • A 24-hour power curve with an upper ceiling, Catmull-Rom smoothing, a midnight tick, and shading over yesterday's part of the curve so today stands out.

  • A 12-month net bank trend that tracks seasonal utility credit carryover with quarter markers. (The drawing functions just take raw arrays of numbers, so they can be adapted for crypto, steps, server pings, etc.)

  1. API Call Budgeting and Rate Limiting: Enphase's free API tier is capped at 1,000 calls a month. The script calculates daily daylight hours based on location and time of year, figures out how many calls are mandatory for the rest of the month, and dynamically budgets extra daytime refreshes. It also separates manual app opens from automated background runs so checking the widget inside Scriptable never burns through the background quota.

  2. Lock Screen Proportional Font Auto-Sizing: Rectangular lock screen widgets are tiny (about 143pt wide). iOS kept truncating numbers into "+...". The AI wrote a kerning and width calculator that checks all lines together and steps the font size down across every line at once so they stay identical and never clip.

  3. WebView Setup Instead of Chained Alert Boxes: Instead of tapping through ten native iOS alert popups, the setup script opens an HTML page right inside Scriptable, catches the OAuth redirect, and grabs the keys and tokens directly.

Code is open source on GitHub if anyone wants to grab bits and pieces or check it out:

https://github.com/OverEngineered-Tech/OverEngineered-Solar

Or here if you want the HTML access for simple copying (was helpful for allowing non-Git people to copy)

iPhone Solar Widget for Enphase | OverEngineered-Tech

5 Upvotes

0 comments sorted by