Hi Brady,
I see that the revenue computation for the battery section is different than expected. I have the following points and potential issues to consider:
- Ensure that 'battery_energy_kWh', 'purchase_from_grid_kWh' and 'home_energy_use_kWh' are initialized correctly before the loop. For 'battery_energy_kWh', its first element should represent the initial state of charge of the battery. 'purchase_from_grid_kWh' should be initialized as a zeros array of the same length as 'timesteps' to ensure you can index into it without errors.
- Ensure that when the battery discharges (providing energy to the home), this energy is not mistakenly counted as needing to be purchased from the grid. Ensure that purchase_from_grid_kWh(i) only accounts for the deficit not covered by the battery.
- Make sure you're handling edge cases correctly, such as:
- The battery starting partially or fully charged.
- Days with exactly enough energy produced to meet consumption (no excess, no deficit).
- The battery being exactly full or empty at the start or end of a timestep
In case the above steps don't resolve your issue, Feel free to share the entire code and datasheet.