iTranslated by AI
[Cat Monitoring System] 3. PTZ (Pan/Tilt/Zoom) Control for Tapo C210
Obtaining Video from Tapo C210
Regarding the video acquisition for the Tapo C210, I was able to implement it quickly by referring to the article Creating a Surveillance Camera Viewer with PySimpleGui.
[Important] Update on January 30, 2026:
It appears that in Tapo firmware version 1.5.x (?), PTZ operations via the ONVIF standard have been discontinued.
As a result, PTZ operations cannot be performed using the method described in this article.
Even if you perform a factory reset by holding down the RESET button on the device to return to the old factory firmware, the firmware will automatically update when you re-link the camera with the app, making it impossible to stay on an older version.
This method only works if you are using a product with firmware older than 1.5.x and have disabled automatic updates.
Alternatively, it seems we can only hope that ONVIF-standard PTZ operations will be restored in the future.
Pan/Tilt Operations
Types of PTZ Operations
First, the ONVIF standard provides three methods for PTZ (Pan/Tilt/Zoom) operations:
- ContinuousMove (Rotation for a specified duration)
- AbsoluteMove (Rotation to specific coordinates)
- RelativeMove (Rotation by a specific displacement relative to current position)
The use cases for each are as follows:
- ContinuousMove: Specify the direction of movement. Movement continues until the initially specified time elapses, a stop command is received, or the boundary is reached.
- AbsoluteMove: Specify the target PTZ coordinates.
- RelativeMove: Specify the amount of movement based on the current coordinates.
Since my cat is often on the cat tower or hammock during the day and on the sofa at late night, I use AbsoluteMove when I want to move the camera to those fixed positions.
Also, since the camera automatically follows the cat (or people) if "Motion Tracking" is turned ON in the Tapo app, I use RelativeMove for movements other than moving to fixed positions.
I have no plans to use ContinuousMove.
Implementation
For this part, I also referred to the article Creating a Surveillance Camera Viewer with PySimpleGui.
ContinuousMove
First, I copy-pasted the code from the reference site to see if it would work.
As mentioned in the comments by others, ContinuousMove resulted in an error on the C210.
However, since I didn't plan on using it anyway, I pulled myself together and moved on to AbsoluteMove.
AbsoluteMove
I also copy-pasted the code for this from the reference site and checked if it worked.
However, a "Bad Request" was returned at the line marked with ★ below.
if is_streaming:
oreq = onvif_request.absolute_move(cur_x, cur_y)
req = urllib.request.Request(url, data=oreq.encode(), method='POST', headers=headers)
try:
with urllib.request.urlopen(req) as response: # ★
pass
When I caught the detailed exception, it was "HTTP Error 400: Bad Request".
Since 400 is a status code indicating that there was some error or problem with the client's request and the process could not be completed, I assumed it meant that the arguments passed to urllib.request.Request() or the content of the arguments were inappropriate.
Since printing the url and headers didn't show any obvious problems, I suspected the value being passed to data was wrong. If that were the case, it would mean the entire onvifreq.py was suspicious.
I spent a whole day searching for ONVIF PTZ standards, giving up and trying other Python libraries, and looking through various forums, but couldn't solve it.
In the end, while using a software called "ONVIF Device Manager", I noticed that the coordinates passed to AbsoluteMove are -1 to 1 for x and y, and 0 to 1 for zoom.
I changed the following:
# Pan/Tilt parameters
X_MIN, X_MAX, X_STP = -170, 170, 10
Y_MIN, Y_MAX, Y_STP = -30, 30, 5
to this, and it worked:
# Pan/Tilt parameters (Min coordinate, Max coordinate, movement amount)
X_MIN, X_MAX, X_STP = -1, 1, 0.1
Y_MIN, Y_MAX, Y_STP = -1, 1, 0.1
RelativeMove
I thought I could just add a function for RelativeMove to onvifreq.py, so I searched for information in the ONVIF PTZ Service Spec.
I thought, "Maybe I just need to change the URL passed to space= for RelativeMove?" and it turned out I was mostly correct.
I added the following below absolute_move():
def relative_move(self, x, y):
command = """
<RelativeMove xmlns="http://www.onvif.org/ver20/ptz/wsdl">
<ProfileToken>profile_1</ProfileToken>
<Translation>
<PanTilt x="{x}" y="{y}" xmlns="http://www.onvif.org/ver10/schema" \
space="http://www.onvif.org/ver10/tptz/PanTiltSpaces/TranslationGenericSpace"/>
<Zoom x="0" xmlns="http://www.onvif.org/ver10/schema" \
space="http://www.onvif.org/ver10/tptz/ZoomSpaces/TranslationGenericSpace"/>
</Translation>
</RelativeMove>
"""
return self.request(self.username, self.password, command.format(x=x, y=y))
When I added a function for ContinuousMove as follows, it also seemed to work appropriately. I only confirmed that it moves by passing arguments intended for RelativeMove. Normally, functions to stop the movement or parameters to specify the duration would be necessary. Since I don't plan to use ContinuousMove this time, I haven't confirmed those details.
def continuous_move(self, x, y):
command = """
<ContinuousMove xmlns="http://www.onvif.org/ver20/ptz/wsdl">
<ProfileToken>profile_1</ProfileToken>
<Velocity>
<PanTilt x="{x}" y="{y}" xmlns="http://www.onvif.org/ver10/schema" \
space="http://www.onvif.org/ver10/tptz/PanTiltSpaces/VelocityGenericSpace"/>
<Zoom x="0" xmlns="http://www.onvif.org/ver10/schema" \
space="http://www.onvif.org/ver10/tptz/ZoomSpaces/VelocityGenericSpace"/>
</Velocity>
</ContinuousMove>
"""
return self.request(self.username, self.password, command.format(x=x, y=y))
Modifying the Viewer
Since the x and y values passed as movement amounts differ between AbsoluteMove and RelativeMove, I modified the viewer as follows.
Showing only the modified parts
# Pan/Tilt parameters. Movement amount only. Range should be 0 to 1.
X_STP = 0.1
Y_STP = 0.1
# Fixed position to move to when the circle button is pressed. Specify absolute position. Range should be -1 to 1.
X_DEFALUT = -0.4
Y_DEFALUT = 0.2
elif "-pt_" in event or inited_ptz:
if is_streaming:
# Move to the fixed position when the circle button is pressed
if "-pt_center-" in event:
x = X_DEFALUT
y = Y_DEFALUT
# For absolute position specification
# Add a minus sign if "Invert Image" is turned ON in the Tapo app.
oreq = onvif_request.absolute_move(-x, -y)
else:
if "right" in event:
x = X_STP
elif "left" in event:
x = - X_STP
else:
x = 0
if "top" in event:
y = Y_STP
elif "btm" in event:
y = - Y_STP
else:
y = 0
# For relative position specification
# Do NOT add a minus sign if "Invert Image" is turned ON in the Tapo app.
oreq = onvif_request.relative_move(x, y)
req = urllib.request.Request(url, data=oreq.encode(), method='POST', headers=headers)
try:
with urllib.request.urlopen(req) as response:
pass
except urllib.error.URLError as e:
if e.reason == 'Bad Request':
print('Out of camera range')
else:
print(e)
inited_ptz = False
Positive and Negative Movement Values for Pan/Tilt
Regarding whether to add a minus sign to the x and y values passed to absolute_move() and relative_move(), the following seems to be the best approach:
If "Invert Image" is turned ON in the Tapo app:
- Add a minus sign for
absolute_move(). - Do NOT add a minus sign for
relative_move(). - Do NOT add a minus sign for
continuous_move().
If "Invert Image" is turned OFF in the Tapo app:
- Do NOT add a minus sign for
absolute_move(). - Add a minus sign for
relative_move(). - Add a minus sign for
continuous_move().
Since I have the camera mounted upside down on the ceiling, I have "Invert Image" turned ON.
Implementing Zoom Operation (Unsuccessful)
This was not in the original article, but I expected that I could implement the Zoom function simply by adding a z parameter to absolute_move(), relative_move(), and continuous_move().
The range for z should be 0 to 1. Providing a value outside this range should return a "Bad Request"... but it didn't work out as expected.
Modification Details
I added z in three places: the argument, <Zoom x="">, and the command passed to the request() function.
def relative_move(self, x, y, z):
command = """
<RelativeMove xmlns="http://www.onvif.org/ver20/ptz/wsdl">
<ProfileToken>profile_1</ProfileToken>
<Translation>
<PanTilt x="{x}" y="{y}" xmlns="http://www.onvif.org/ver10/schema" \
space="http://www.onvif.org/ver10/tptz/PanTiltSpaces/TranslationGenericSpace"/>
<Zoom x="{z}" xmlns="http://www.onvif.org/ver10/schema" \
space="http://www.onvif.org/ver10/tptz/ZoomSpaces/TranslationGenericSpace"/>
</Translation>
</RelativeMove>
"""
return self.request(self.username, self.password, command.format(x=x, y=y, z=z))
# Pan/Tilt parameters. X, Y, Z should be in the range of 0 to 1.
X_STP = 0.1
Y_STP = 0.1
Z_STP = 0.1
# Initial position to move to when the circle button is pressed. X, Y range is -1 to 1, Z range is 0 to 1.
X_DEFALUT = -0.4
Y_DEFALUT = 0.2
Z_DEFALUT = 0
elif "-pt_" in event or inited_ptz:
#print(event, "x:", x, "y:", y)
if is_streaming:
# Move to the fixed position when the circle button is pressed
if "-pt_center-" in event:
x = X_DEFALUT
y = Y_DEFALUT
z = Z_DEFALUT
# For absolute position specification
# Add a minus sign to x and y if "Invert Image" is turned ON in the Tapo app.
oreq = onvif_request.absolute_move(-x, -y, z)
else:
if "right" in event:
x = X_STP
elif "left" in event:
x = - X_STP
else:
x = 0
if "top" in event:
y = Y_STP
elif "btm" in event:
y = - Y_STP
else:
y = 0
if "-pt_zoomin-" in event:
z = Z_STP
elif "-pt_zoomout-" in event:
z = -Z_STP
else:
z = 0
# For relative position specification
# Do NOT add a minus sign to x and y if "Invert Image" is turned ON in the Tapo app.
oreq = onvif_request.relative_move(x, y, z)
req = urllib.request.Request(url, data=oreq.encode(), method='POST', headers=headers)
try:
with urllib.request.urlopen(req) as response:
pass
except urllib.error.URLError as e:
if e.reason == 'Bad Request':
print('Out of camera range')
else:
print(e.reason)
print(e)
inited_ptz = False
Test Results
| No. | Move | Movement Amount | Result |
|---|---|---|---|
| 1 | relative_move() | z=0, y=0, z=0 | Bad Request returned |
| 2 | relative_move() | z=0, y=0, z=0.1 | Bad Request returned |
| 3 | relative_move() | z=0, y=0, z=0.5 | Bad Request returned |
| 4 | relative_move() | z=0, y=0, z=0.9 | Bad Request returned |
| 5 | relative_move() | z=0, y=0, z=1 | Bad Request returned |
| 6 | relative_move() | z=0.1, y=0.1, z=0.5 | Pan/Tilt works normally, but no Zoom In/Out |
| 7 | relative_move() | z=-0.1, y=-0.1, z=0.5 | Pan/Tilt works normally, but no Zoom In/Out |
| 8 | relative_move() | z=0.1, y=0.1, z=-0.5 | Pan/Tilt works normally, but no Zoom In/Out |
| 9 | relative_move() | z=-0.1, y=-0.1, z=-0.5 | Pan/Tilt works normally, but no Zoom In/Out |
| 10 | absolute_move() | z=-0.5, y=0.2, z=1 | Pan/Tilt works normally, but no Zoom In/Out |
| 11 | absolute_move() | z=-0.5, y=0.2, z=0 | Pan/Tilt works normally, but no Zoom In/Out |
| 12 | absolute_move() | z=-0.5, y=0.2, z=0.5 | Pan/Tilt works normally, but no Zoom In/Out |
In summary:
- When only
zis changed, a Bad Request is returned. - When values other than
zare also changed, Pan/Tilt operations occur. If an out-of-range value is specified for Pan/Tilt, a Bad Request is returned.
Even when using the software "ONVIF Device Manager", the Zoom section was inactive (fixed at 0).
Looking at the manufacturer's product information, the C210 I purchased has no mention of "Zoom," whereas the C320WS explicitly states it can zoom up to 8x. Furthermore, according to reviews on Kakaku.com, the 8x zoom on the C320WS is not a hardware zoom function of the camera itself but rather an enlargement function within the Tapo app.
I completely overlooked this before purchasing.
If you want to perform Zoom In/Out, it seems you need to implement it as a feature of the viewer rather than relying on the camera's hardware functions.
Discussion