Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tapo: Enable KLAP protocol + P100 devices #10606

Merged
merged 25 commits into from
Nov 12, 2023
Merged

Conversation

thierolm
Copy link
Sponsor Contributor

@thierolm thierolm commented Nov 1, 2023

This PR enables evcc to use TAPO plugs having a newer firmware that supports only the new KLAP protocol.
Refer to discussion #10461

Additionally the complete tapo go module structure was redesigned, based on the top work of @insomniacslk.
Refer to https://github.com/insomniacslk/tapo

Test-runs
Passthrough-Protocol (deprecated):

thierolm@LAPTOP-KQMMVN3H:~/git-repos/evcc$ ./evcc -c ./evcc_tapotest.yaml -l debug charger
[main  ] INFO 2023/11/07 23:37:51 evcc 0.121.5 (d98c2b72)
[main  ] INFO 2023/11/07 23:37:51 using config file: ./evcc_tapotest.yaml
[db    ] INFO 2023/11/07 23:37:51 using sqlite database: /home/thierolm/.evcc/evcc.db
[tapo  ] DEBUG 2023/11/07 23:37:51 SMART.TAPOPLUG P110 connected (fw:1.2.3 Build 230425 Rel.142542,hw:1.0,mac:54-AF-97-1D-5E-98)
[tapo  ] DEBUG 2023/11/07 23:37:51 SMART.TAPOPLUG P100 connected (fw:1.1.0 Build 220720 Rel.163239,hw:2.0,mac:34-60-F9-9C-B5-E1)
wb-Tapo-P110
------------
Power:         0W
Charge status: B
Enabled:       false
Charged:       0.0kWh
Features:      []

wb-Tapo-P100
------------
[tapo  ] WARN 2023/11/07 23:37:52 meter not available
Power:         300W
Charge status: C
Enabled:       true
Charged:       0.0kWh
Features:      []

KLAP-Protocol (newer fw versions - P100 fw:1.2.1 Build 230804 Rel.190922):

thierolm@LAPTOP-KQMMVN3H:~/git-repos/evcc$ ./evcc -c ./evcc_tapotest.yaml -l debug charger
[main  ] INFO 2023/11/12 00:49:23 evcc 0.122.0 (b4b154e4)
[main  ] INFO 2023/11/12 00:49:23 using config file: ./evcc_tapotest.yaml
[db    ] INFO 2023/11/12 00:49:23 using sqlite database: /home/thierolm/.evcc/evcc.db
[tapo  ] DEBUG 2023/11/12 00:49:23 SMART.TAPOPLUG P100 connected (fw:1.2.1 Build 230804 Rel.190922,hw:2.0,mac:34-60-F9-9C-B5-E1)
[tapo  ] DEBUG 2023/11/12 00:49:23 meter not available
Power:         300W
Charge status: C
Enabled:       true
Charged:       0.0kWh
Features:      []

meter/tapo/connection.go Outdated Show resolved Hide resolved
@andig andig marked this pull request as draft November 1, 2023 22:46
@andig andig added the enhancement New feature or request label Nov 2, 2023
meter/tapo/connection.go Outdated Show resolved Hide resolved
@thierolm
Copy link
Sponsor Contributor Author

thierolm commented Nov 4, 2023

@AndySchoe , ist deine Tapo Dose schon zu mir unterwegs? Ich denke die Chance stehen gut, dass ich sie erfolgreich testen kann. :-)

@thierolm thierolm changed the title Tapo: Enable KLAP protocol + redesign Tapo: Enable KLAP protocol + P100 devices Nov 7, 2023
@thierolm
Copy link
Sponsor Contributor Author

thierolm commented Nov 7, 2023

Die P100 von @AndySchoe ist bei mir angekommen :-) Vielen Dank!! Ich habe sie eingerichtet und auf den aktuellsten Firmwarestand gebracht. Beim Testen hat sich herausgestellt, dass die Probleme der Dose nicht durch das KLAP Protokoll ausgelöst worden ist, sondern durch das fehlende Meter Feature bei der P100 zum Fehler-Code {"error_code":-1001} führt.
Ich habe diesen jetzt behandelt und schon funktionierts:

