Add PTZ functionality to the camera platform

I think it would be nice to have integrated controls for PTZ and motion alarms in the camera platform.

It could be done in the same way as the media player platform where each component sets it’s own capabilities and the UI updates accordingly.

It would make configuration of automation’s a lot easier.

The examples in the docs for foscam is not accurate. It’s a bit more complicated to set up motion detection alarms.

You need to supply the whole config for the motion-detection alarms, schemas, areas to trigger and other settings in the same curl call, otherwise all settings would be cleared when you toggle the switch. Its not that simple for a novice user to figure out.

There is also a lot of nice python library’s for controlling Foscam cameras, if we just have the infrastructure for it, it would be a small task to implement! The same probably goes for other cameras as well.

3 Likes

I need this too. At least a couple of buttons we can control the functions for

1 Like

Amcrest already supporst it, however we need to implement it on the frontend. At my home, I do like this:

image

And then I have the configuration below:

#shell_commands.yaml
amcrestcam2_motion_on:  /home/hass/.virtualenvs/hass_venv/bin/amcrest-cli --camera amcrestcam2 --motion-detection true
amcrestcam2_motion_off: /home/hass/.virtualenvs/hass_venv/bin/amcrest-cli --camera amcrestcam2 --motion-detection false
amcrestcam2_goto_preset_crib: /home/hass/.virtualenvs/hass_venv/bin/amcrest-cli --camera amcrestcam2 --ptz-goto-preset 0 1
amcrestcam2_goto_preset_crib_zoom: /home/hass/.virtualenvs/hass_venv/bin/amcrest-cli --camera amcrestcam2 --ptz-goto-preset 0 4
amcrestcam2_goto_preset_roomview: /home/hass/.virtualenvs/hass_venv/bin/amcrest-cli --camera amcrestcam2 --ptz-goto-preset 0 2
amcrestcam2_goto_preset_nursechair: /home/hass/.virtualenvs/hass_venv/bin/amcrest-cli --camera amcrestcam2 --ptz-goto-preset 0 3
amcrestcam2_goto_preset_mattress_zoom: /home/hass/.virtualenvs/hass_venv/bin/amcrest-cli --camera amcrestcam2 --ptz-goto-preset 0 5

Hi @tchellomello

I’ve been trying to control the preset position of my amcrest cams for a few days using other commands with no sucess and have just come across this post.

Are you running hassbian? I am trying to figure out how to make it work using a AIO setup. This is what I have tried as a shell command so far but it isn’t working.

amcrest_test1: /srv/homeassistant/homeassistant_venv/bin/amcrest-cli --camera black --ptz-goto-preset 0 1

is where the virtual environment is located in the AIO set up and black is the name of my camera.

Any ideas?

Edit: black is what its named via amcrest, cam_black is how its refered to in home assistant

I’ve also tried these with no luck

amcrest_test3: /home/hass/.virtualenvs/hass_venv/bin/amcrest-cli --camera black --ptz-goto-preset 0 1
amcrest_test4: /home/homeassistant/.virtualenvs/homeassistant_venv/bin/amcrest-cli --camera black --ptz-goto-preset 0 1
amcrest_test5: /home/homeassistant/homeassistant_venv/bin/amcrest-cli --camera black --ptz-goto-preset 0 1
amcrest_test6: /srv/homeassistant/homeassistant_venv/bin/amcrest-cli --camera cam_black --ptz-goto-preset 0 1

@tchellomello Do you have the necessary skills to being able to implement this in HA? I’m a very new member of the community, and I’m just starting on Pything/polymer etc, it’s a real mess right now.

I would gladly make a small donation if you or somebody else could make the PTZ waypoints available in the frontend and make us able to enable/disable the motion detection.
I’m also willing to help with testing, if you need to.
I’m using the Hass.io installer btw.

It’s just that we are so close on getting the PTZ controls in HA. We have the connections, the components etc, but we have been missing the PTZ control from since when I joined.

Have a great day! :slight_smile:

1 Like

I have implemented something similar with custom ui elements. Its working pretty ok for now but there are many hard coded strings etc. For now, there are simply four buttons which activate a service on the server side (using manual switches atm, but this service could get integrated into e.g. the camera platform in some fashion [e.g., enable_motion_detection and disable_motion_detection are already there]).

Generally speaking, does anybody know what the current status regarding this is? This is the only thread I have found so far, maybe this has been discussed elsewhere.

There are also other things that have to be considered, e.g.:

  • there are many different ways to control ptz: (e.g. SOAP requests for onvif, general http requests, custom python library)
  • as far as I can estimate this, the service could be residing in many different locations and be referenced by the config? (e.g. in the onvif platform for onvif ptz cameras)

So far this is working for me great (as a custom ui element) but would love to help creating an general approach.

2 Likes

I might tackle this next weekend. I want this as well. Here’s my goals:

  • add ui for ptz controls
  • make ptz presets available as services to control via automation
    Longer term goals:
  • send audio output to the camera
  • send images to aws rekognition to identity faces and then send personalized audio responses back
1 Like

did u manage to implement it? ui maybe

1 Like

I am working on this for amcrest, see here

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?