datMaffin / homebridge-tesla-powerwall

Homebridge Plugin for the Tesla Powerwall
ISC License
21 stars 11 forks source link

Authentication token required since Powerwall 2 firmware version 20.49.0 #21

Closed angelosan closed 3 years ago

angelosan commented 3 years ago

After updating to version 20.49.0 the plugin does not work. Thank you

datMaffin commented 3 years ago

The current (breaking) update is also discussed in: https://github.com/vloschiavo/powerwall2/issues/41

I will look into the issue at the earliest at the beginning of April.

gmankono commented 3 years ago

I found this issue as well after updating Homebridge to 1.3.0 and finding new log entries about the homebridge-tesla-powerwall plug-in generating warnings about values expected showing up as undefined ("This plugin generated a warning from the characteristic 'Brightness': characteristic value expected number and received undefined. See https://git.io/JtMGR for more info.")

In checking the IP address web interface for my Powerwall (running firmware "CUSTOMER VERSION 20.49.0"), I now find that the basic details about charging performance is no longer available at the initial page for the Powerwall without logging in to the system using the Tesla Gateway or Backup Gateway information, which seems unfortunate, but understandable if they are trying to secure the system info on a LAN.

I haven't studied the plug-in enough to know how it is passing the information from the powerwall web interface to know how to pass that information along from the plug-in configuration, so I'll set a reminder for myself to check back after the first week of April.

Kudos to datMaffin for the plug-in, and many thanks for your time on continued development.

datMaffin commented 3 years ago

I found this issue as well after updating Homebridge to 1.3.0 and finding new log entries about the homebridge-tesla-powerwall plug-in generating warnings about values expected showing up as undefined ("This plugin generated a warning from the characteristic 'Brightness': characteristic value expected number and received undefined. See https://git.io/JtMGR for more info.")

In checking the IP address web interface for my Powerwall (running firmware "CUSTOMER VERSION 20.49.0"), I now find that the basic details about charging performance is no longer available at the initial page for the Powerwall without logging in to the system using the Tesla Gateway or Backup Gateway information, which seems unfortunate, but understandable if they are trying to secure the system info on a LAN.

I haven't studied the plug-in enough to know how it is passing the information from the powerwall web interface to know how to pass that information along from the plug-in configuration, so I'll set a reminder for myself to check back after the first week of April.

Kudos to datMaffin for the plug-in, and many thanks for your time on continued development.

Yeah, regarding the warnings with homebridge 1.3.0 see also #22. Fixing the warnings should be fairly easy to do. My guess would be that a fix similar to what was needed for #12 will suffice.

Fixing/Adding the authentication will (very likely) require more time.

Honosapiens commented 3 years ago

Hello, I'm also having this issue since the beginning of this year. Of course the issue is due to the Power Wall update 20.49.0. Is there an update on how to make it work again? Or still working on a fix for this? Thanks for the help as usual!

datMaffin commented 3 years ago

I already looked into the issue. I believe I know what is required to get it working again. The plan is to implement the changes this weekend.

datMaffin commented 3 years ago

Changes are now implemented. I did not yet have the ability to test whether it works or not.

It is possible to install the current version that was pushed to github with sudo npm install -g https://github.com/datMaffin/homebridge-tesla-powerwall. (To overwrite it with the old/regular version again, just call sudo npm install -g homebridge-tesla-powerwall).