thierolm@LAPTOP-KQMMVN3H:~/git-repos/evcc$ ./evcc -c ./evcc_tapotest.yaml -l debug charger
[main  ] INFO 2023/11/07 23:37:51 evcc 0.121.5 (d98c2b72)
[main  ] INFO 2023/11/07 23:37:51 using config file: ./evcc_tapotest.yaml
[db    ] INFO 2023/11/07 23:37:51 using sqlite database: /home/thierolm/.evcc/evcc.db
[tapo  ] DEBUG 2023/11/07 23:37:51 SMART.TAPOPLUG P110 connected (fw:1.2.3 Build 230425 Rel.142542,hw:1.0,mac:54-AF-97-1D-5E-98)
[tapo  ] DEBUG 2023/11/07 23:37:51 SMART.TAPOPLUG P100 connected (fw:1.1.0 Build 220720 Rel.163239,hw:2.0,mac:34-60-F9-9C-B5-E1)
wb-Tapo-P110
------------
Power:         0W
Charge status: B
Enabled:       false
Charged:       0.0kWh
Features:      []

wb-Tapo-P100
------------
[tapo  ] WARN 2023/11/07 23:37:52 meter not available
Power:         300W
Charge status: C
Enabled:       true
Charged:       0.0kWh
Features:      []

@thierolm
Copy link
Sponsor Contributor Author

thierolm commented Nov 7, 2023

@andig Leider hab' ich jetzt keine Dose mit KLAP Protokoll zum Testen.
Allerdings ist m.E. durch den Switch auf das Repo von @insomniacslk mit hoher Wahrscheinlichkeit sicher gestellt, das solche Devices zukünftig funktionieren.
Ich würde für mergen voten :-)
Was meinst du?

@thierolm
Copy link
Sponsor Contributor Author

thierolm commented Nov 7, 2023

Hier noch das charger Trace Log der P100 von @AndySchoe:
(Man sieht sehr schön, dass eine Verbindung via KLAP versucht wird, aber weil das failed dann auf Passthru geswitched wird.)

