Onvif camera platform - How to do PTZ?

it works for me

type: custom:webrtc-camera
url: http://onvif_rtsp
mode: webrtc
ui: true
muted: true
style: >-
  .mode {display: none} .pictureinpicture{display: none} .screenshot{display:
  none} .ptz{opacity: initial}
background: true
ptz:
  service: onvif.ptz
  data_up:
    tilt: UP
    entity_id: camera.ip_camera_profile_001
    speed: 1
    distance: 1
    move_mode: ContinuousMove
    continuous_duration: 0.6
  data_down:
    tilt: DOWN
    entity_id: camera.ip_camera_profile_001
    speed: 1
    distance: 1
    move_mode: ContinuousMove
    continuous_duration: 0.6
  data_left:
    pan: LEFT
    entity_id: camera.ip_camera_profile_001
    speed: 1
    distance: 1
    move_mode: ContinuousMove
    continuous_duration: 0.6
  data_right:
    pan: RIGHT
    entity_id: camera.ip_camera_profile_001
    speed: 1
    distance: 1
    move_mode: ContinuousMove
    continuous_duration: 0.6
type: custom:webrtc-camera
url: onvif://admin:[email protected]:80?subtype=MediaProfile00000
mode: webrtc
ui: true
muted: true
style: >-
  .mode {display: none} .pictureinpicture{display: none} .screenshot{display:
  none} .ptz{opacity: initial}
background: true
ptz:
  service: onvif.ptz
  data_zoom_in:
    zoom: ZOOM_IN
    entity_id: camera.shed_onvif_mediaprofile_channel1_mainstream
    speed: 1
    distance: 1
    move_mode: ContinuousMove
    continuous_duration: 0.1
  data_down_out:
    zoom: ZOOM_OUT
    entity_id: camera.shed_onvif_mediaprofile_channel1_mainstream
    speed: 1
    distance: 1
    move_mode: ContinuousMove
    continuous_duration: -0.1

Anyone know how to get zoom on a varifocal working? ODM says it supports ptz but i can’t get it working. Empire Tech/ Dahua 5542 s3 IPC-T54IR-ZE White S3

1 Like

This is the zoom part from my code and is working

  - entity: camera.hikvision_ds_2de4225iw_de_mainstream
    tap_action:
      action: call-service
      service: onvif.ptz
      service_data:
        entity_id: camera.hikvision_ds_2de4225iw_de_mainstream
        zoom: ZOOM_IN
        speed: 1
        distance: 0.3
        move_mode: ContinuousMove
    name: zoomin
    show_state: false
    icon: mdi:magnify-plus
    show_icon: true
  - entity: camera.hikvision_ds_2de4225iw_de_mainstream
    tap_action:
      action: call-service
      service: onvif.ptz
      service_data:
        entity_id: camera.hikvision_ds_2de4225iw_de_mainstream
        zoom: ZOOM_OUT
        speed: 1
        distance: 0.3
        move_mode: ContinuousMove
    name: zoomout
    show_state: false
    icon: mdi:magnify-minus
    show_icon: true

Tanks a lot!
It works!

1 Like

I tried a bunch of different preset naming and I always get this error:

2025-04-09 11:07:12.772 WARNING (MainThread) [homeassistant.components.onvif] Absolute Presets not supported on device 'Speed B18T'

Does that mean my camera does not support presets over Onvif no matter what? (it does have presets in the camera’s manufacturer’s app)

if wanted, i was making a project " onvif_ptz-control.js

as i was always having problems with bad PTZ service for home asisatant …

now, you can control everything and you call it from a “shell_command” and define it in:

→ configuration.yaml …

#under:
shell_command:
onvif_ptz_control: ssh -o “StrictHostKeyChecking=no” root@localhost “/usr/local/nodejs/bin/node /home/onvif/onvif_ptz-control.js --log=1 --ip={{ ip }} --port={{ port }} --user={{ user }} --pass={{ password }} --action={{ action }}{% if pan is defined %} --pan={{ pan }}{% endif %}{% if tilt is defined %} --tilt={{ tilt }}{% endif %}{% if zoom is defined %} --zoom={{ zoom }}{% endif %}{% if time is defined %} --time={{ time }}{% endif %}{% if preset is defined %} --preset={{ preset }}{% endif %}{% if presetname is defined %} --presetname={{ presetname }}{% endif %}{% if debug is defined %} --debug={{ debug }}{% endif %}{% if verbose is defined %} --verbose={{ verbose }}{% endif %}{% if mute is defined %} --mute={{ mute }}{% endif %}”

and then you call ther service from a button in lovelace or whatever …
via:

        hold_action:
          action: call-service
          confirmation:
            text: Do you really want to save the current position as *2*
          service: shell_command.onvif_ptz_control
          service_data:
            ip: 172.20.1.171
            port: 8080
            user: admin
            password: 1234
            action: setpreset
            presetname: Preset012

for more info … see: onvif_ptz-control.js on github

have fun …

cu camel

Thanks, I used this code and addes the zoom function from my hikvision dome cam like described in the docs.

  - entity: camera.dome
    tap_action:
      action: call-service
      service: onvif.ptz
      service_data:
        entity_id: camera.ds_2df8223i_ael_mainstream
        zoom: ZOOM_IN
        speed: 1
        distance: 0.3
        move_mode: ContinuousMove
    name: ZOOM_IN
    icon: mdi:magnify-plus
    show_icon: true
  - entity: camera. Dome
    tap_action:
      action: call-service
      service: onvif.ptz
      service_data:
        entity_id: camera.ds_2df8223i_ael_mainstream
        zoom: ZOOM_OUT
        speed: 1
        distance: 0.3
        move_mode: ContinuousMove
    name: ZOOM_OUT
    icon: mdi:magnify-minus
    show_icon: true