I recently got one of those cheap Tuya indoor cameras with PTZ functionality and was disappointed, that it didn’t work in Home Assistant (with official Tuya integration). This guide will show how to quickly add PTZ control from HA with the use of localtuya.
Prerequisites
- Working localtuya integration (will be needed as official integration doesn’t expose PTZ). Setup instructions can be found here.
- Working official Tuya integration (as localtuya doesn’t support camera streams)
localtuya setup
- open Tuya cloud dashboard, click on
Devices
→All devices
→Debug device
(make sure to select the camera) - in the opened page in the center part (
Control Device with Standard
section) findptz_control
andptz_stop
and take note of their values (In my caseptz_control
has a value of 3 andptz_stop
is ON (soTrue
). - Click
Send instruction
. - In localtuya add new device and look for DPs with values of
ptz_control
andptz_stop
. DPs should be listed in the same order as they were in theDebug device
menu underStandard Instruction Set
section (right side of the page). In my case I would be looking for the value ofTrue
followed by3
. - Once you find those add them. Make sure the DP for
ptz_control
has the entity typeselect
(with selection reflecting what was visible in Tuya dashboard, in my case0,1,2,3,4,5,6,7
)
You should now have something similar to this:
Making it more friendly to use
Right now you can control your camera by selecting a value from PTZ control entity and toggling PTZ stop, when you reach the desired position. It’s nice, but not useful. Moving directions are as follows (at least for me):
0
or 1
- up
4
or 5
- down
6
or 7
- left
2
or 3
- right
Next we’ll add a script, which we will be able to call to move the camera in a more human friendly fashion. Just copy the code from below and paste it into new script. (Home Assistant really needs a way to share scripts, just like blueprints)
YAML:
alias: Tuya PTZ
icon: mdi:camera-control
mode: single
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ direction == \"up\" }}"
sequence:
- service: select.select_option
data:
option: "0"
target:
entity_id: "{{ ptz_control_entity }}"
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: "{{ duration | default(200) }}"
- service: switch.toggle
data: {}
target:
entity_id: "{{ ptz_stop_entity }}"
- conditions:
- condition: template
value_template: "{{ direction == \"down\" }}"
sequence:
- service: select.select_option
data:
option: "4"
target:
entity_id: "{{ ptz_control_entity }}"
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: "{{ duration | default(200) }}"
- service: switch.toggle
data: {}
target:
entity_id: "{{ ptz_stop_entity }}"
- conditions:
- condition: template
value_template: "{{ direction == \"left\" }}"
sequence:
- service: select.select_option
data:
option: "6"
target:
entity_id: "{{ ptz_control_entity }}"
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: "{{ duration | default(200) }}"
- service: switch.toggle
data: {}
target:
entity_id: "{{ ptz_stop_entity }}"
- conditions:
- condition: template
value_template: "{{ direction == \"right\" }}"
sequence:
- service: select.select_option
data:
option: "2"
target:
entity_id: "{{ ptz_control_entity }}"
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: "{{ duration | default(200) }}"
- service: switch.toggle
data: {}
target:
entity_id: "{{ ptz_stop_entity }}"
Now verify, that it’s working by calling this service (don’t forget to change the entities, duration is specified in ms
):
service: script.tuya_ptz
data:
ptz_control_entity: select.ptz_control
ptz_stop_entity: switch.ptz_stop
direction: up
duration: 200
And that’s all!
Now you should be able to control the camera from HA without tuya app.
As a bonus here’s a quick card with controls included:
type: picture-glance
camera_view: auto
camera_image: camera.kamera_tuya
entities:
- entity: select.ptz_control
icon: mdi:arrow-up
tap_action:
action: call-service
service: script.tuya_ptz
service_data:
ptz_control_entity: select.ptz_control
ptz_stop_entity: switch.ptz_stop
direction: up
- entity: select.ptz_control
icon: mdi:arrow-down
tap_action:
action: call-service
service: script.tuya_ptz
service_data:
ptz_control_entity: select.ptz_control
ptz_stop_entity: switch.ptz_stop
direction: down
- entity: select.ptz_control
icon: mdi:arrow-left
tap_action:
action: call-service
service: script.tuya_ptz
service_data:
ptz_control_entity: select.ptz_control
ptz_stop_entity: switch.ptz_stop
direction: left
- entity: select.ptz_control
icon: mdi:arrow-right
tap_action:
action: call-service
service: script.tuya_ptz
service_data:
ptz_control_entity: select.ptz_control
ptz_stop_entity: switch.ptz_stop
direction: right