[main  ] INFO 2023/11/08 00:00:04 evcc 0.121.5 (d98c2b72)
[main  ] INFO 2023/11/08 00:00:04 using config file: ./evcc_tapotest.yaml
...
[tapo  ] TRACE 2023/11/08 00:00:04 KLAP handshake failed, trying passthrough handshake
[tapo  ] TRACE 2023/11/08 00:00:04 Handshake request: {"method":"handshake","requestTimeMils":1699398004982,"params":{"key":"-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDqwhwaiJiQwM7VQnasJdS05q8V\npw7HJPut0IGj9bIMe3rJaV0clmuOnjM6sXRUmGSIpSstju09sFfXqSHDQGov95sn\nTf9U+692b23Z39xHRZBVwTj4Z8TAddfbjob5Xw3NZwUQkjw5j7UqnqyhFDMMyqpL\nb0AfM5U6o4ntqx694QIDAQAB\n-----END PUBLIC KEY-----\n"}}
[tapo  ] TRACE 2023/11/08 00:00:04 Handshake response: {"error_code":0,"result":{"key":"2XoP6TOne4Ta3PXFIQ0tJK3TiXenPjPmk9WZ51Jox22oZGvk84+1+PN0UaBMaZNchaDLxNjGpLajlEQkpjLwZ3T+9d/Q+FW0Hcp0qtIx2Ai2DaY3TA5skwofAF1efKy0fO6Nkp0wKfRWap2LRIYIRpplmEYtGvwBiHvkBxNDfho="}}
[tapo  ] TRACE 2023/11/08 00:00:05 Login request: {"method":"login_device","requestTimeMils":1699398005000,"params":{"username":"MWYzYzU4N2JmMjRhYzUwY2RiY2RmZjUyZjAxMmI1MWQ0MzM0OGY1Mw==","password":"dGFwbzEyMzQ="}}
[tapo  ] TRACE 2023/11/08 00:00:05 Passthrough request: {"method":"securePassthrough","params":{"request":"4zAmKoA8WrpHkPmCUPxlRyxWv+eBUgfT/WUK75CixW8LtMAZ1S5as4HIoKN6GHezEmHSi04nymH1ueALfyDhMchwv9EFt97KvSPUS/bx5Q0defjn3VIynZf314uydn5rNmBU8oHcx71svXv/2Vxqre5vTAkf3RvkciM2gfxGzKOa9jZD35dFLivoTtW0gApFsuyeqtT2PY5OuhgoVkd92Whdz9rnUaY2dqBSTBfbOkE="}}
[tapo  ] TRACE 2023/11/08 00:00:05 Passthrough response: {"error_code":0,"result":{"response":"CRP3Jqq8SL3PXU8LP0MDqlVrxL8YvK+buIT3hb3mV9n6pNS0W5ZdPu6SFnKnzXFUVMjDIPCZ8J5lRaFuRjkgPEDTXxjiwvOzO5HzZhiy4w4="}}
[tapo  ] TRACE 2023/11/08 00:00:05 Login response: {"error_code":0,"result":{"token":"F16F1792853A1791D00014916A2A9490"}}
[tapo  ] TRACE 2023/11/08 00:00:05 Session: &{log:0xc001506180 Key:[238 227 16 146 137 245 145 146 31 70 17 146 172 141 17 146] IV:[231 212 17 146 62 241 17 146 155 157 17 146 119 207 17 146] ID:TP_SESSIONID=CA3D14B357E790900D299392C3041193 addr:{addr:{hi:0 lo:281473914024589} z:0xc000128078} username:m.thiexxxx password:txxx token:F16F1792853A1791D00014916A2A9490 privateKey:0xc000bb8000 publicKey:0xc000bb8000 timeout:0}
[tapo  ] TRACE 2023/11/08 00:00:05 GetDeviceInfo request: {"method":"get_device_info","requestTimeMils":1699398005008}
[tapo  ] TRACE 2023/11/08 00:00:05 Passthrough request: {"method":"securePassthrough","params":{"request":"Q/LSM87CJN1NBYUN3rplAniDturL/EEYjLkEllD6iytwvnLhprcGYeOun1nh8L07qdtITHnx5LSwPzC/q2yWpw=="}}
[tapo  ] TRACE 2023/11/08 00:00:05 Passthrough response: {"error_code":0,"result":{"response":"1dnP/SaqUTbrf3lREE65STsm/W1dpjbA6hrrvUd13zV4NQk3qTiouX+y8E7OMdubdb6/48jLBUzuzz7hRr2In0IaVy+S0PZk5kqgtAgBTf6rZPrHock42ao93mrQcLEVFAazoWibBpaZ5AAY2e7aCMHB5g9Z4SzBQA1dmW8Ma1u+D4QW4Yb5Sav2gZ7TeMVGw4xTz7rJtZyjMKPVXjGc8puJ84VHv4g6GwtJ+Ufu4KUkGb7iY5UkAGYmDJNUyFJmQn/ZqmSQW/korZaLWVJIJ47NQKsfRw2AMkoRnKoM+GdYClkMjIbe1+dzW+5Xhx6CB0Gu2XHRsMa5CMxIibvmYHfaG+eeUQddMsDWJ3Vb2z0L7n2d9E3c6sof5pRcmuaDJ4swz0kHnFwhOC0QfRpBkQJ/EBXGOuR+nXxuftGqsqfhUt9RQPUeyt08nFrlhl4DfXeewSi752jWLs7Mo7DM6htYpdT7A7RNP+QX1t7uXa9LYEMvqbND7LH9kL/mWTg9WuyvHgWlisDXqUxrGjVhD4UMN4N0bdK104rcYAGIV7IDPZ6B+wjnIldLEaO4U8ZRNmRmEjB/mfwYLQCWR2uvzN3uhJjbtrJobTUSU+kB5APxokO1nmq5dhnG2na+dxPmdootk8cGtHUjw8oP5cXiNwha9Sf00rjOLB3E+DnRC2+toK2gSwJ5L8Ik7Op+EAzMTMbxun0YemuOpmQsX0VaGYUbfTbBan9nd/IP8uvtwcAatF4syQHcRpDHgrBna5qaDgNoS3dTyI7/qgNR4qOzDNGXnu9f11mTiep1StMg9nPzWLULBVnlyAnYawFp/bScwXoBRARqMnoPAxIJdV0klQHA+edzIxsZnOnjC5SwRV/ZFTIcI5CP3kUOdBdGchkGajXZW9aKqUp+wemaUkZBfg=="}}
[tapo  ] TRACE 2023/11/08 00:00:05 GetDeviceInfo response: {"result":{"device_id":"8022787193A97B73E48B699466A2F0D520076842","fw_ver":"1.1.0 Build 220720 Rel.163239","hw_ver":"2.0","type":"SMART.TAPOPLUG","model":"P100","mac":"34-60-F9-9C-B5-E1","hw_id":"4D44B233807D5BDA45BEC69DC18AAE09","fw_id":"00000000000000000000000000000000","oem_id":"6A0E161B05B8FB93E53988B66CE51E30","ip":"192.168.178.141","time_diff":60,"ssid":"VEhJRVJPTEYtV0xBTg==","rssi":-68,"signal_level":2,"latitude":498164,"longitude":90563,"lang":"","avatar":"plug","region":"Europe/Berlin","specs":"","nickname":"VGFwbyBQMTAw","has_set_location_info":true,"device_on":true,"on_time":1339,"default_states":{"type":"last_states","state":{}},"overheated":false},"error_code":0}
[tapo  ] DEBUG 2023/11/08 00:00:05 SMART.TAPOPLUG P100 connected (fw:1.1.0 Build 220720 Rel.163239,hw:2.0,mac:34-60-F9-9C-B5-E1)
...
[tapo  ] TRACE 2023/11/08 00:00:05 GetEnergyUsage request: {"method":"get_energy_usage","requestTimeMils":1699398005105}
[tapo  ] TRACE 2023/11/08 00:00:05 Passthrough request: {"method":"securePassthrough","params":{"request":"pxJ7b32YfmU68J7aI+sSnOYB/9LgepEIvjEGnxlxwRjNZO8qbfPc6umO0i4Qqkn11cu+OJZzRW4h9lPLzIRHMw=="}}
[tapo  ] TRACE 2023/11/08 00:00:05 Passthrough response: {"error_code":0,"result":{"response":"gXMYxo00iIwwrh9Cn0+9Ur83sfBfc1sDdbvKwfty5Qc="}}
[tapo  ] TRACE 2023/11/08 00:00:05 GetEnergyUsage response: {"error_code":-1001}
[tapo  ] WARN 2023/11/08 00:00:05 meter not available
Power:         300W
Charge status: C
Enabled:       true
Charged:       0.0kWh
Features:      []

