Skip to content

Commit

Permalink
Add get_time_remaining()
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Dec 23, 2023
1 parent 1116b9a commit f75855e
Show file tree
Hide file tree
Showing 3 changed files with 504 additions and 1 deletion.
4 changes: 4 additions & 0 deletions proxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ def do_GET(self):
pod["PW%d_POD_nom_full_pack_energy" % idx] = get_value(d, 'POD_nom_full_pack_energy')
idx = idx + 1
pod["backup_reserve_percent"] = pw.get_reserve()
d = pw.system_status()
pod["nominal_full_pack_energy"] = get_value(d,'nominal_full_pack_energy')
pod["nominal_energy_remaining"] = get_value(d,'nominal_energy_remaining')
pod["time_remaining_hours"] = pw.get_time_remaining()
message = json.dumps(pod)
elif self.path == '/version':
# Firmware Version
Expand Down
25 changes: 24 additions & 1 deletion pypowerwall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,4 +749,27 @@ def battery_blocks(self, jsonformat=False):
if jsonformat:
return json.dumps(result, indent=4, sort_keys=True)
else:
return result
return result

def get_time_remaining(self):
"""
Get the backup time remaining on the battery
Returns:
The time remaining in hours
"""
if self.cloudmode:
d = self.Tesla.get_time_remaining()
# {'response': {'time_remaining_hours': 7.909122698326978}}
if d is None:
return None
if 'response' in d and 'time_remaining_hours' in d['response']:
return d['response']['time_remaining_hours']

# Compute based on battery level and load
d = self.system_status()
if 'nominal_energy_remaining' in d:
return d['nominal_energy_remaining']/self.load()
# Default
return None

Loading

0 comments on commit f75855e

Please sign in to comment.