[Custom Component] Tapo: Cameras Control

I had the same issue, there is a new motion entity, available in the integration, the current one is not available anymore.

1 Like

Hello, I have an issue with the add-on installation. The add-on is rejecting my cloud password even though I’ve confirmed it by logging out of the app to make sure it was correct. I disabled two-factor authentication to be sure, but it didn’t make any difference.
I updated the Tapo C210 yesterday.
What can I do?
Thanks

@JurajNyiri, it seems to be that Tapo is rolling out some new authentication method for all of their devices.

I see in the app, that I have an update for my Tapo P100 plug as well, and that says Enhanced device security.

The other Tapo integration for plugs has already multiple issues with similar content that you you linked above.

I would suggest to everybody using this integration to do not update any firmware to a newer one at the moment, until somebody finds out the new authentication method.

Otherwise I wouldn’t be surprised if this is an aftermatch of the previous CVE reported for the C210 cameras, which was fixed in the firmware 1.3.6.

2 Likes

If someone could get a link to the latest firmware that would be appreciated:

POST https://[IP_ADDRESS]/stok=[TOKEN]/ds

{
	"method": "get",
	"cloud_config": {
		"name": ["upgrade_info"]
	}
}

Version 5.4.0 :lock:

This release adds support for the new encryption introduced in the latest and upcoming firmware(s) for cameras. This was first seen in Feature Request: Support new authorization on the newest firmwares · Issue #436 · JurajNyiri/HomeAssistant-Tapo-Control · GitHub on C210 1.3.9 Build 231019 Rel. 13805n(4555). In these new firmwares a new strengthened communication was introduced, encrypting and decrypting the traffic on fly.
Integration now automatically chooses the highest possible encryption available in firmware of your camera.

Note

When you update camera to the new firmware with the new encryption, you will need to restart HA instance once.

Thank you

@bonvga for providing the logs of communication between app and camera
@GSzabados for help with debugging
@viprapp for help with testing

1 Like

After an update, my C200 camera stopped working.
I have the following error:

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:34:09 PM (7 occurrences)
Last logged: 8:38:49 PM

Unable to connect to Tapo: Cameras Control controller: Error: -1, Response: {"result": {"responses": [{"msg": "Check tapo tag failed", "error_code": -1}]}, "error_code": -1}

Can anyone help?

You beat me to it, i was looking at init_py :slight_smile: … however i have 4x C200 on 1.3.6, if you need 1 :neutral_face:

I downgrade Tapo Cameras Control to: 5.4.3 and now it works :slight_smile:

I’m getting a strange error in the logs, which I think is related to a camera.

I have an automation that turns on privacy mode for several cameras overnight then turns it back off again in the morning. The log errors are:

Logger: homeassistant.components.automation.all_lights_automation
Source: helpers/script.py:468
Integration: Automation (documentation, issues)
First occurred: 14 November 2023 at 22:33:01 (4 occurrences)
Last logged: 07:00:00

Night Lights and Reset: Choose at step 1: choice 2: Error executing script. Unexpected error for call_service at pos 15: Padding is incorrect.
Night Lights and Reset: Error executing script. Unexpected error for choose at pos 1: Padding is incorrect.
Night Lights and Reset: Choose at step 1: choice 3: Error executing script. Unexpected error for call_service at pos 5: Padding is incorrect.
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  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 409, in async_turn_on
    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.

The service call that is failing seems to be for one camera, but I have no idea what this

 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.

means or how it relates to the inability to call a service? I can manually turn on and off privacy mode for each camera, so I suspect it’s something to do with switching several cameras in succession.

Here are the relevant service calls:

         - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.guest_bedroom_camera_privacy
          - service: switch.turn_on
            data: {}
            target:
              entity_id:
                - switch.seans_room_camera_privacy
          - service: switch.turn_on
            data: {}
            target:
              entity_id:
                - switch.jamie_s_room_cam_privacy

I’m running v5.4.4 with core HA 2023.11.1, Supervisor 2023.11.3 and OS 11.1

Anyone able to shed some light please?

I had the same issue and followed Joca’s advice.
After the following steps it seems to work for now again:

  1. Downgrade to 5.4.3 and restart HA
  2. Delete the cameras and connect them again (simply reconfigure didn’t work for all of my cameras)
  3. Restart the cameras
    I will let you know in case the issue occurs again.