@thierolm thierolm marked this pull request as ready for review November 7, 2023 23:10
@thierolm
Copy link
Sponsor Contributor Author

thierolm commented Nov 7, 2023

@andig ich habe versucht den go.mod Konflikt mit go mod tidy aufzulösen. Hat leider nicht funktioniert. Hast du einen Tip?

@andig
Copy link
Member

andig commented Nov 8, 2023

User/password sollten noch redacted werden ;)

@andig
Copy link
Member

andig commented Nov 9, 2023

Ouch, that was unwanted.

We can always redact in evcc. From a library I would expect the raw data, typically wire data. To be able to redact though, I need to supply an evcc logger, not a log.Logger.

@thierolm
Copy link
Sponsor Contributor Author

thierolm commented Nov 11, 2023

Hi @andig, wollen wir diesen PR nicht schon mergen? Funktional bietet er ja schon dass, was das Tapo Modul bisher konnte und unterstützt zusätzlich die P100 Dose.
@AndySchoe wäre damit schon in der Lage seine beiden P100 Dosen zu nutzen.

Ich kann mich in einem neuen PR um das "improvement" des Loggings kümmern. (Hab' mir das schon mal angeschaut, werde das aber nicht so schnell zum Fliegen bekommen ...)

@thierolm
Copy link
Sponsor Contributor Author

thierolm commented Nov 11, 2023

Die Firmware der P100 von @AndySchoe wurde heute aktualisiert. Ich konnte auch das KLAP Protokoll erfolgreich testen (siehe PR Beschreibung oben) :-)
Ich konnte es im Trace Log nachvollziehen. :-)