The plugin now requires a "password" field in the config.json (see README). (There are additional fields for email and username, however, according to https://github.com/vloschiavo/powerwall2 they are currently ignored.)

Feedback welcome!

nisnu commented 3 years ago

Thanks @datMaffin. If I try executing the install command I receive an error:

npm ERR! code 128
npm ERR! Command failed: git clone --mirror -q https://github.com/datMaffin/homebridge-tesla-powerwall.git /root/.npm/_cacache/tmp/git-clone-3e7ecad5/.git
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-3e7ecad5/.git'

Do you have any idea what could be the cause? Is this an access right problem on my end?

datMaffin commented 3 years ago

@nisnu Thanks for trying to try the update.

Hmmm. Probably an issue of git + npm(?).

The current version is now also uploaded to npm (under the dev tag). To install, try executing: sudo npm install -g homebridge-tesla-powerwall@2.0.0-Beta.

ceeeekay commented 3 years ago

Thanks for getting this out. I've just tried the updated plugin but I'm getting [Tesla Powerwall] !! Login Failed !! in the logs, followed by repeated This plugin generated a warning from the characteristic ... errors.

        "platform": "TeslaPowerwall",
        "name": "Tesla Powerwall",
        "ip": "192.168.1.x",
        "username": "me@sample.com",
        "password": "XXXXX",
        "port": "",

These are the same credentials I use to access the Powerwall web interface. Powerwall IP is static fwiw.

Any ideas?

Homebridge v1.3.4 homebridge-config-ui-x v4.41.0 homebridge-tesla-powerwall v2.0.0-Beta (Confirmed on config-ui-x plugin page)

datMaffin commented 3 years ago

@ceeeekay Thanks for giving it a shot.

I now changed the request type for all requests to https, and (potential) login request errors will now be printed to the log. The new version can be installed with sudo npm install -g homebridge-tesla-powerwall@2.0.0-Beta2.

ceeeekay commented 3 years ago

With Beta2 I'm now getting [Tesla Powerwall] Login successful but the characteristic errors in the logs continue, and all Powerwall accessories in home are reporting Off.

datMaffin commented 3 years ago

@ceeeekay

Hmm, bummer. I must have misunderstood how the request library handles cookies then...

Regarding the characteristic errors, I believe I now understand why they are printed: I added a response code check such that ,for an unsuccessful response, it will return the default value instead of resorting to undefined.

With sudo npm install -g homebridge-tesla-powerwall@2.0.0-Beta3, it should now print out the error response, which should be not authorized or similar, and the characteristic errors should disappear. Still need to look into why the auth cookie is apparently not used.

Edit: forgot to change Beta2 to Beta3

ceeeekay commented 3 years ago

OK, on Beta3 now, and the errors seem unchanged:

[4/11/2021, 11:17:17 PM] [homebridge-tesla-powerwall] This plugin generated a warning from the characteristic 'Battery Level': characteristic value expected valid finite number and received "undefined" (undefined). See https://git.io/JtMGR for more info.

datMaffin commented 3 years ago

Ok. @ceeeekay, again, thanks for trying. Me, not being able to locally test it sucks... (Without the authentication, I was able to just start a mock server hosting example Powerwall responses.) I will hopefully be able to test it today by myself.

The next step would be to start homebridge with the -D (debug) parameter and look at the log...

ceeeekay commented 3 years ago

Here's the debug with just Powerwall results: https://gist.github.com/ceeeekay/7b62c5f2f59f830042ccdd64dcc0fa2d

So we have a login successful, but it's also failed. I guess that's the token failing?

datMaffin commented 3 years ago

Ok. At least the log printout works ;). ~(It looks like homebridge was started without the debug parameter, with the debug enabled it would be possible to see the response of all, even the successful, http requests, i.e., the login request response.)~.

Yeah, how the authentication should work is: call the login page, get a cookie, and then use the cookie in subsequent calls for authentication.

Edit: Oh I see what you mean: the login request fails, even though the message login successful is printed.

ceeeekay commented 3 years ago

That is definitely the debug output - it's about 10x chattier than the standard logs. Homebridge-config-ui-x gives you a handy debug switch that forces a restart, and that's the point I captured from the logs.

So yeah the visible difference between beta1 and beta2 is it's reporting it's logged in successfully but I don't see any other change in the logs since beta2.

It's after midnight Sunday here so I have to drop this for now. Happy to test any updates in the morning.

datMaffin commented 3 years ago

That is definitely the debug output

Ok. I believe I found (at least one) mistake in my code...

It's after midnight Sunday here so I have to drop this for now. Happy to test any updates in the morning.

Good night then, thanks for your work.

datMaffin commented 3 years ago

There is now sudo npm install -g homebridge-tesla-powerwall@2.0.0-Beta4 available.

Honosapiens commented 3 years ago

It's working, IT'S WORKING!!!!!!

ceeeekay commented 3 years ago

Yep, working for me as well, although I was having login failures with username set. It might be best to not pass this value anywhere if the user has set it in the config?

Anyway, great work! I have my grid state automations back again. Thanks!

angelosan commented 3 years ago

Hi, I updated the plugin, it works, but in the log I constantly find this error: "[homebridge-tesla-powerwall] This plugin generated a warning from the characteristic 'Consumption': characteristic was supplied illegal value: number -451 exceeded minimum of 0. See https://git.io/JtMGR for more info." Thanks!

nisnu commented 3 years ago

As well working for me, many thanks. Do you have any idea when this will be available (not only beta)? Reason behind: I would like to use the plugin as well via iobroker to realise dynamic loading of EV and I don't know how I can use the beta there.

datMaffin commented 3 years ago

@nisnu There is not a lot that holds a full release back: mainly a bit of documentation and gathering feedback if everything works as expected.

I am also thinking about whether it is now possible to turn the Powerwall on/off (previously this did not work because it always required some kind of authentication, now it might work), and whether there should be an option to explicitly (or by default) enable a read only mode such that an accidental "turn the Powerwall off", command will not result in some undesired behavior (I personally see no reason for turning the Powerwall off).

