Add PTZ functionality to the camera platform

Could you share your YAML code for the PTZ camera control buttons (UP / DOWN / LEFT / RIGHT)? Thanks!

Hi,
I have my own home made solution for that. It’s quite simple:

First a bit of API to trigger the PTZ

rest_command :
  ptz_goto:
    url: !secret camera_ptz_goto
  
  ptz_manual:
    url: !secret camera_ptz_manual

Then a couple of automation with an input_number representing the ptz view number

automation:
  - alias: ptz_auto
    initial_state: true
    trigger:
      platform: state
      entity_id: input_number.ptz
    action:
      service: rest_command.ptz_goto
      data_template:
        preset: "{{ states('input_number.ptz') | int }}"

Then lots of switches to control manually or using PTZ views

switch :
  - platform: template
    switches:
      camera_up:
        value_template: "on"
        turn_on:
          service: rest_command.ptz_manual
          data_template:
            command: up
        turn_off:
          service: rest_command.ptz_manual
          data_template:
            command: up
  - platform: template
    switches:
      camera_down:
        value_template: "on"
        turn_on:
          service: rest_command.ptz_manual
          data_template:
            command: down
        turn_off:
          service: rest_command.ptz_manual
          data_template:
            command: down
  - platform: template
    switches:
      camera_left:
        value_template: "on"
        turn_on:
          service: rest_command.ptz_manual
          data_template:
            command: right
        turn_off:
          service: rest_command.ptz_manual
          data_template:
            command: right
  - platform: template
    switches:
      camera_right:
        value_template: "on"
        turn_on:
          service: rest_command.ptz_manual
          data_template:
            command: left
        turn_off:
          service: rest_command.ptz_manual
          data_template:
            command: left
  - platform: template
    switches:
      camera_diag:
        value_template: "{{ (states('input_number.ptz') | int) == 0}}"
        turn_on:
          service: input_number.set_value
          data_template:
            entity_id: input_number.ptz
            value: 0
        turn_off:
          service: input_number.set_value
          data_template:
            entity_id: input_number.ptz
            value: 0
  - platform: template
    switches:
      camera_desk:
        value_template: "{{ (states('input_number.ptz') | int) == 1}}"
        turn_on:
          service: input_number.set_value
          data_template:
            entity_id: input_number.ptz
            value: 1
        turn_off:
          service: input_number.set_value
          data_template:
            entity_id: input_number.ptz
            value: 0
  - platform: template
    switches:
      camera_sofa:
        value_template: "{{ (states('input_number.ptz') | int) == 2}}"
        turn_on:
          service: input_number.set_value
          data_template:
            entity_id: input_number.ptz
            value: 2
        turn_off:
          service: input_number.set_value
          data_template:
            entity_id: input_number.ptz
            value: 0
  - platform: template
    switches:
      camera_bed:
        value_template: "{{ (states('input_number.ptz') | int) == 3}}"
        turn_on:
          service: input_number.set_value
          data_template:
            entity_id: input_number.ptz
            value: 3
        turn_off:
          service: input_number.set_value
          data_template:
            entity_id: input_number.ptz
            value: 0

The result using picture-glance :
Capture%20d%E2%80%99%C3%A9cran%20de%202019-02-08%2012-44-26 Capture%20d%E2%80%99%C3%A9cran%20de%202019-02-08%2012-48-53

Hope it helps :smile:

3 Likes

I will try something like this, thanks for sharing.

Just to confirm, is the image updated in real time? I mean, when I hit the icon to move the camera, the image keeps still until I click to view the stream, right?

You’ll need two web browser for doing that. When you trigger the PTZ it will make the camera rotate but the camera card is a picture card with low refresh rate so it will take time. If you access the stream by clicking on the picture on another page it will update in real time or close to it.

hi can you please share the picture glance card code?

where did you go for the passwords??

For example for my Foscam camera:
http://192.168.15.21:88/cgi-bin/CGIProxy.fcgi?cmd=ptzGotoPresetPoint&name=New&usr=NAME&pwd=PASS
http://192.168.15.21:88/cgi-bin/CGIProxy.fcgi?cmd=ptzGotoPresetPoint&name=Koridor&usr=NAME&pwd=PASS
Names of preset positions are configured in the camera itself.

I have the escam qf001I can not know what is the link for ptz to work.
Some help?

I already find the commands, how do I get them working in HASSIO?

command=ptz_req&req=start&param=directionleft&channel=1&stream=0
command=ptz_req&req=start&param=directionright&channel=1&stream=0
command=ptz_req&req=start&param=directiondown&channel=1&stream=1
command=ptz_req&req=start&param=directionup&channel=1&stream=1

Does anyone know the correct settings for reolink cameras?

which reolink camera do you have?

It’s reolink C2-pro

I have a RLC-23 and I saved preset locations to point at in the camera web interface and setup a restful command to that tell the camera to point at the saved preset locations.

that is exactly what I need. Would you mind sharing those rest commands?

Ok, I figured it out.
For those who want to know how:

  • Open the admin page of your camera. Mine was on http://192.168.0.121
  • Go to the PTZ section and see your pre-configured locations
  • Open your debug tools of your browser (on mac, F12) and select the network tab
  • Execute the command to move to default location
  • Take a look at the network tab to see which url was called
  • Enjoy

One example:
http://192.168.0.121/cgi-bin/api.cgi?cmd=PtzCtrl&token=xxxxxxx

Glad you figured it.

If you are on use Chrome Ctrl+Shift+i to bring up the network panel.

rest_command:
  poolcamptz1:
    url: http://192.168.1.128/cgi-bin/api.cgi?cmd=PtzCtrl&token=xxxxxxxxxxxx
    method: POST       
    payload: '[{"cmd":"PtzCtrl","action":0,"param":{"channel":0,"op":"ToPos","speed":32,"id":1}}]'

"id"1 refers to saved camera position 1

1 Like

Yes, that’s exactly how I ended doing it, thank you. The hardest par was to get a token hourly inside the hassio way of doing things.

How did you mange that?

I wrote a detailed description here:

1 Like

Where you can check for the reolink

1 Like