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

OPERATION no longer listed under BATTERY_DATA #410

Closed
jaymunro opened this issue Jun 14, 2023 · 18 comments
Closed

OPERATION no longer listed under BATTERY_DATA #410

jaymunro opened this issue Jun 14, 2023 · 18 comments

Comments

@jaymunro
Copy link

In HA the operation mode is no longer populated on startup and is left empty. See comment in #618 of alandtse/tesla#618 (comment)

It seems this can be resolved by retrieving the data from the SITE_CONFIG endpoint under the default_real_mode property.

{
    "response":{
        "id":"<redacted>",
        "site_name":"My Home",
        "backup_reserve_percent":15,
        "default_real_mode":"autonomous",
        "installation_date":"2022-07-01T15:15:19+12:00",
        "user_settings":{
            "storm_mode_enabled":true,
            "powerwall_onboarding_settings_set":true,
            "powerwall_tesla_electric_interested_in":false,
            "sync_grid_alert_enabled":true,
            "breaker_alert_enabled":false},
        "components":{
            "solar":true,
            "solar_type":"pv_panel",
...       
        }}}

Details of my API responses are at #342 (comment)

energy.py, line 175-178:

    @property
    def operation_mode(self) -> str:
        """Return operation mode."""
        return self._battery_data.get("operation")

Change to:

    @property
    def operation_mode(self) -> str:
        """Return operation mode."""
        return self._site_config.get("default_real_mode")
@alandtse
Copy link
Collaborator

PRs are welcome.

@jaymunro
Copy link
Author

Thanks Alan. I’m new to this and I’d often wondered how to create a PR.

I’ve forked and edited, but have no idea how to test this with tesla_custom using my new fork or by just manually editing the code in HA (teslajsonpy code does not seem to exist in the custom_components folder). Any pointers would be most welcome.

@alandtse
Copy link
Collaborator

If you install teslajsonpy locally into custom_components it will take precedence over the system copy. You can also modify it in the system location if you can figure out where your system is hosting the library.

@jaymunro
Copy link
Author

If you install teslajsonpy locally into custom_components it will take precedence over the system copy. You can also modify it in the system location if you can figure out where your system is hosting the library.

Thanks for the pointer. I've downloaded the teslajsonpy source into the custom_components directory and updated code there, but it does not seem to be using the code at that location. I'm probably missing something basic.

This is the location I added the source code for confirmation:
Screenshot 2023-06-15 at 11 58 20 PM

@purcell-lab
Copy link

This PR has become more urgent as the BATTERY endpoints have stopped functioning but the SITE_CONFIG endpoint is still OK.

$ python3 ./cli.py -e [email protected] -z BATTERY_DATA
Traceback (most recent call last):
  File "/home/mark/./cli.py", line 221, in <module>
    main()
  File "/home/mark/./cli.py", line 122, in main
    print(product.api(command, **command_data))
  File "/usr/local/lib/python3.9/dist-packages/teslapy/__init__.py", line 726, in api
    return self.tesla.api(name, pathvars, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/teslapy/__init__.py", line 363, in api
    return self.request(endpoint['TYPE'], uri, serialize,
  File "/usr/local/lib/python3.9/dist-packages/teslapy/__init__.py", line 155, in request
    response.raise_for_status()  # Raise HTTPError, if one occurred
  File "/usr/lib/python3/dist-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 410 Client Error: https://powergate.prd.sn.tesla.services:443/api/powerwalls/1152100-14-J--CN321293G4J50D/fullstatus => Gone for url: https://owner-api.teslamotors.com/api/1/powerwalls/STE20220321-00093

@jaymunro
Copy link
Author

jaymunro commented Oct 6, 2023

If someone can help me get up to speed with getting tesla_custom to use my local version of teslajsonpy then I may be able to test and advance this PR.

@gkwok1
Copy link
Contributor

gkwok1 commented Oct 7, 2023

If someone can help me get up to speed with getting tesla_custom to use my local version of teslajsonpy then I may be able to test and advance this PR.

You can use the local version by putting teslajsonpy folder under /config instead of /config/custom_components.

@Jonesnetwork
Copy link

Any chance you could share the Teslajson file? Happy to have a play to try and get it working?

@jaymunro
Copy link
Author

jaymunro commented Oct 7, 2023

If someone can help me get up to speed with getting tesla_custom to use my local version of teslajsonpy then I may be able to test and advance this PR.

You can use the local version by putting teslajsonpy folder under /config instead of /config/custom_components.

Will try this. Thanks.

@jaymunro
Copy link
Author

jaymunro commented Oct 7, 2023

My branch is here for those that would like to help
https://github.com/jaymunro/teslajsonpy

@gkwok1
Copy link
Contributor

gkwok1 commented Oct 7, 2023

My branch is here for those that would like to help https://github.com/jaymunro/teslajsonpy

The latest is not working for me but I found this which has the latest API and response. It's a little too much for me to handle.

https://tesla-api.timdorr.com/energy-products/energy

@jaymunro
Copy link
Author

jaymunro commented Oct 7, 2023

My changes in that repo were back in June and in response to a different api change, much more minor just involving one number variable self._battery_data.get("operation") which was replaced by self._site_config.get("default_real_mode").

@gkwok1 if you give me access to your repo, I’ll add this change (and the associated logging code change as _battery_data log is no longer working).

@JasonRS1969
Copy link

@gkwok1 appears to have fixed the issue.

alandtse/tesla#724 (comment)

@gkwok1
Copy link
Contributor

gkwok1 commented Oct 7, 2023

My changes in that repo were back in June and in response to a different api change, much more minor just involving one number variable self._battery_data.get("operation") which was replaced by self._site_config.get("default_real_mode").

@gkwok1 if you give me access to your repo, I’ll add this change (and the associated logging code change as _battery_data log is no longer working).

I have already included your change in my PR.

#428

@jaymunro
Copy link
Author

jaymunro commented Oct 7, 2023

Yes, reviewing it now…

@purcell-lab
Copy link

My changes in that repo were back in June and in response to a different api change, much more minor just involving one number variable self._battery_data.get("operation") which was replaced by self._site_config.get("default_real_mode").

Thanks @jaymunro , this Issue and your PR were the early indicators that the upstream API was changing, unfortunately the implications were not fully understood and once the upstream API was finally changed we had this mad scramble for 24 hours to get back to a working condition. Thanks @gkwok1 for turning something around very quickly which is now working and can be merged back into the HA eco system.

The joy of working with an undocumented API :-)

@jaymunro
Copy link
Author

jaymunro commented Oct 7, 2023

Yes, a pity I didn’t have the knowledge to put the teslajsonpy repo in the right place for testing.
Still, scrambles like this are good for keeping the community tight. 😜

@jaymunro
Copy link
Author

jaymunro commented Oct 7, 2023

Closing as resolved by alandtse/tesla#724

@jaymunro jaymunro closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants