Comments (10)
Yep, I think that makes sense. I should be able to get this done pretty quickly, assuming I didn't mess anything up with the other PR.
I considered whether or not it would be better to return (-1, 0, 1) to be an easier check (e.g. if grid_status() > 0 then it's up but that's likely over optimizing and sacrificing readability.
from pypowerwall.
I like this! Thanks @wcwong .
def grid_status(self, verbose=False)
Response (not verbose) - something like this:
- {"grid_status":"SystemGridConnected"} = "UP"
- {"grid_status":"SystemIslandedActive"} = "DOWN"
- {"grid_status":"SystemTransitionToGrid"} = "SYNCING"
Thoughts? I would welcome a PR or I'll get to it in a few days.
Thanks for the suggestion!
from pypowerwall.
Great idea. We could do both...
def grid_status(self, verbose=False, numerical=False):
If numerical is True, respond with -1 for down, 0 for syncing, and 1 for up?
from pypowerwall.
verbose
and numerical
have the potential to conflict (i.e. the case where both values are True
).
What do you think about the following?
def grid_status(self, type="string"):
"""
Get the status of the grid
Args:
type == "string" (default) returns: "UP", "DOWN", "SYNCING"
type == "JSON" return raw JSON
type == "numeric" return -1 (Syncing), 0 (DOWN), 1 (UP)
"""
from pypowerwall.
Take a look at the PR above implemented with the type argument. Let me know if you'd prefer the implementation to be the boolean parameters.
from pypowerwall.
Thanks @wcwong ! I love the approach. Make sure you add your cmu.edu email address to your github profile so you get contributor credit. 👍
from pypowerwall.
@wcwong I made some slight modifications to grid_status()
- make sure you sync these and please provide feedback if I missed anything. My changes were based on:
- simplify - remove the conditions and solve with a map which makes it easier to adjust if Tesla alters API/payload
- exceptions - limiting exception raising to API use error rather than Powerwall response - payload errors are returned via logging and returning None when not as expected (provides some protection to API user)
- parameters - keeping all parameters consistent case (lowercae)
def grid_status(self, type="string"):
"""
Get the status of the grid
Args:
type == "string" (default) returns: "UP", "DOWN", "SYNCING"
type == "json" return raw JSON
type == "numeric" return -1 (Syncing), 0 (DOWN), 1 (UP)
"""
if type not in ['json', 'string', 'numeric']:
raise ValueError("Invalid value for parameter 'type': " + str(type))
payload = self.poll('/api/system_status/grid_status', jsonformat=True)
if type == "json":
return json.dumps(payload, indent=4, sort_keys=True)
map = {'SystemGridConnected': {'string': 'UP', 'numeric': 1},
'SystemIslandedActive': {'string': 'DOWN', 'numeric': 0},
'SystemTransitionToGrid': {'string': 'SYNCING', 'numeric': -1}}
try:
grid_status = payload['grid_status']
return map[grid_status][type]
except:
# The payload from powerwall was not valid
log.debug("ERROR Invalid return value received from gateway: " + str(payload.grid_status))
return None
from pypowerwall.
Looks good to me. The use of map
is definitely more elegant.
from pypowerwall.
Is it possible to have some additional response values added to the map? I'd be happy submit a PR with these added if that is okay.
I have had a shell script running for about year, monitoring the grid_status every 10 seconds and sending alerts when it changes. Over this time, I have observed the below additional "valid" responses from my Powerwall:
- {"grid_status":"SystemTransitionToIsland"} = Transitioning to off-grid?
- {"grid_status":"SystemIslandedReady"} = Ready to go off-grid?
As these are not documented anywhere that I can find, the comment is my interpretation of the status and what I decided to send in an e-mail alert when this occurs.
At the moment, if these occur the pypowerwall grid_status function will raise an exception and return None, however they are valid responses.
I have had these happen only a couple of times in the past year. I believe you may receive these responses based on "timing" of the request, i.e. you just happened to request the grid_status from the Powerwall in the same millisecond that a power outage or off-grid request occurred.
I think I had these responses once when manually switching to off-grid from the Tesla app, and another time when the transition to off-grid was not quite seamless (power in my house went out for about 1 second when a blackout occurred).
@jasonacox - If it still makes sense to consider these responses as "SYNCING" (i.e. in this case, we are syncing to off-grid rather than on-grid), then the map could be updated as below?
map = {'SystemGridConnected': {'string': 'UP', 'numeric': 1},
'SystemIslandedActive': {'string': 'DOWN', 'numeric': 0},
'SystemTransitionToGrid': {'string': 'SYNCING', 'numeric': -1},
'SystemTransitionToIsland': {'string': 'SYNCING', 'numeric': -1},
'SystemIslandedReady': {'string': 'SYNCING', 'numeric': -1}}
What are your thoughts - I can submit a PR if you agree it still makes sense for these?
from pypowerwall.
Awesome find @mcbirse ! Yes, please submit a PR for this.
I agree with your SYNCING categorization. That meets the intent of grid_status()
describing the status of the grid vs the specific transition state. A user wanting the transition (SYNC) details would just sent grid_status(type="json")
.
from pypowerwall.
Related Issues (20)
- Alert Code feedback HOT 2
- PVAC_a030_fan_faulted HOT 2
- [Feature Request] Proxy - shortcuts to endpoints HOT 2
- Proxy connect to hostname vs IP HOT 6
- Tesla API Change - set-reserve.py and set-mode.py HOT 1
- New Tesla Pros software update does not work with pypowerwall HOT 8
- set-reserve ERROR gives Missing access token parameter. Auth token expired? HOT 3
- Ran upgrade.sh but it does not pull all new files HOT 2
- New PW firmware seems to break vitals - 23.44.0 HOT 17
- INFO: Alerts displayed when one Powerwall is defective HOT 1
- Critical Bug - 404 HTTP Status Code Handling
- python3 set-reserve.py --read error HOT 15
- Missing ? energy_sites/grid_import_export HOT 3
- Powerwall not reachable ever since January 26th HOT 1
- Set Reserve via Proxy API HOT 8
- pyPowerwall [0.8.3] Proxy Server [t53] testing HOT 28
- Change the path .auth & .site files are saved to HOT 2
- Slow charge speed from grid? HOT 2
- Cannot set reserve lower than 5% HOT 14
- Changing Battery Configuration State Via GET HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pypowerwall.