Thanks for the great Tapo integration. I love these cameras! Iāve been trying to automate switching on a pan/tilt preset facing the wall and Privacy mode on so everyone knows theyāre not being recorded when theyāre home. Itās been the only way I can install cameras and I understand why.
Iāve set up a template switch for each camera as follows:
- platform: template
switches:
cam_kitchen_privacy_mode:
value_template: "{{ is_state_attr('camera.kitchen_hd', 'privacy_mode', 'on') }}"
turn_on:
- service: tapo_control.ptz
data:
entity_id: camera.kitchen_hd
preset: 2
- service: tapo_control.set_privacy_mode
data:
entity_id: camera.kitchen_hd
privacy_mode: 'on'
turn_off:
- service: tapo_control.set_privacy_mode
data:
entity_id: camera.kitchen_hd
privacy_mode: 'off'
- service: tapo_control.ptz
data:
entity_id: camera.kitchen_hd
preset: 1
This works great. Now I wanted to automate setting them back on when we vacate the areas. (asleep or away). So I set an automation up to turn the switches on which works great apart from the rare possibility if one the cameras has been set to privacy mode manually through the app or a toggle on the camera preview. I get this error and the automation/script stops running:
[2981106832] Error: Privacy mode is ON, not able to execute Response:{"error_code": -64324}
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 215, in service_handler
await script_entity.async_turn_on(
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 320, in async_turn_on
await coro
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1026, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 242, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 250, in _async_step
await getattr(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 596, in _async_choose_step
await self._async_run_script(script)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 670, in _async_run_script
await self._async_run_long_action(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 419, in _async_run_long_action
long_task.result()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1026, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 242, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 250, in _async_step
await getattr(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 460, in _async_call_service_step
await self._async_run_long_action(service_task)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 419, in _async_run_long_action
long_task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 215, in service_handler
await script_entity.async_turn_on(
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 320, in async_turn_on
await coro
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1026, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 242, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 250, in _async_step
await getattr(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 596, in _async_choose_step
await self._async_run_script(script)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 670, in _async_run_script
await self._async_run_long_action(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 419, in _async_run_long_action
long_task.result()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1026, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 242, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 250, in _async_step
await getattr(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 457, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 593, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 664, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 630, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/template/switch.py", line 189, in async_turn_on
await self._on_script.async_run(context=self._context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1026, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 242, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 250, in _async_step
await getattr(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 457, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 576, in handle_service
await service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 593, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 664, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 630, in _handle_entity_call
await result
File "/config/custom_components/tapo_control/camera.py", line 260, in ptz
await self.hass.async_add_executor_job(
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.8/site-packages/pytapo/__init__.py", line 378, in setPreset
return self.performRequest(
File "/usr/local/lib/python3.8/site-packages/pytapo/__init__.py", line 104, in performRequest
raise Exception(
Exception: Error: Privacy mode is ON, not able to execute Response:{"error_code": -64324}
So Iāve just spent a few hours trying to get a script to work, which has been a bit of a nightmare but I think Iāve cracked it, pending some extended testing:
cameras_indoor_privacy_on:
alias: Cameras Indoor Privacy On
mode: parallel
sequence:
- choose:
- conditions:
- condition: state
entity_id: camera.kitchen_hd
attribute: privacy_mode
state: 'off'
sequence:
- service: switch.turn_on
entity_id: switch.cam_kitchen_privacy_mode
- delay: 10
- service: script.cameras_indoor_privacy_on
- conditions:
- condition: state
entity_id: camera.bedroom_hd
attribute: privacy_mode
state: 'off'
sequence:
- service: switch.turn_on
entity_id: switch.cam_bedroom_privacy_mode
- delay: 10
- service: script.cameras_indoor_privacy_on
- conditions:
- condition: state
entity_id: camera.lounge_hd
attribute: privacy_mode
state: 'off'
sequence:
- service: switch.turn_on
entity_id: switch.cam_lounge_privacy_mode
cameras_indoor_privacy_off:
alias: Cameras Indoor Privacy Off
mode: parallel
sequence:
- choose:
- conditions:
- condition: state
entity_id: camera.kitchen_hd
attribute: privacy_mode
state: 'on'
sequence:
- service: switch.turn_off
entity_id: switch.cam_kitchen_privacy_mode
- delay: 5
- service: script.cameras_indoor_privacy_off
- conditions:
- condition: state
entity_id: camera.bedroom_hd
attribute: privacy_mode
state: 'on'
sequence:
- service: switch.turn_off
entity_id: switch.cam_bedroom_privacy_mode
- delay: 5
- service: script.cameras_indoor_privacy_off
- conditions:
- condition: state
entity_id: camera.lounge_hd
attribute: privacy_mode
state: 'on'
sequence:
- service: switch.turn_off
entity_id: switch.cam_lounge_privacy_mode
I tried lots of different things but it seems the privacy on script was taking a while to realise the privacy mode attribute so kept failing. I had to introduce a long delay 5-10s to make sure it didnāt fail. Weirdly I didnāt have the same issue with the off script at 1s delay but I added 5s just to be on the safe side.
I also tried a wait for trigger but this didnāt work for one reason or another:
cameras_indoor_privacy_on:
alias: Cameras Indoor Privacy On
mode: parallel
sequence:
- choose:
- conditions:
- condition: state
entity_id: camera.kitchen_hd
attribute: privacy_mode
state: 'off'
sequence:
- service: switch.turn_on
entity_id: switch.cam_kitchen_privacy_mode
- wait_for_trigger:
- platform: state
entity_id: camera.kitchen_hd
attribute: privacy_mode
to: 'off'
- service: script.cameras_indoor_privacy_on
- conditions:
- condition: state
entity_id: camera.bedroom_hd
attribute: privacy_mode
state: 'off'
sequence:
- service: switch.turn_on
entity_id: switch.cam_bedroom_privacy_mode
- wait_for_trigger:
- platform: state
entity_id: camera.bedroom_hd
attribute: privacy_mode
to: 'off'
- service: script.cameras_indoor_privacy_on
- conditions:
- condition: state
entity_id: camera.lounge_hd
attribute: privacy_mode
state: 'off'
sequence:
- service: switch.turn_on
entity_id: switch.cam_lounge_privacy_mode
If anyone has any suggestions how I can improve this or maybe if this error can be fixed that would be great!