JurajNyiri / HomeAssistant-Tapo-Control

Control for Tapo cameras as a Home Assistant component
Apache License 2.0
1.1k stars 88 forks source link

Camera needs to be reconfigured when Home Assistant restarts #453

Closed jtsarnas76 closed 10 months ago

jtsarnas76 commented 10 months ago

Description

Using 4 tapo C310 cameras. 3 are working great. Fourth needs to be reconfigured every time ha restarts. Camera uses firmware 1.3.9 and it's hardware version 1.0. All 4 cameras using same credentials.

Reproduction Steps

  1. Originaly configured tapo camera and worked as expected
  2. On HA restart I get a notification that Integration requires reconfiguration
  3. I reconfigure using same credentials and works ok again

Expected behavior

Work with no need of reconfiguration

If applicable, add error logs.

Logger: homeassistant.config_entries Source: config_entries.py:426 First occurred: 8:10:06 PM (1 occurrences) Last logged: 8:10:06 PM

Config entry '192.168.1.49' for tapo_control integration could not authenticate: Invalid authentication data

This error originated from a custom integration.

Logger: custom_components.tapo_control Source: custom_components/tapo_control/init.py:760 Integration: Tapo: Cameras Control (documentation, issues) First occurred: 8:10:06 PM (1 occurrences) Last logged: 8:10:06 PM

Unable to connect to Tapo: Cameras Control controller: Invalid authentication data

Device Firmware

1.3.9 Build 231024 Rel. 73362n(4555)

Integration Version

5.4.4

Using stream component

Yes

Does camera work via official integrations?

Yes

Camera has all attributes filled out in developer tools

Yes

HASS Environment

HAOS bare metal x86

Search for similar issues

Yes

Additional information

No response

JurajNyiri commented 10 months ago

Are the other cameras using the new firmware as well?

jtsarnas76 commented 10 months ago

No. 2 are on 1.3.7, the third on 1.3.2

jtsarnas76 commented 10 months ago

Come to think of it, problem occurred after update, a couple of days ago

JurajNyiri commented 10 months ago

Try to factory reset the camera and remove and add to ha. Does the problem still happen?

jtsarnas76 commented 10 months ago

I 'll give it a go tomorrow and will provide feedback

JurajNyiri commented 10 months ago

@flipaz please create new issue for a different error. This issue is specifically for authorization requests after fresh ha boot.

flipaz commented 10 months ago

Ok I've deleted my previous comment as the issue is resolved.

ryann72 commented 10 months ago

hello, I have the same problem with my two c210 cameras on the latest firmware 1.3.9 with the latest version available under hacs from tapo control

Lorus-X commented 10 months ago

