Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for reading/writing powerwall Storm Mode #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions energysite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down