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

Check sleep state before polling #18

Closed
steve28 opened this issue Feb 10, 2019 · 5 comments
Closed

Check sleep state before polling #18

steve28 opened this issue Feb 10, 2019 · 5 comments

Comments

@steve28
Copy link

steve28 commented Feb 10, 2019

When using the API to poll the car, if the car is asleep, it will be woken. When using teslajsonpy with things like HomeAssistant where it periodiclaly polls to make graphs of the battery level for example, it keeps waking the car to get the battery status. This results in large 'vampire drain' when the car is sitting idle (overnight, while owner is at work, etc.).

Could a flag be added to the API to tell it what to do if the car was asleep?

Something like:

Vehicle.data_request(name, wake_if_asleep=False)

Where wake_if_asleep is either True (should be default to preserve current behavior) or False. If set to False and the vehicle is asleep, the call return value should be something that could be easily checked.

How to check:
The data returned from /api/1/vehicles/{id} includes a state key which is either online or asleep - this call should NOT wake the vehicle and allows checking first.

@alandtse
Copy link
Collaborator

Thanks. This parameter may make sense. We're actually fixing a bug(#16) where it's not being woken up enough but that will only increase the vampire drain you're discussing here so there's a balance we need to strike.

As a note, I also had the phantom drain problem and put in a fix to create an update switch in HA (#8) that may provide some relief. I couldn't push it in because the pypi package wasn't updated, but I recently got contributor rights so we can probably push it in after we resolve #16.

@steve28
Copy link
Author

steve28 commented Feb 11, 2019

Adding the switch is better than nothing, but it still requires the user to manually turn if off so it won't wake.

The proper solution is to check the state field of /api/1/vehicles/{id} for the value of online (awake) or asleep and if it's sleeping don't send the /api/1/vehicles/{id}/data request (unless the flag is set that the user intended the vehicle to be woken).

@alandtse
Copy link
Collaborator

Agree with your point. However, as this is an API fix, someone has to change all the calling functions to pass the flag which is slightly harder than a user manually flipping it in HA.

I've created the flag and testing it now.

@zabuldon
Copy link
Owner

@steve28 @alandtse

How to check:
The data returned from /api/1/vehicles/{id} includes a state key which is either online or asleep - this call should NOT wake the vehicle and allows checking first.

Please keep in mined that in some cases it returns empty field.

@alandtse
Copy link
Collaborator

I haven't seen that but the current code treats the empty state as offline. We can see if that induces any unexpected bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants