From d9092f29c0bf5ef76010e1398f6327fac1450f1b Mon Sep 17 00:00:00 2001 From: Mike Cardwell Date: Sun, 30 Jun 2024 22:20:56 +0100 Subject: [PATCH] Support for reading/writing powerwall Storm Mode --- energysite.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/energysite.go b/energysite.go index 9027a9d..6741d17 100644 --- a/energysite.go +++ b/energysite.go @@ -31,6 +31,7 @@ type EnergySiteStatus struct { BatteryType string `json:"battery_type"` BackupCapable bool `json:"backup_capable"` BatteryPower int64 `json:"battery_power"` + StormModeEnabled bool `json:"storm_mode_enabled"` c *Client } @@ -137,6 +138,25 @@ func (s *EnergySite) historyPath(period HistoryPeriod) string { return strings.Join([]string{s.basePath(), "history"}, "/") + fmt.Sprintf("?%s", v.Encode()) } +func (s *EnergySite) SetStormMode(enabled bool) error { + url := s.basePath() + "/storm_mode" + payload := fmt.Sprintf(`{"enabled":%t}`, enabled) + body, err := s.sendCommand(url, []byte(payload)) + if err != nil { + return err + } + response := SiteCommandResponse{} + if err := json.Unmarshal(body, &response); err != nil { + return err + } + + if response.Response.Code != 201 { + return fmt.Errorf("setStormMode failed: %s", response.Response.Message) + } + + return nil +} + func (s *EnergySite) SetBatteryReserve(percent uint64) error { url := s.basePath() + "/backup" payload := fmt.Sprintf(`{"backup_reserve_percent":%d}`, percent)