Honosapiens commented 3 years ago

Yes everything is working, Even the Power Wall is turning on and off. However the error "This plugin generated a warning from the characteristic 'Consumption': characteristic was supplied illegal value: number -20 exceeded minimum of 0. See https://git.io/JtMGR for more info." is slowing down the refresh rate on Home Kit. Is not a big deal, but it would be great to not see that error over and over again.

Thanks!

datMaffin commented 3 years ago

The warning regarding a negative consumption should now be fixed.

sudo npm install -g homebridge-tesla-powerwall@2.0.0-Beta5

ceeeekay commented 3 years ago

@datMaffin I would prefer that it's not possible to stop the system via homebridge. If you ever need to stop it there are multiple other ways to do so, and I don't see any value in exposing it to homebridge, and perhaps trigger it from an incorrect Siri command.

Honosapiens commented 3 years ago

Well, this is a good feature when you like to automate your system.

nisnu commented 3 years ago

Great, I confirm everything works perfectly!

As well I can confirm that switching on/off is working for me. I cannot think currently about any reason for switching on/off the Powerwall. The read only option is probably a good idea, but personally I do not need it urgently.

ceeeekay commented 3 years ago

@Honosapiens consider for a moment that the Powerwall appears to Homekit as a light. What if you ask Siri to turn off all the lights?

Giving Homebridge access to stop the Powerwall creates a whole mess of issues, and maybe solves a single case of you wanting to automate shutting it down it somehow -- although I don't see how doing that could be helpful in any way.

As I said before, in the unlikely event you would ever want to stop your Powerwall there are other ways to do it, such via as the gateway web interface.

Honosapiens commented 3 years ago

I get all that, but what you can do is remove on your Homebridge the Powerwall Switch. This way we all have what we like and what we need.

Thanks!

angelosan commented 3 years ago

I'm sorry but I have to report an additional problem :( [homebridge-tesla-powerwall] This plugin generated a warning from the characteristic 'Reset': characteristic value expected valid finite number and received "undefined" (undefined). Thank you for your time

Honosapiens commented 3 years ago

Yes, I'm receiving a similar error:

[@milo526/homebridge-tuya-web] This plugin generated a warning from the characteristic 'Brightness': characteristic was supplied illegal value: number 392 exceeded maximum of 100. See https://git.io/JtMGR for more info.

Thanks!

datMaffin commented 3 years ago

Yes, I'm receiving a similar error:

[@milo526/homebridge-tuya-web] This plugin generated a warning from the characteristic 'Brightness': characteristic was supplied illegal value: number 392 exceeded maximum of 100. See https://git.io/JtMGR for more info.

Thanks!

Brightness is set to be equal to the percentage of the battery filling. So your battery seems to be charged to almost 400%(?). I assumed the battery percentage must be within [0, 100].

Are more than 100% reasonable? Would an option to define a maximum battery percentage be reasonable?

To solve it (in the short term), I am just going to set every value above 100 to 100.

datMaffin commented 3 years ago

sudo npm install -g homebridge-tesla-powerwall@2.0.0-Beta6 is now available.

There is now a new config option "additionalServices"."powerwall"."makeOnOffSwitchReadOnly", which is true by default.

ceeeekay commented 3 years ago

Perfect, thanks @datMaffin.

jongent commented 3 years ago

Thanks @datMaffin! Running Beta6 without problems at all. I did get tripped up with the username thing like was mentioned above too. Passed the value initially and got the error below repeatedly. Removed that username from my config.json and it works beautifully just like it used to. Also thanks very much for the default switching behavior to be read only and for adding that as an option for those who may want it (not me, LOL). Thanks again!

[4/16/2021, 6:56:52 PM] [Powerwall] error: null [4/16/2021, 6:56:52 PM] [Powerwall] status code: 403 [4/16/2021, 6:56:52 PM] [Powerwall] body: {"code":403,"error":"Unable to GET to resource","message":"User does not have adequate access rights"}

cjastennett commented 3 years ago

Thanks for all hard work on this @datMaffin

I have installed the new beta version, and updated my config with password etc.

I have reverted to the basic miminal config:

{ "platform": "TeslaPowerwall", "name": "Tesla Powerwall", "ip": "192.168.1.XXX", "password": "XXXXXXXXXXXXXXX" }

I get a login failure:

[17/04/2021, 23:52:30] [Tesla Powerwall] error: null [17/04/2021, 23:52:30] [Tesla Powerwall] status code: 401 [17/04/2021, 23:52:30] [Tesla Powerwall] body: { code: 401, error: 'bad credentials', message: 'Login Error' } [17/04/2021, 23:52:30] [Tesla Powerwall] !! Login Failed !!