Hi, after the update today my Tapo H200 that was a hub for two C420 cameras went ti%$ up (meaning: „failed to setup, will retry”. This used to happen before with other updates in the past, but always re-adding the H200 did the trick. Now after removing the device, and restarting it I can add the H200 to HA, but I get the „failed to setup, will retry” all the time and it is showing no entities (so no cameras). Downgrading to previous version does not help. Would really appreciate the help.

Ashk0812 commented 10 months ago

I too have this error since the update.

cmdev100 commented 10 months ago

I have the same issue with FW 1.3.9. The log says: 2023-11-11 17:07:23.814 ERROR (MainThread) [custom_components.tapo_control] Unable to connect to Tapo: Cameras Control controller: Invalid authentication data

Not sure it's the correct log row though.

jtsarnas76 commented 10 months ago

Try to factory reset the camera and remove and add to ha. Does the problem still happen?

Did that, problem still there. Has to be a firmware issue.

ryann72 commented 10 months ago

Is it possible to downgrade the camera firmware?

joebar38 commented 10 months ago

Hello, Same problem here, a daily reconfiguration required... Not possible to downgrade the camera firmware

ryann72 commented 10 months ago

Hello, Same problem here, a daily reconfiguration required... Not possible to downgrade the camera firmware

when I want to validate the configuration I get the following error: Invalid RTSP stream authentication data. the camera still seems controllable but I no longer have the video in home assistant. how to recover the video stream?

JurajNyiri commented 10 months ago

@ryann72 you are overloading the camera. It supports max 2 concurrent streams. This topic is not for your issue and it is not integration issue at all.

JurajNyiri commented 10 months ago

@joebar38 Does this issue happen only on home assistant start or after some time running as well? It is important to properly describe the issue.

jtsarnas76 commented 10 months ago

On my part, it happens when home assistant starts

JurajNyiri commented 10 months ago

I will need a camera with ports 443 and 554 port forwarded along with all credentials so that I can debug this as I do not currently own camera with this firmware. Contact me via juraj.nyiri@gmail.com.

joebar38 commented 10 months ago

Ce problème se produit-il uniquement au démarrage de l’assistant domestique ou après un certain temps d’exécution ? Il est important de bien

@joebar38 Does this issue happen only on home assistant start or after some time running as well? It is important to properly describe the issue.

Sometimes AT start, but frequently some Time running as well

ryann72 commented 10 months ago

@ryann72 you are overloading the camera. It supports max 2 concurrent streams. This topic is not for your issue and it is not integration issue at all.

ok just that I have the two messages one of reconfiguration request am at the reboot of ha. and this one during configuration. but I recently integrated the cameras under frigate so I must have 3 streams 1 ha and 2 on frigate low and high resolution. I will try to modify this.

juliomatcom commented 10 months ago

Hello, Same problem here, a daily reconfiguration required... Not possible to downgrade the camera firmware

you can try factory reset

joebar38 commented 10 months ago

Hello, Same problem here, a daily reconfiguration required... Not possible to downgrade the camera firmware

you can try factory reset

I already tried. I also completely removed the integration and completely reconfigured, but same problem

juliomatcom commented 10 months ago

I just factory reset it but the same firmware 1.3.9 is still there, this error started today or yesterday for me.

Unable to connect to Tapo: Cameras Control controller: Invalid authentication data

It was working fine with the Firmware: 1.3.7 Build 230823 Rel.55314n(4555), we better leave the auto update disabled for sure.

cmdev100 commented 10 months ago

Make sure you update the "Tapo: cameras control" to the latest version 5.4.4. I had version 5.1 (manuall install, not by HACS). My camera with 1.3.9 works now.

joebar38 commented 10 months ago

Error this morning without reboot during night : [custom_components.tapo_control] Authentication failed while fetching Tapo resource status @JurajNyiri how do you send the logs you need?

Jimb62 commented 10 months ago

I have 4 camera C200 and 2 camera c310. With the last firware 1.3.7 no problem. Since the c200 camera update to 1.3.9 i also have problems and need to reconfigure and sometimes to disconnect the power off one or other camera. So i decide to wait for upgarding the firware of the c310 camera. Problems arrive sometimes when HA reboot or sometimes when it is runnnig since a few days. i don't detect a specific action for having the problem.

jtsarnas76 commented 10 months ago

Make sure you update the "Tapo: cameras control" to the latest version 5.4.4. I had version 5.1 (manuall install, not by HACS). My camera with 1.3.9 works now.

I was already on 5.4.4 version when the problem occurred with fw 1.3.9

Jimb62 commented 10 months ago

Sorry for my english. But if it can help i have an exemple. My camera is a C200. I just tonight update the firmware to 1.3.9 build 231019 Rel.29120n(4555).

In HA the camera was in problem in Tapo Camera Control. Need to reconfigure. Ok i reconfigure (Just validation of credentials).

The camera was ok in Tapo Camera control after that.

In HA, I tried to use the privacy mode for checking (swithc.nameofthecamera_privacy)

I got the error : Padding is incorrect. (Debug log below).

I electrically disconnect the camera.

Wait 20 seconds

Put the power on.

I tried again the privacy mode and it's OK no padding error.

Log Debug for the error :

2023-11-13 18:30:47.869 DEBUG (MainThread) [custom_components.tapo_control] Finished fetching Tapo resource status data in 0.281 seconds (success: True) 2023-11-13 18:30:48.047 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140155217776576] Padding is incorrect. Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 230, in handle_call_service await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service return await service.entity_service_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 876, in entity_service_call response_data = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call result = await task ^^^^^^^^^^ File "/config/custom_components/tapo_control/switch.py", line 419, in async_turn_off result = await self._hass.async_add_executor_job( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pytapo/init.py", line 838, in setPrivacyMode return self.executeFunction( ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pytapo/init.py", line 331, in executeFunction data = self.performRequest( ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pytapo/init.py", line 420, in performRequest responseJSON = json.loads(self.decryptResponse(encryptedResponse)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pytapo/init.py", line 367, in decryptResponse return unpad(pt, AES.block_size) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/Crypto/Util/Padding.py", line 92, in unpad raise ValueError("Padding is incorrect.") ValueError: Padding is incorrect. 2023-11-13 18:30:49.085 DEBUG (MainThread) [custom_components.tapo_control] Debouncer call ignored as shutdown has been requested.

JurajNyiri commented 10 months ago

I received the update today and my C200 v3.0 works flawlessly (even with 2 HA instances hitting it at the same time!) so far (few minutes :-) ).

I will keep it running and see if I notice anything suspicious.

Unless someone else can find the issue, as I said yesterday, I will need a camera with ports 443 and 554 port forwarded along with all credentials so that I can debug this as I do not currently own camera experiencing this issue. Contact me via juraj.nyiri@gmail.com.

Further comments "me too" providing no new information will be hidden.

FSHelgeland commented 10 months ago

I got the same problem. And I can not update my credentials. A HA restart fix the issue but for a little while running the fault appears again. I have written some lines in the discord channel as well, but it was not much response over there. Happy to see others have the same problem and there will hopefully be a fix soon.

JurajNyiri commented 10 months ago

Upgrade to 5.4.6.

Add following to configuration.yaml:

logger:
  logs:
    custom_components.tapo_control: debug

Post full log in case of an error.

If you see Incorrect pytapo version installed error on start, fix your environment.

joebar38 commented 10 months ago

Another error for me with 5.4.6 :

2023-11-16 19:13:04.354 DEBUG (SyncWorker_8) [custom_components.tapo_control] [pytapo] 200 2023-11-16 19:13:04.355 DEBUG (SyncWorker_8) [custom_components.tapo_control] [pytapo] {'error_code': -40413, 'result': {'data': {'code': -40401, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': 'REDACTED'}}} 2023-11-16 19:13:04.364 DEBUG (SyncWorker_2) [custom_components.tapo_control] [pytapo] 200 2023-11-16 19:13:04.364 DEBUG (SyncWorker_2) [custom_components.tapo_control] [pytapo] {'error_code': -40413, 'result': {'data': {'code': -40401, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': 'REDACTED'}}} 2023-11-16 19:13:04.367 DEBUG (SyncWorker_2) [custom_components.tapo_control] [pytapo] New request: 2023-11-16 19:13:04.368 DEBUG (SyncWorker_2) [custom_components.tapo_control] [pytapo] {'data': {'method': 'login', 'params': {'cnonce': 'REDACTED', 'encrypt_type': '3', 'digest_passwd': 'REDACTED', 'username': 'admin'}}, 'headers': {'Host': 'REDACTED', 'Referer': 'REDACTED', 'Accept': 'application/json', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Tapo CameraClient Android', 'Connection': 'close', 'requestByApp': 'true', 'Content-Type': 'application/json; charset=UTF-8', 'Seq': '873', 'Tapo_tag': 'REDACTED'}, 'verify': False} 2023-11-16 19:13:04.373 DEBUG (SyncWorker_10) [custom_components.tapo_control] [pytapo] 200 2023-11-16 19:13:04.373 DEBUG (SyncWorker_10) [custom_components.tapo_control] [pytapo] {'error_code': -40413, 'result': {'data': {'code': -40401, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': 'REDACTED'}}} 2023-11-16 19:13:04.406 DEBUG (MainThread) [custom_components.tapo_control] mediaSync 2023-11-16 19:13:04.502 DEBUG (SyncWorker_2) [custom_components.tapo_control] [pytapo] 200 2023-11-16 19:13:04.503 DEBUG (SyncWorker_2) [custom_components.tapo_control] [pytapo] {'error_code': -40413, 'result': {'data': {'code': -40401, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': ''}}} 2023-11-16 19:13:04.506 ERROR (MainThread) [custom_components.tapo_control] Authentication failed while fetching Tapo resource status data: Invalid authentication data 2023-11-16 19:13:04.507 DEBUG (MainThread) [custom_components.tapo_control] Finished fetching Tapo resource status data in 0.971 seconds (success: False) 2023-11-16 19:13:04.509 DEBUG (MainThread) [custom_components.tapo_control] [REAUTH][192.168.1.5] Showing config flow for reauth - stream. 2023-11-16 19:13:33.351 DEBUG (SyncWorker_4) [custom_components.tapo_control] [pytapo] Failure detecting hashing algorithm on getTag, reauthenticating.

MattJeanes commented 10 months ago

@JurajNyiri I have just emailed over to you a couple of log traces

reauth.log this is when the popup appeared in the notifications to re-auth. Home Assistant had been up for a few hours at this point.

reauth-2.log this is when I went through the re-auth flow which completed successfully. I did not change any settings just pressed submit twice.

Hopefully this helps, I have the full log files but they were massive so I tried scoping them down to roughly the interesting area, but let me know if you need anything more. Going to disable debug logging for now as it's writing a ton.

Note that restarting Home Assistant seems to temporarily mitigate the issue, as does re-authing, but it comes back.

No results in log for Incorrect pytapo version installed by the way

JurajNyiri commented 10 months ago

Thank you, I will need to add more logs into pytapo to find the reason of "Invalid authentication data" as from these logs it could be either https://github.com/JurajNyiri/pytapo/blob/main/pytapo/__init__.py#L408 or https://github.com/JurajNyiri/pytapo/blob/main/pytapo/__init__.py#L389 or even https://github.com/JurajNyiri/pytapo/blob/main/pytapo/__init__.py#L317 in theory.

JurajNyiri commented 10 months ago

Please download and install https://github.com/JurajNyiri/HomeAssistant-Tapo-Control/tree/pytapo_3.3.12 manually.

Add following to configuration.yaml:

logger:
  logs:
    custom_components.tapo_control: debug

Post full log in case of an error, now we will know what exactly happened during auth.

MattJeanes commented 10 months ago

I wasn't too sure how to install the custom version and I don't have direct file access so I applied the changes in this commit in the folder in custom_components and restarted Home Assistant (with the debug logging back on)

Hopefully that does the job but not too sure how HA installs python dependencies for custom components

JurajNyiri commented 10 months ago

That should do it! It installs from manifest.json*, if you did the change PYTAPO_REQUIRED_VERSION = "3.3.12" and it launched as expected (no error) you are running the correct version.

*Except some unsupported setups users are running where the pytapo version can be older and it does not install automatically... that is why I added the check recently.

MattJeanes commented 10 months ago

Yep I did that change as well, and it's up and currently working - so fingers crossed! I'll hang tight for it to request re-auth again and pop over the logs as before, might be tomorrow we'll see how fast it comes up.

silfax commented 10 months ago

I don't know if this info is of any use. C310 here, updated to 1.3.9, seeing the infamous 'Invalid authentication data' message and the suggestion to check with VLC. Did that and VLC is not able to display stream1 as well, although showing stream2 without any issues, with the same credentials.

MattJeanes commented 10 months ago

@JurajNyiri we've had two cameras (out of 3) fail overnight, I've sent over hopefully the relevant parts of the logs - let me know if you need anything else!

JurajNyiri commented 10 months ago

Thank you @MattJeanes ! It looks like it is failing with Incorrect device_confirm value, raising Exception.. Probably camera requiring additional refresh.

-40413: INVALID_NONCE -40401: SESSION_EXPIRED

I will put in additional refresh and lets see if it solves the issue.

JurajNyiri commented 10 months ago

@MattJeanes Please download and install https://github.com/JurajNyiri/HomeAssistant-Tapo-Control/tree/fix_453 manually. (Change pytapo references to PYTAPO_REQUIRED_VERSION = "3.3.15" and "pytapo==3.3.15" if applying the code manually) I added an internal retry in the pytapo so hopefully this will solve the issue.

Add following to configuration.yaml:

logger:
  logs:
    custom_components.tapo_control: debug

Please share logs in case of issue persisting or confirm if the issue is no longer present.

Edit: Added one more area for retry that I encountered during resolving unrelated issue, use 3.3.15.

MattJeanes commented 10 months ago

Applied pytapo 3.3.15 and rebooted now - I'll let you know! If it doesn't do it within 2 days then that's probably done it :)

MattJeanes commented 10 months ago

Oh no, it blew up already! I've sent over the full log since startup although I think I accidentally disabled the debug logging before I went through the re-auth flow again, some interesting errors from that too right at the bottom.

JurajNyiri commented 10 months ago

Config entry has already been setup! is something wrong with env. Make sure to completely remove the camera (make sure to check .storage folder as well for any tapo_control references and remove it there) and add again.

JurajNyiri commented 10 months ago

Fixed in https://github.com/JurajNyiri/HomeAssistant-Tapo-Control/releases/tag/5.4.8.

If not, we will reopen.

sandimartian commented 10 months ago

I still have the problem with version 5.4.8. After a certain amount of time, I have no stream from the camera (C200, hw 1.0, firmware 1.3.9). Problem can be solved only by rebooting the camera and reintroducing the credentials in HA.

JurajNyiri commented 10 months ago

This issue solves control issues, not stream. Read FAQ for stream issue.

MattJeanes commented 10 months ago

I'm on 5.4.8 now and still been getting issues and I've managed to grab some more debug level logs. I can see that there is 5.4.10 out now which I'm just updating to now, but I thought I'd send them over anyway in case they are useful to you. I'll let you know if I see anything further on 5.4.10.