Maybe it would have been enough to just restart the cameras after the downgrade but since my ‘fleet’ isn’t too big I decided to kick them all out and properly connect again.

@P6Dave Do not downgrade. This is a very bad advise.

Upgrade to 5.4.5.

In case the issue persists:

Add following to configuration.yaml:

logger:
  logs:
    custom_components.tapo_control: debug

Post full log in case of an error into new issue on github.

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

2 Likes

I’m about to follow your instructions, thanks!

1 Like

In case of the issue persisting in 5.4.5, there are instructions in Upgraded Firmware 1.3.9 on Tapo C200 and get Check tapo tag failed when trying to connect · Issue #456 · JurajNyiri/HomeAssistant-Tapo-Control · GitHub what to do to help me fix the Tapo tag issue (not padding, that is already fixed in 5.4.5!)

It is possible 5.4.4 broke the auth that once worked on 5.4.3 by now - ironically - succeeding auth with 3rd party credentials instead of requiring cloud password but then failing since camera (no longer?) expects it. If that is the case, 5.4.5 will not work as well, and we need your help in the issue. Once the logs are there as I requested I can quickly fix this.

I tested it with version 5.4.5 and it works fine.
Thanks.

Thank you so much for the integration. Totally new to HA, and after some struggle I’m finally able to get motion detection working on my C320WS (running Firmware: 1.0.5 and version 5.4.4 of the integration).

What finally worked for me was to allow access to camera port 1024 and allow the camera to access port 8123 on HA (with HA and camera set up on different VLANs) as described in https://github.com/home-assistant/core/issues/91661

This was besides already allowing camera to access ports 443, 554, 2020 on HA mentioned in the README, and 8800 mentioned elsewhere. 8800 and 2020 may have been unnecessary in my case - will test again with those disabled.

Since upgrading to 5.4.5 I am now regularly getting a notification to reconfigure random cameras. The motion detection cell keeps becoming unavailable on random cameras too.

This is the error in the logs

This error originated from a custom integration.

Logger: custom_components.tapo_control
Source: custom_components/tapo_control/__init__.py:452
Integration: Tapo: Cameras Control (documentation, issues)
First occurred: 16 November 2023 at 13:06:12 (10074 occurrences)
Last logged: 21:30:36

Error communicating with Tapo Camera. Status code: 500
HTTPSConnectionPool(host='192.168.0.128', port=443): Max retries exceeded with url: /stok=c30897fbef3e17c37ae02af5f50efa58/ds (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f1b6594a610>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
'utf-8' codec can't decode bytes in position 2-3: invalid continuation byte

Logs are full of:

2023-11-17 01:30:14.935 ERROR (MainThread) [custom_components.tapo_control] 'utf-8' codec can't decode bytes in position 2-3: invalid continuation byte

Just seems to be one issue after another.

  1. Use the newest version, you are using 3 versions old release.
  2. Read the error message. Host is unreachable. Fix your network.
  3. There has been no changes to onvif motion events. Check your network.
  4. Post proper logs with proper description to github if you are still having issues.

With the information you provided, nobody can help you. Read How to help us help you - or How to ask a good question .

Just seems to be one issue after another.

TPLink released a new firmware introducing new encryption through completely proprietary, obfuscated and undocumented algorithms / apis. I added initial support for it within 1 day and spent 10s of hours since then fixing all the issues, even though my camera did not receive the update at that time. If you do not like the integration, do not use it. If you do and encounter issues and want to help, do so constructively or not at all. I, nor anyone else contributing and helping in issues is paid and we do this for free and completely voluntarily.

This literally popped up in my HA this morning :roll_eyes:

My network is fine. The cameras are always reachable in the Tapo app.

Yes, you’re right, I should use github more. Sorry for venting at you :slightly_frowning_face:

I really do like the integration, and believe me I appreciate how much time and effort goes into this. I’d love to help, but it’s way above my skillset, as it is for many other users. So we rely on people like you with the skills to create custom integrations such as these for us. However, you need to understand our frustrations when we spend hours creating scripts, automations and scenes that use your custom integration only to have them stop working for what we feel is something outwith our control.

You have actually helped thanks. But I will read this link again and endeavour to be a better question asker :laughing: