Closed wtadler closed 2 years ago
Hello!
The batteryRemainingAmount
is coming from the login response. The library I use does not expose that value when doing a login. Also, I don't think there is a way to know if the value would be recent or very old.
To get the battery status, you have to publish the command update
to the leaf/{vin}/command/battery
topic.
In your logs, it looks like it was done, but the library received an error from the Nissan server. I recommend setting the variable COMMAND_ATTEMPTS
to 5 to let leaf2mqtt retry up to 5 times in this case.
A more reliable way to get the current battery % would be to follow the logic in the readme (Recommended Battery Status Update Script).
It uses the lastReceivedDateTimeUtc
and lastUpdatedDateTimeUtc
to know if the value is recent enough and will retry when it is not.
I will close this now, reopen it if you still have issues.
Hm, it seems that simply retrying the update command only helps on rare occasion. Every once in a while it will work, and will publish the battery state of charge via MQTT. But far more often, when I do the update command, I get no battery update, but a log just like the above: In Result
it lists a batteryRemainingAmount
that I know is up to date because I just drove the car and checked. The data even includes lastUpdatedDateAndTime
to know if the value is recent—and it usually is.
Is there any way to modify the library to publish these two values? Even appending their names with _login_response
or something like that would be a big improvement, if it's important to separate the two ways this info can make it in. It's just odd to get published battery updates only rarely when I know the library is indeed receiving updated values. (It is very reliable about publishing cabin temp and location.)
Hello @wtadler,
I tested it and those values are the same values as the one that are shown when you open the app before you click the refresh button. These values will be the values that was fetch from the car during the latest refresh (when you click the refresh button or call the update command). A login does not provoke a communication with the car, it must be a clear manual operation since it wakes the car and can deplete the car's 12v battery. So if there was no prior refresh done, the login values will be stale (Just checked, and they are 10 hours behind in my case even if the car was driven twice up to now)
Also, the library that is used by the leaf2mqtt service does not expose those values.
When you use the app, do you notice sometime you have to click refresh more than once to get the real latest values? In my case it happens often and it is the same behavior with the update command of leaf2mqtt. That is why in the readme you see an example on how to create a script in home assistant that will retry the update command multiple time up to a given limit and stop when it knows the values are good.
The package is not always publishing battery status, even though I can tell from my logs that Nissan is reporting it. Do a search for
batteryRemainingAmount
to see that Nissan is indeed reporting it, but that it's not being published via MQTT along with the other info.