$npx -y skills add dpearson2699/swift-ios-skills --skill energykitQuery grid electricity forecasts and submit load events using EnergyKit to help users optimize home electricity usage. Use when building smart home apps, EV charger controls, HVAC scheduling, or energy management dashboards that guide users to use power during cleaner or cheaper
| 1 | # EnergyKit |
| 2 | |
| 3 | Use grid cleanliness and cost guidance to shift or reduce managed-device load. |
| 4 | For managed-device insights, submit the device's real load events promptly. |
| 5 | |
| 6 | > **Beta-sensitive.** Core EnergyKit ships in iOS/iPadOS 26. The iOS/iPadOS 27 |
| 7 | > `ElectricalLoadDevice` and Home-facing LoadEvents experience are beta; re-check |
| 8 | > current Apple documentation before relying on those APIs. |
| 9 | |
| 10 | ## Contents |
| 11 | |
| 12 | - [Setup](#setup) |
| 13 | - [Core Concepts](#core-concepts) |
| 14 | - [Querying Electricity Guidance](#querying-electricity-guidance) |
| 15 | - [Working with Guidance Values](#working-with-guidance-values) |
| 16 | - [Energy Venues](#energy-venues) |
| 17 | - [Submitting Load Events](#submitting-load-events) |
| 18 | - [Electricity Insights](#electricity-insights) |
| 19 | - [Common Mistakes](#common-mistakes) |
| 20 | - [Review Checklist](#review-checklist) |
| 21 | - [References](#references) |
| 22 | |
| 23 | ## Setup |
| 24 | |
| 25 | ### Entitlements and Version Split |
| 26 | |
| 27 | | Runtime | Load-event device API | Capabilities | |
| 28 | |---|---|---| |
| 29 | | iOS/iPadOS 26.x | `deviceID:` compatibility initializer | EnergyKit | |
| 30 | | iOS/iPadOS 27+ beta | `ElectricalLoadDevice` with the `device:` initializer | EnergyKit; add EnergyKit LoadEvents for Home app integration | |
| 31 | |
| 32 | All EnergyKit use requires `com.apple.developer.energykit`; enable the EnergyKit |
| 33 | capability on the app target. On iOS/iPadOS 27+, add the EnergyKit LoadEvents |
| 34 | capability (`com.apple.developer.energykit.loadevents-experience`) only when the |
| 35 | app needs device names, energy context, activity logs, historical charts, or |
| 36 | trend notifications in the Home app. That Home experience requires both |
| 37 | capabilities. Missing permission can surface as `EnergyKitError.permissionDenied`. |
| 38 | |
| 39 | ### Import |
| 40 | |
| 41 | ```swift |
| 42 | import EnergyKit |
| 43 | ``` |
| 44 | |
| 45 | **Platform availability:** Core EnergyKit APIs are iOS/iPadOS 26.0+. Some |
| 46 | insight breakdown APIs, including grid cleanliness categories, are 26.1+ and |
| 47 | need availability guards. Apple currently documents electricity guidance only |
| 48 | for the contiguous United States; handle `EnergyKitError.unsupportedRegion`. |
| 49 | |
| 50 | ## Core Concepts |
| 51 | |
| 52 | EnergyKit provides two main capabilities: |
| 53 | |
| 54 | 1. **Electricity Guidance** -- time-weighted forecasts telling apps when |
| 55 | electricity is cleaner and, when rate data is available, less expensive |
| 56 | 2. **Load Events** -- telemetry from managed devices (EV chargers, HVAC) |
| 57 | submitted by the same device/app that requested guidance so EnergyKit can |
| 58 | generate insights |
| 59 | |
| 60 | ### Key Types |
| 61 | |
| 62 | | Type | Role | |
| 63 | |---|---| |
| 64 | | `ElectricityGuidance` | Forecast data with weighted time intervals | |
| 65 | | `ElectricityGuidance.Service` | Interface for obtaining guidance data | |
| 66 | | `ElectricityGuidance.Query` | Query specifying shift or reduce action | |
| 67 | | `ElectricityGuidance.Value` | A time interval with a rating (0.0-1.0) | |
| 68 | | `EnergyVenue` | A physical location (home) registered for energy management | |
| 69 | | `ElectricVehicleLoadEvent` | Load event for EV charger telemetry | |
| 70 | | `ElectricHVACLoadEvent` | Load event for HVAC system telemetry | |
| 71 | | `ElectricalLoadDevice` | iOS/iPadOS 27+ beta device identity for load events | |
| 72 | | `ElectricityInsightService` | Service for querying energy/runtime insights | |
| 73 | | `ElectricityInsightRecord` | Historical energy or runtime data, optionally broken down by tariff or 26.1+ grid cleanliness | |
| 74 | | `ElectricityInsightQuery` | Query for historical insight data | |
| 75 | |
| 76 | ### Suggested Actions |
| 77 | |
| 78 | | Action | Use Case | |
| 79 | |---|---| |
| 80 | | `.shift` | Devices that can move consumption to a different time (EV charging) | |
| 81 | | `.reduce` | Devices that can lower consumption without stopping (HVAC setback) | |
| 82 | |
| 83 | ## Querying Electricity Guidance |
| 84 | |
| 85 | Use `ElectricityGuidance.Service` to get a forecast stream for a venue. |
| 86 | |
| 87 | ```swift |
| 88 | import EnergyKit |
| 89 | |
| 90 | func observeGuidance(venueID: UUID) async throws { |
| 91 | let query = ElectricityGuidance.Query(suggestedAction: .shift) |
| 92 | let service = ElectricityGuidance.sharedService |
| 93 | |
| 94 | let guidanceStream = service.guidance(using: query, at: venueID) |
| 95 | |
| 96 | for try await guidance in guidanceStream { |
| 97 | print("Guidance token: \(guidance.guidanceToken)") |
| 98 | print("Interval: \(guidance.interval)") |
| 99 | print("Venue: \(guidance.energyVenueID)") |
| 100 | |
| 101 | // Check if rate plan information is available |
| 102 | if guidance.options.contains(.guidanceIncorporatesRatePlan) { |
| 103 | print("Rate plan data incorporated") |
| 104 | } |
| 105 | if guidance.options.contains(.locationHasRatePlan) { |
| 106 | print("Location has a rate plan") |
| 107 | } |
| 108 | |
| 109 | processGuidanceValues(guidance.values) |
| 110 | } |
| 111 | } |
| 112 | ``` |
| 113 | |
| 114 | ## Working with Guidance Values |
| 115 | |
| 116 | Each `ElectricityGuidance.Value` contains a time interval and a rating |
| 117 | from 0.0 to 1.0. Lower ratings indicate better times to use electricity. |
| 118 | |
| 119 | ```swift |
| 120 | func processGuidanceValues(_ values: [ElectricityGuid |