dan-r / HomeAssistant-NissanConnect

Unofficial Home Assistant integration for interacting with Nissan Connect vehicles 🚗
Apache License 2.0
26 stars 6 forks source link

Woke to a Flat battery #14

Closed maegibbons closed 3 months ago

maegibbons commented 4 months ago

What happened? I meant to post this a couple of weeks ago when it happened. I had drafted a bug report but obviously did not press submit!

Basically the 12v battery was flat

To Reproduce Leave the car plugged in for 48 hours

Expected behavior Not to have a flat battery

Log Output

Home Assistant Version 2024.3

Integration Version 0.42

Additional context Basically you are checking for car being plugged in rather than charging to set the increased charging polling frequency.

When the car is plugged in and NOT charging it will drain the battery with increased polling.

dan-r commented 4 months ago

The increased polling rate is 15 minutes rather than an hour - if this kills the 12v battery it seems indicative of a weak battery. I've left my car for 8 days with the 1 hour poll rate and had no issues (which is 192 wakes, equivalent to quarter-hourly over 48h).

Checking for the car being plugged in is a conscious design decision so, for example, I can keep track of when the car is charging (or not) at a public/dumb charger.

The car being plugged in for 48 hours seems a rather niche use case - if this is something you do regularly I'd recommend changing the update interval from the 'Configure' menu: image

That said, I'll add a disclaimer to the docs to make it clear that 12v battery drain is a risk and that leaving the car plugged in for a long period while not charging is not recommended, and investigate adding an option to up the poll rate only when charging, not just when plugged in.

maegibbons commented 4 months ago

Yes. I understand all that.... and setting both to 60 minutes is exactly what I did so that regardless of plugged state it only ever polls every hour.

Plugged does not mean charging. Its a strange design decision to assume it does.

The Leaf can take increased polling during charging as the onboard traction to 12v charging circuit is active.

It is certainly not active when plugged in and not charging.

I don't think calculating the number of wakes on a one hour poll is the same as calculating them even every 15.

On the hour, the battery has a chance to sleep for the majority of the hour I.e. 55 mins out of every hour. Once every 15 mins means it sleeps only 40 mins of every hour assuming minimum 5 min wake time of every wake which I believe is what happens. I actually believe its worse than that in the sense that once its woken it does other housekeeping to the extent that at 15 minutes polling it hardly ever gets back to sleep IF the onboard 12v charging circuit is not active.

The plugged and not charging issue has been known about for years and was dealt with in leaf2mqtt.

dan-r commented 3 months ago

I'm currently testing a logic change in v0.4.5-beta.1 - if the car is plugged in but not charging for an hour (with default settings), it'll revert to the longer interval.

I'm reluctant to change to the same behaviour as leaf2mqtt as for certain use cases (like tracking the charge curve overnight with a 'smart' charger), it can result in less useful data. If you don't think this is an acceptable compromise, I can look to add an option to follow the leaf2mqtt behaviour at all times.

maegibbons commented 3 months ago

Sounds like a sensible solution. I will try it.

It would be good if you could expose the current delay time (interval) in minutes as a sensor so that we could plot that to make sure it is working correctly.

dan-r commented 3 months ago

I've been meaning to look into adding that sort of thing as a sensor, perhaps behind a configuration option, but for now if you enable debug logging for the integration you'll see messages in the log like: Changing next update interval to 15 minutes

So when I'm testing I tend to just do something like: docker logs homeassistant | grep "next update interval" or grep homeassistant.log "next update interval"

maegibbons commented 3 months ago

Just put it in as a disabled sensor in diagnostic section would be my suggestion.

dan-r commented 3 months ago

@maegibbons have you had a chance to test the new version yet? Seems to be working as expected for me.

maegibbons commented 3 months ago

Sorry. Not yet. But will do over next few days

dan-r commented 3 months ago

I've released this with v0.5.0 as in my testing its been working as expected. Please re-open this issue if you have any problems with it.

Dan