本文主要是介绍让HomeAssistant可以PTZ控制大华摄像头云台,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在网上遨游了很久都没答案,后来受到瀚思一篇关于海康的摄像头实现PTZ控制的启发,去找了下大华的摄像头API,并且实验成功了,以下只说控制重点,HA的控件添加什么的就不提了。

示例:
比如向上移动,用以下命令,IP 192.168.1.61,用户名admin,密码12345,都要修改成你自己的设置,arg2=1是移动速度:
http://admin:12345@192.168.1.61/cgi-bin/ptz.cgi?action=start&channel=0&code=Up&arg1=0&arg2=1&arg3=0
执行后,云台就向上以最慢的速度运动了,并返回ok,如果格式错误就会显示error
想停下,就必须把start替换成stop:
http://admin:12345@192.168.1.61/cgi-bin/ptz.cgi?action=stop&channel=0&code=Down&arg1=0&arg2=1&arg3=0
执行后,就停止了
然后按照这个方法做成卡片按键或者自动化就好了~具体规则见下面
大华的PTZ控制命令规则:
http://<ip>/cgi-bin/ptz.cgi?action=[action]&channel=[ch]&code=[code]&arg1=[argstr]&arg2=[argstr]&arg3=[argstr]
action定义:start和stop
ch定义:默认0就好了
Code和argstr见下表(区分大小写)
| Code | Code description | arg1 | arg2 | arg3 |
| Up | Tile up | 0 | Vertical speed, range is [1-8] | 0 |
| Down | Tile down | 0 | Vertical speed, range is [1-8] | 0 |
| Left | Pan left | 0 | Vertical speed, range is [1-8] | 0 |
| Right | Pan right | 0 | Vertical speed, range is [1-8] | 0 |
| ZoomWide | Zoom out | 0 | multiple | 0 |
| ZoomTele | Zoom in | 0 | multiple | 0 |
| FocusNear | Focus near | 0 | multiple | 0 |
| FocusFar | Focus far | 0 | multiple | 0 |
| IrisLarge | Aperture larger | 0 | multiple | 0 |
| IrisSmall | Aperture smaller | 0 | multiple | 0 |
| GotoPreset | Go to PTZ preset point | 0 | Preset point number | 0 |
| SetPreset | Set PTZ preset point | 0 | Preset point number | 0 |
| ClearPreset | Clear PTZ preset point | 0 | Preset point number | 0 |
| LampWaterClear | 1: open | 0 | 0 | |
| 2: close | ||||
| StartTour | Start PTZ tour | Tour path number | 0 | 1: start |
| 2: automatically | ||||
| 3: stop | ||||
| LeftUp | Pan left and tile up | Vertical speed, range is [1-8] | Horizontal speed, | 0 |
| range is [1-8] | ||||
| RightUp | Pan right and tile up | Vertical speed, range is [1-8] | Horizontal speed, | 0 |
| range is [1-8] | ||||
| LeftDown | Pan left and tile down | Vertical speed, range is [1-8] | Horizontal speed, | 0 |
| range is [1-8] | ||||
| RightDown | Pan right and tile down | Vertical speed, range is [1-8] | Horizontal speed, | 0 |
| range is [1-8] | ||||
| AddTour | Add preset point to tour path | Tour path number | Preset point number | 0 |
| DelTour | Delete preset point from tour path | Tour path number | Preset point number | 0 |
| ClearTour | Clear tour path | Tour path number | 0 | 0 |
| AutoPanOn | Start pan rotate | 0 | 0 | 0 |
| AutoPanOff | Stop pan rotate | 0 | 0 | 0 |
| SetLeftLimit | Set left limit. | 0 | 0 | 0 |
| SetRightLimit | Set right limit. | 0 | 0 | 0 |
| AutoScanOn | Start auto scan. | 0 | 0 | 0 |
| AutoScanOff | Stop auto scan. | 0 | 0 | 0 |
| SetPatternBegin | Begin pattern path set. | Pattern number | 0 | 0 |
| SetPatternEnd | End pattern path set. | Pattern number | 0 | 0 |
| StartPattern | Run pattern path | Pattern number | 0 | 0 |
| StopPattern | Stop pattern path | Pattern number | 0 | 0 |
| ClearPattern | Clear pattern path | Pattern number | 0 | 0 |
| AlarmSearch | Search alarm. | 0 | 0 | 0 |
| Position | Go to position | Horizontal position | Vertical position | Zoom change |
| AuxOn | Auxiliary function on, auxiliary function is defined in product definition document. | 0 | 0 | 0 |
| AuxOff | Auxiliary function off | 0 | 0 | 0 |
| Menu | 0 | 0 | 0 | |
| Exit | 0 | 0 | 0 | |
| Enter | 0 | 0 | 0 | |
| Esc | 0 | 0 | 0 | |
| MenuUp | 0 | 0 | 0 | |
| MenuDown | 0 | 0 | 0 | |
| MenuLeft | 0 | 0 | 0 | |
| MenuRight | 0 | 0 | 0 | |
| Reset | Restore default configuration. | 0 | 0 | 0 |
| SetPresetName | Preset point number (1 byte) | Preset point title. | 0 | |
| AlarmPtz | Alarm linked PTZ. | External alarm input channel. | Link type: | Argument of link type: Link type = 1, |
| 1: go to preset point 2: auto scan | this is preset point | |||
| 3: tour | number | |||
| Link type = 2, | ||||
| this is auto scan path Link type = 3, | ||||
| this is tour path | ||||
| LightController | Control the light on/off. | Address of light | Light number | switch |
| controller | ||||
| PositionABS | Go to ABS position | Horizontal angle: | Vertical angle :0°-90° | Zoom in mutiple |
| 0°-360° | ||||
| PositionReset | Use current direction as reference. | 0 | 0 | 0 |
| UpTele | up + TELE | Speed [1-8] | 0 | 0 |
| DownTele | down + TELE | Speed [1-8] | 0 | 0 |
| LeftTele | left + TELE | Speed [1-8] | 0 | 0 |
| RightTele | right + TELE | Speed [1-8] | 0 | 0 |
| LeftUpTele | leftup + TELE | Speed [1-8] | 0 | 0 |
| LeftDownTele | leftdown + TELE | Speed [1-8] | 0 | 0 |
| RigjtUpTele | rightup + TELE | Speed [1-8] | 0 | 0 |
| RightDownTele | rightdown + TELE | Speed [1-8] | 0 | 0 |
| UpWide | up + WIDE | Speed [1-8] | 0 | 0 |
| DownWide | down + WIDE | Speed [1-8] | 0 | 0 |
| LeftWide | left + WIDE | Speed [1-8] | 0 | 0 |
| RightWide | right + WIDE | Speed [1-8] | 0 | 0 |
| LeftUpWide | leftup + WIDE | Speed [1-8] | 0 | 0 |
| LeftDownWide | leftdown + WIDE | Speed [1-8] | 0 | 0 |
| RightUpWide | rightup + WIDE | Speed [1-8] | 0 | 0 |
| RightDownWide | rightdown + WIDE | Speed [1-8] | 0 | 0 |
这篇关于让HomeAssistant可以PTZ控制大华摄像头云台的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!