tesla
tesla copied to clipboard
Keep polling the car during "charging"
Currently, it may happen that the car finishes charging but goes to sleep before the integration can poll the vehicle again. It's then disconnected but the Charging status will stay until the car awakes again for whatever reason.
I propose to keep polling the car and ignore the disconnected state as long as the last charging status is "Charging".
Unfortunately it can't poll if it's asleep without waking it. But also it shouldn't go to sleep if it is still being polled regularly (as it would be while charging). What is your poll rate set to? If it's too long then it may have time to sleep between regular polls.
I recommend going with a shorter poll interval so that it won't go to sleep before ha updates from charging to idle, at which point it'll automatically slow the polling to let the car sleep (if you have it on the 'normal' profile).
Hi Carleeno
That's actually what I think would be nice, to wake up the car in such cases. This would fix that issue without the need to increase the polling interval unnecessarily. Further, it will only happen if this "rare" case happens.
I use default settings.
Regards
In a similar vein, is it possible to poll more frequently while driving? Maybe every minute while driving and then the setup frequency while not in drive?
@InTheDaylight14 yes it does already. By default it polls every 60 seconds while driving, 300 seconds when parked and not trying to sleep, and 660 seconds when trying to sleep.
I think the answer might be to decrease the charging polling interval just like it does for driving, so that we get an update to understand if it's finished charging before it goes to sleep, and then slow down the polling rate back to normal.
I find it unusual that the car would go to sleep within < 5 minutes of finishing charging, given the default polling rate, but I have my polling interval set to 15 seconds so I never noticed this as it will finish charging, and then it'll go from 15 seconds to 660 seconds to let it sleep.
I have a WIP pr which updates the online/sleep logic and I'll see if I can find a way to address this post-charging issue without waking the car just to poll it. Otherwise I think it would be risky in causing the integration to start keeping cars awake when not desired.
300 seconds when parked and not trying to sleep, and 660 seconds when trying to sleep.
How is that determined (whether it's trying to sleep or not), I always thought the integration will switch to 660 immediately after driving to let the car sleep.?
I think the answer might be to decrease the charging polling interval just like it does for driving, so that we get an update to understand if it's finished charging before it goes to sleep, and then slow down the polling rate back to normal.
Sounds like a solution :)
By default it polls every 60 seconds while driving, 300 seconds when parked and not trying to sleep, and 660 seconds when trying to sleep.
Oh cool! Would you mind pointing me to where that happens in the code? Just curious to read through it.
@InTheDaylight14 all of these time defaults are defined in teslajsonpy/const.py, and used in controller.py
It should also be doing 60 seconds during charging or when climate is on. Please reference the wiki.
It should also be doing 60 seconds during charging or when climate is on. Please reference the wiki.
@alandtse maybe the wiki is out of date? the code doesn't do this, I double checked. it only polls vehicle data at 60 second intervals when the vehicle is in gear.
I may be misremembering but the Wiki should be considered the spec we adhere to. If we don't match it, then it's a bug. We'll need to see about reminding PRs to include wiki updates.
Looking at it again, https://github.com/alandtse/tesla/wiki/Polling-policy, it looks like it stuck to polling_interval while charging. I am ok with a PR taking it down to 60 seconds. The car isn't sleeping so the energy cost should be minimal. The other alternative is to schedule an update at the last known estimated completion time since we have that now.
Do we have any tests made with all those different pooling settings? I mean that we have 3 different policies: normal/connected/always and additionally we can set different pooling intervals. I am really considering how all of them actually impact the battery life during standby/charging/driving. Maybe we shouldn't be so restrict...
Today my logbook got spammed probably due to this behavior.
The charging session was short (got Tesla app push notifications) and already finished by that time but the car stayed on "Charging".
Please let me know if I can help with any log files.
Today my logbook got spammed probably due to this behavior.
The charging session was short (got Tesla app push notifications) and already finished by that time but the car stayed on "Charging".
Please let me know if I can help with any log files.
Polling every minute might fix that issue but it's really driven by poor logic when I first wrote the sensor. There is a PR https://github.com/alandtse/tesla/pull/419 ready to fix the time charge complete updating every minute like in these logs.
I've tried making an automation that sets the polling_interval to 60 when the car is plugged in, and then back to 660 when not plugged in. However, the car was going to sleep anyways. I ended up creating an automation that forces an update while it is charging.
alias: "Car update"
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.catmobile_charging
from: "off"
to: "on"
condition: []
action:
- repeat:
while:
- condition: state
entity_id: binary_sensor.catmobile_charging
state: "on"
sequence:
- delay:
hours: 0
minutes: 3
seconds: 0
milliseconds: 0
- service: button.press
data: {}
target:
entity_id: button.catmobile_force_data_update
mode: single
@mikkelzzz3 thanks for the approach, I was also trying to change the update interval