thierolm@LAPTOP-KQMMVN3H:~/git-repos/evcc$ ./evcc -c ./evcc_tapotest.yaml -l trace charger
[main  ] INFO 2023/11/12 00:48:53 evcc 0.122.0 (b4b154e4)
[main  ] INFO 2023/11/12 00:48:53 using config file: ./evcc_tapotest.yaml
[db    ] INFO 2023/11/12 00:48:53 using sqlite database: /home/thierolm/.evcc/evcc.db
[db    ] TRACE 2023/11/12 00:48:53 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="settings" -1 <nil>
...
[db    ] TRACE 2023/11/12 00:48:53 SELECT * FROM `configs` WHERE `configs`.`class` = 1 ORDER BY id 0 <nil>
[tapo  ] TRACE 2023/11/12 00:48:53 GetDeviceInfo request: {"method":"get_device_info","requestTimeMils":1699746533528}
[tapo  ] TRACE 2023/11/12 00:48:53 Plaintext: {"method":"get_device_info","requestTimeMils":1699746533528}
[tapo  ] TRACE 2023/11/12 00:48:53 Seq: -390014968
[tapo  ] TRACE 2023/11/12 00:48:53 IV: [0 72 105 212 132 254 135 237 0 97 111 184 232 192 216 8]
[tapo  ] TRACE 2023/11/12 00:48:53 Padded plaintext: [123 34 109 101 116 104 111 100 34 58 34 103 101 116 95 100 101 118 105 99 101 95 105 110 102 111 34 44 34 114 101 113 117 101 115 116 84 105 109 101 77 105 108 115 34 58 49 54 57 57 55 52 54 53 51 51 53 50 56 125 4 4 4 4]
[tapo  ] TRACE 2023/11/12 00:48:53 Ciphertext: [8 249 199 228 154 228 174 106 119 141 73 91 235 171 100 132 215 232 244 21 188 34 201 182 242 7 115 89 149 3 227 250 111 215 7 159 159 37 46 191 234 109 55 29 1 134 77 28 95 110 117 2 202 44 119 70 78 65 147 241 66 156 250 49]
[tapo  ] TRACE 2023/11/12 00:48:53 Digest 96 [141 255 231 138 10 42 149 4 217 7 62 34 255 220 241 130 204 180 13 218 58 159 199 188 77 151 185 128 232 192 216 8 8 249 199 228 154 228 174 106 119 141 73 91 235 171 100
...

@andig
Copy link
Member

andig commented Nov 12, 2023

Es wäre schön das Logging noch zu korrigieren. Die Logs hier sind für evcc nicht sichtbar. Lass uns das gleich richtig machen. Es wäre auch schön, die iv/plaintext/cipthertext etc Meldungen los zu werden. So wie es jetzt ist lieber kein Logging, wäre auch ok.

@thierolm
Copy link
Sponsor Contributor Author

Ok, hab das logging erst mal deaktiviert, Fehler werden ja ausgegeben. Dann habe ich mehr Zeit, um am Logging zu arbeiten. Ich schaue mir dazu an, wie das evcc easee Modul mit der signalr library zusammenwirkt.

@andig andig merged commit c8c6f7d into evcc-io:master Nov 12, 2023
6 checks passed
@andig
Copy link
Member

andig commented Nov 12, 2023

Na dann rein damit- VIELEN DANK!

@thierolm
Copy link
Sponsor Contributor Author

Top! :-) @insomniacslk are PR's allowed to your tapo project? I would try to suggest some logging feature improvements ...

