Hello, I’m Dakshil and I’m excited to introduce to you EnergyKit.
The electricity powering your home comes from different sources throughout the day. These can include renewable energy, like solar and wind, or fossil fuels, like coal and natural gas. We started this journey by launching Grid Forecast, a feature in the Home app. It allows people in the contiguous U.S. to see times of day when electricity from relatively cleaner sources is available on the grid.
We also made the Energy category within the Home app more personal and actionable by integrating people’s home electricity usage directly into the experience. EnergyKit drives these features, and we are excited to make this framework available to you for residential applications.
EnergyKit allows you to integrate insights about people’s local electricity grid into your app, helping them reduce or shift electricity usage and potentially save money. For example, if you are an electric vehicle manufacturer or a smart thermostat manufacturer, then EnergyKit can help you choose when to use electricity, prioritizing cleaner and potentially less expensive times. For instance, EnergyKit can help an electric vehicle manufacturer shift charging schedules to times when the grid is cleaner and potentially less expensive. In this talk, we will guide you through how to integrate EnergyKit into your app.
You will learn how to fetch electricity guidance, and adjust the charging schedules of electric vehicles managed by your app.
Plus, we’ll show you how to create an amazing user experience using EnergyKit insights.
Let’s get started with how to onboard people to EnergyKit.
Integrating EnergyKit into your app first requires people to opt in to a Clean Energy Charging experience, and make a selection for each location where they want to charge using cleaner electricity. In our sample app, we have a list of charging locations which represent where you charge an electric vehicle. We added a toggle to allow people to opt in to a Clean Energy Charging experience for their electric vehicle when charging at this location.
An EnergyVenue is a physical site where devices controlled by your app consume electricity from the grid, and where the owner has established a Home via the Home app or the EnergyKit onboarding flow. When they enable Clean Energy Charging, we retrieve a list of EnergyVenues near that location. If they select a venue, you should persist a mapping of the selected venue to the charging location until they opt out.
It is recommended that you store the unique identifier for the venue locally.
For each launch of your app, you should check that the selected venue exists. You can retrieve the selected venue by using the venue identifier that you saved earlier.
Now that you have identified that the person wants to use Clean Energy Charging and has selected an EnergyVenue, the next step is to generate a Clean Energy Charging Schedule. To generate a Clean Energy Charging schedule, you require a forecast that will help guide the schedule.
We call this forecast Electricity Guidance. This guidance is generated by using a combination of the Home location, Grid information about the location, such as carbon emissions, or whether renewables are generating, and Utility account information, if available.
There are two types of guidance actions available: Reduce and Shift. The “Reduce” guidance action is used for devices, such as smart thermostats, which are designed to reduce electricity usage.
The “Shift” guidance action is used for devices, such as electric vehicles, which can shift their electricity usage from one time to another time, but use the same amount of electricity. Let's take a look at an example.
The illustration shows electricity guidance for an EnergyVenue.
Guidance values are from 0 to 1 as represented by the Y axis, where lower values indicate periods where electricity is cleaner and potentially less expensive if rate plan information is available. In our example, a person has onboarded their utility account in the Home app, and is on a time of use rate plan where electricity is more expensive between the hours of 4 to 9pm.
The car is plugged in at around 6:30pm.
Your charging preferences might know that they unplugged their car at around 9am or have a charging deadline of 9am.
This gives us a charging window from 6:30pm to 9am the next day.
If guidance is not applied to the charging schedule, the car may begin charging immediately at 6:30pm, which is not the most favorable from a cleanliness and cost perspective.
Instead, we can select hours such that we can optimize the charging schedule to charge the vehicle during cleaner and potentially less expensive times.
Let’s take a look at how we can fetch this Electricity Guidance at a selected EnergyVenue.
We start by adding a method called streamGuidance to our EnergyVenueManager.
As we get updates, we will store it in the guidance variable.
We need to create a query to retrieve the guidance for our use case.
For an electric vehicle, the suggested action type would be to shift electricity usage.
We are now ready to retrieve guidance for the EnergyVenue.
ElectricityGuidance has a sharedService helper that should be used to retrieve guidance. You get back an AsyncSequence, which is updated as EnergyKit receives updated Guidance.
For more information, check out the video "Demystify concurrency in SwiftUI".
If you do not need to continuously listen for updates, you can break out of the loop after the first fetch. You can call streamGuidance from a Task. If your app requires updates while in the background, you should call this from a Background Task handler. If your app has an interactive charging widget, you can also utilize that widget to keep guidance up to date while the app is not running. For more information, check out the video, “Finish tasks in the background”.
You can now iterate over the guidance values in order to determine better times to charge.
EnergyKit Insights help provide electricity information in a format that is easy to present to people.
You can use the provided insights to inform people how much of the electricity used for charging their vehicle was during cleaner times, which can help reduce carbon emissions of their home electricity usage. The vehicle’s electricity usage is categorized by grid cleanliness and is reported in one of three categories: clean, reduce and avoid. You can also inform them about the electricity used during relatively less expensive times. The vehicle’s electricity usage is categorized by electricity rate plan when available and is reported in one of five categories: super off peak, off peak, partial peak, on peak, and critical peak.
Rate plan is also known as the rate tariff. The next question is: How do these insights work? Insights are influenced by a combination of factors. The algorithm you use to shift or reduce electricity based on the provided guidance determines whether the device under control consumes electricity during cleaner or less expensive times.
The state of the electricity grid where your device consumed electricity is determined by various factors such as electricity demand, renewable generators that are online, grid emissions, etc. If the person has onboarded their utility account in the Home app and they are on a time-of-use rate plan, the electricity usage can be attributed to the various time-of-use periods to get back the relative cost of using electricity.
And the most important piece, how and when your device consumed electricity. This is determined by the behavior of your device, interaction by people, and how your app applied guidance to the device.
For an EV manufacturer, this would be the charging session behavior for the vehicle. In order to generate insights about your vehicle's charging with respect to the cleanliness and relative cost of electricity used, it is required that your app submits feedback to EnergyKit. We call this feedback LoadEvents. You should periodically create events as your vehicle charges and changes occur to its state of charge during the charging session. When a charging session begins, create an event which represents the state of the vehicle at the start of the session. As the vehicle charges, create events periodically. We recommend one event every 15 minutes when the vehicle is charging at a steady rate. If a significant event such as pausing the session, a change in the charging schedule due to a new guidance set being applied, or a rapid change in power consumption occurs, create events for the same. At the end of a session, close the session with an event that represents the final state of the vehicle. For EnergyKit to generate insights for the created events, you need to submit them to EnergyKit. You may submit events as they occur or in batches periodically, or even in a batch at the end of the charging session.
We recommend batch submitting events for performance. Do not submit events between charging sessions. Let’s take a look at how to create and submit these events. For a charging session, the most important pieces of information are: the state of charge of the battery, the power being consumed at a given instance, the cumulative energy consumed since the start of a charging session. When the vehicle starts charging, we consider that to be the start of the session.
This event represents the initial state of the vehicle at the start of the charging session. The guidance state indicates whether the session started because the charging schedule was following the electricity guidance represented by the guidance token.
This token is unique to the phone that retrieved the guidance which was in effect, and is to be used to create events on that phone. As charging progresses, the session is marked as active. Once the charging session has ended, the session is closed with an end event. This event represents the final state of the vehicle at the end of the charging session. In our sample app, we create LoadEvents and cache them until we are ready to submit as a batch. These batched events are submitted to the EnergyVenue at which the vehicle was charging. The events you submit are stored in accordance to Apple’s privacy policies with storage in Core Data on device and backed up with end-to-end encryption to CloudKit. This data is also shared with all people that already share the HomeKit Home associated to the EnergyVenue for which the events are submitted. We now finally have all the information needed to generate insights. To retrieve insights, we first create a query where we specify that we are interested in insights for cleanliness and relative cost if available. In our sample app, we are interested in displaying a summary of electricity consumption for a previous day. Once we have created the query, we can fetch insights for our vehicle at a venue where it was charging previously. We get back an AsyncStream and since we are interested in the insight for a particular day, we can filter the stream as per our requirement. The retrieved insight can now be used to create a summary. Your app is now integrated with EnergyKit. In this talk, we went over the building blocks of interacting with EnergyKit.
For onboarding, we looked at how people would interact with your app to select an EnergyVenue. We then went over how to use the selected EnergyVenue and to fetch electricity guidance, and use that to generate a charging schedule.
After generating a charging schedule, as your vehicle charges, we went over the importance of submitting LoadEvents as feedback to EnergyKit to drive insight generation. Finally, we looked at how you can request insights based on the guidance retrieved and the feedback submitted by your app to build your user experience.
You can download the sample app that accompanies this talk and also access the documentation for EnergyKit at developer.apple.com.
At Apple, we are committed to protecting the environment and you can learn more about this at apple.com/2030 We are excited to see what amazing apps you build using EnergyKit.