and then continual errors after that:

[17/04/2021, 23:55:57] [Tesla Powerwall] status code: 403 [17/04/2021, 23:55:57] [Tesla Powerwall] body: {"code":403,"error":"Unable to GET to resource","message":"User does not have adequate access rights"} [17/04/2021, 23:55:57] [Tesla Powerwall] error: null

The Tesla Powerwall is online and pingable. Pasword has been verified and checked correct. Powerwall is on version 20.49.0

Any ideas?

cheers


SOLUTION FOUND:

My powerwall, for some reason, required a re-registration and password update. Once done, it all worked perfectly - Thanks

datMaffin commented 3 years ago

@cjastennett

SOLUTION FOUND: My powerwall, for some reason, required a re-registration and password update. Once done, it all worked perfectly - Thanks

Thanks for reporting a solution. I will add this to the README faq.

cjastennett commented 3 years ago

I am now repeatedly getting the following error in the log, typically in groups of 4:

[21/04/2021, 17:14:53] [homebridge-tesla-powerwall] This plugin generated a warning from the characteristic 'Reset': characteristic value expected valid finite number and received "undefined" (undefined). See https://git.io/JtMGR for more info.

with the following setup:

{ "platform": "TeslaPowerwall", "name": "Tesla Powerwall", "ip": "192.168.1.XXXXXX", "password": "XXXXXXXXX", "email": "XXXXXX@XXXXXXXX.XX", "loginInterval": 39600000, "pollingInterval": 15000, "historyInterval": 300000, "lowBattery": 10, "additionalServices": { "powerwall": { "homekitVisual": true, "eveHistory": true, "batteryIsLowSwitch": false, "batteryIsChargingSwitch": false, "makeOnOffSwitchReadOnly": true }, "solar": { "homekitVisual": true, "evePowerMeter": true, "eveHistory": true, "eveLineGraph": false }, "grid": { "homekitVisual": true, "positiveEvePowerMeter": true, "negativeEvePowerMeter": false, "eveHistory": true, "eveLineGraph": false }, "battery": { "homekitVisual": true, "positiveEvePowerMeter": true, "negativeEvePowerMeter": false, "eveHistory": true, "eveLineGraph": false }, "home": { "homekitVisual": true, "evePowerMeter": true, "eveHistory": true, "eveLineGraph": false }, "gridstatus": { "gridIsDownSwitch": true, "gridIsUpSwitch": false, "gridIsNotYetInSyncSwitch": false, "gridIsDownSensor": false, "gridIsUpSensor": false } } }

Any thoughts?

datMaffin commented 3 years ago

@cjastennett

characteristic 'Reset'

I am really not sure about what could be the issue here. From my side, I ensured that I never set anything to undefined (could have missed something, though, that is pretty unlikely).

A guess would be that the warning may(?) disappear when changing the historyInterval to a lower value.

I am starting to think that it might be triggered because of something https://github.com/simont77/fakegato-history does. We currently do use an older version of fakegato-history, there might already be a fix. I am pretty scared to touch the dependency though.

It would probably be best to just open a new issue. I can look into it after the whole authentication stuff is fully released and, for example, then release a version that uses the current fakegato-history, which can be used for testing purposes.

Honosapiens commented 3 years ago

@cjastennett

What version are you running. I had the same errorr you are describing, and was already fixed for me. Check if you are running the correct version Beta 6.

Here is the Terminal command:

sudo npm install -g homebridge-tesla-powerwall@2.0.0-Beta6

Hope this works for you.

mubenab1107 commented 3 years ago

@datMaffin

is it already foreseeable when the plugin for 20.49.0 will be released (not Beta) again?

datMaffin commented 3 years ago

@mubenab1107 I am currently only waiting for feedback from a person I know (personally) who uses this plugin.

mubenab1107 commented 3 years ago

@cjastennett @datMaffin how did you "re-registration" the powerwall? Just updating the password or some additional? I am fighting with the combination "Login successful" and then continual errors 403. All data are transfered to Homebridge. Maybe just cosmetic?

datMaffin commented 3 years ago

@mubenab1107 If you did fill in something into the username field, remove it (see also https://github.com/datMaffin/homebridge-tesla-powerwall#i-get-a-login-error ).

It is definitely considered a bug if "Login successful" is printed, but there are still authentication errors. The problem is that I do not have the means to reproduce an error like that on my own.

datMaffin commented 3 years ago

I just published (finally...) a non beta version to npm that is equivalent to Beta6 with improved documentation.

Outstanding issues regarding problems with authentication can still be discussed in this issue.

Otherwise, please open new issues.