@insomniacslk
Copy link

Top! :-) @insomniacslk are PR's allowed to your tapo project? I would try to suggest some logging feature improvements ...

@thierolm absolutely welcome and encouraged!

@jove01
Copy link

jove01 commented Nov 29, 2023

Today I got a new update for Tapo and I hoped the problem is solved.
But in EVCC there is allways the same Error:

  • `[lp-1 ] ERROR 2023/11/29 13:37:06 charger: tapo error 1003:
  • [lp-1 ] ERROR 2023/11/29 13:37:07 charge meter: tapo error 1003:
  • [lp-1 ] ERROR 2023/11/29 13:37:07 charge rater: tapo error 1003:
  • [lp-1 ] ERROR 2023/11/29 13:37:07 charger: tapo error 1003:`

So I think, the problem is not solved. Do you need any Information to solve it.

For your Information: The Tapo-Integration works. I set the P110 to on in the App and I see that in HA, also the other way.

@thierolm
Copy link
Sponsor Contributor Author

Hi @jove01, the KLAP protocol extension is not yet deployed in evcc head branch ...

That's the reason for the error after Tapo firmware update.

Try the nightly until next release.

@jove01
Copy link

jove01 commented Nov 29, 2023

Hi @jove01, the KLAP protocol extension is not yet deployed in evcc head branch ...

That's the reason for the error after Tapo firmware update.

Try the nightly until next release.

Thanks for the Info

@andig
Copy link
Member

andig commented Dec 3, 2023

@insomniacslk the latest dependency upgrade has brought this:

go: upgraded github.com/insomniacslk/tapo v0.0.0-20231102105048-52dbe7a83ca7 => v0.0.0-20231130201649-d2497ac78359

Mentioned as word of warning. If you want to make breaking changes it would be good to release a stable 1.0 version before doing so or we will catch these breaking changes.

@insomniacslk
Copy link

@andig thanks for the heads-up, I'll cut a 1.0 release tomorrow. Those changes are not breaking (at least not the library, just the CLI), but the code is stable enough to deserve a release

@insomniacslk
Copy link

I've just published the tag v1.0.0 based on the latest commit

@xXApfelmusTVXx
Copy link

Hi @jove01, the KLAP protocol extension is not yet deployed in evcc head branch ...

That's the reason for the error after Tapo firmware update.

Try the nightly until next release.

When is the next Update comming for evcc with thus Problem solved

@xXApfelmusTVXx
Copy link

Hi @jove01, the KLAP protocol extension is not yet deployed in evcc head branch ...

That's the reason for the error after Tapo firmware update.

Try the nightly until next release.

Hey @theirolm,
Do you know when evcc get his New update with this proble solved?

@thierolm
Copy link
Sponsor Contributor Author

Sorry, no. @andig is the owner of release planning. I expect there is a plan to have a Christmas release ...

@thierolm
Copy link
Sponsor Contributor Author

Christmas release including KLAP protocol is out now:
https://github.com/evcc-io/evcc/releases/tag/0.123.0
image

@xXApfelmusTVXx

This comment was marked as off-topic.

@xXApfelmusTVXx

This comment was marked as off-topic.

@thierolm
Copy link
Sponsor Contributor Author

To answer this, U have to provide your evcc.yaml to identify the obsolete settings ... see breaking changes.

@xXApfelmusTVXx

This comment was marked as off-topic.

@xXApfelmusTVXx

This comment was marked as off-topic.

@andig
Copy link
Member

andig commented Dec 22, 2023

This PR has been completed and released. Closing.

@evcc-io evcc-io locked as resolved and limited conversation to collaborators Dec 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants