Closed birkirb closed 6 months ago
It seems to be the same as https://github.com/nickknissen/hass-monta/issues/49 The problem is that Monta API is returning wrong ID's when the plugin tries to fetch charges.
I will close this issue because of duplication.
It seems to be the same as #49 The problem is that Monta API is returning wrong ID's when the plugin tries to fetch charges.
Hmm... then why does the Switch Off work outside of a script? :thinking:
Can you maybe elabborate on that? Are there some cases where it works?
Yes, when using this button.
I'll enable the Debug and try to spot if there's any difference in the API calls. Sounds like you are certain it's not the token.
As reported in issue #49 there where some problems with stop charge which should be resolved now that Monta has fixed the list charges endpoint.
I have tested both start/stop charge via the controls button and service and both works on my end. If you still have the issue, please enable debug and forward the logs to me with a start and stop.
System Health details
None
Checklist
Describe the issue
The issue is the Invalid Credentials error that occurs (see debug logs below). The issue occurs in an Automation that turns on charging and then sets up a time delay trigger for a switch off a few hours later.
When the switch off is executed the error occurs.
Given what I know about the Monta API, and some of the symptoms I'd like to offer the following hypothesis:
Most likely an Oauth token is created for every new instance of the integration and this token has a very short lifetime (say less than two hours). The same instance is used for the lifetime of the Automation and when used like this the credentials are already expired when the next call happens.
This hypothesis has the additional observation that even as the Switch Off fails in the Automation, I can open the device view and press the switch off button and it will work there.
A possible resilient solution would be to try and capture errors like this, refresh the credentials and try again.
I left out the diagnostic dump and system health details, but will be happy to try and provide them if you deem the current info insufficient.
Many thanks for making your integration available to the Home Assistant Community! :muscle: :bow:
Reproduction steps
Debug logs
Diagnostics dump
None