diff --git a/core/site_optimizer.go b/core/site_optimizer.go index e72398a92..be3b59ee1 100644 --- a/core/site_optimizer.go +++ b/core/site_optimizer.go @@ -551,10 +551,8 @@ func (site *Site) optimizerUpdate(battery []types.Measurement) error { return apiError(resp) } - if resp.JSON200.Status != optimizer.Optimal { - return errors.New(string(resp.JSON200.Status)) - } - + // publish before the status check so the optimizer page stays available + // for diagnosing non-optimal results site.publish("evopt", optimizerResult{ Updated: time.Now(), Req: req, @@ -562,6 +560,10 @@ func (site *Site) optimizerUpdate(battery []types.Measurement) error { Details: details, }) + if resp.JSON200.Status != optimizer.Optimal { + return errors.New(string(resp.JSON200.Status)) + } + slotHours := firstSlotDuration.Hours() gridImporting := len(resp.JSON200.GridImport) > 0 && resp.JSON200.GridImport[0] > 0 gridExporting := len(resp.JSON200.GridExport) > 0 && resp.JSON200.GridExport[0] > 0