Onvif camera platform - How to do PTZ?

Looking at the Onvif camera platform, it looks like HA should auto-discover PTZ capable cameras?

I was able to view a camera stream for the PTZ camera, but there was no controls to pan/tilt/zoom. The platform mentions service attributes for tilt, pan, and zoom, but I don’t know how to access them or bring them into lovelace. Looking at the entity properties, I don’t see anything. Am I missing some extra step to enable PTZ?

Thanks!

2 Likes

I have same issue… have you solved please ?
Thanks in advance

No, still no luck. Sorry.

I’ll note I was able to get service calls for my dinky onvif camera to do pan/tilt via calls to:
service: onvif.ptz

and data like:

entity_id: all
tilt: DOWN
speed: 1
distance: 0.3
move_mode: ContinuousMove

Turns out that “move_mode” is important for my cam and some cameras only support ContinuousMove apparently. YMMV.

Started a cute panel for it, I’m sure it’s been done plenty, but I like it:

type: picture-glance
entities:
  - entity: camera.garage_tilt
    tap_action:
      action: call-service
      service: onvif.ptz
      service_data:
        entity_id: camera.garage_tilt
        pan: LEFT
        speed: 1
        distance: 0.3
        move_mode: ContinuousMove
    name: Pan Left
    show_state: false
    icon: 'mdi:arrow-left'
    show_icon: true
  - entity: camera.garage_tilt
    tap_action:
      action: call-service
      service: onvif.ptz
      service_data:
        entity_id: camera.garage_tilt
        tilt: UP
        speed: 1
        distance: 0.3
        move_mode: ContinuousMove
    name: Tilt Up
    icon: 'mdi:arrow-up'
  - entity: camera.garage_tilt
    tap_action:
      action: call-service
      service: onvif.ptz
      service_data:
        entity_id: camera.garage_tilt
        tilt: DOWN
        speed: 1
        distance: 0.3
        move_mode: ContinuousMove
    name: Tilt Down
    icon: 'mdi:arrow-down'
  - entity: camera.garage_tilt
    tap_action:
      action: call-service
      service: onvif.ptz
      service_data:
        entity_id: camera.garage_tilt
        pan: RIGHT
        speed: 1
        distance: 0.3
        move_mode: ContinuousMove
    name: Pan Right
    icon: 'mdi:arrow-right'
    show_icon: true
camera_image: camera.garage_tilt
camera_view: live

Full panel with little pan/tilt buttons at the bottom.

22 Likes

Hi Mate
I have just used your card code for my onvif camera and it works relatively well, however…
When I click any of the arrows, it does the whole circle, until it ends , also I’m getting a message: “failed to call service onvif/ptz missing attribute”
Not sure what I’m missing.
I would be happy if I would have more control over the pan and tilt
Thanks

Thank you for this card setup. I just added my Escam G2 to HA via ONVIF integration (in the past I was using it as a general camera) and when I saw that I can trigger these movements, I started to search for a way to add these buttons to the card. Your solution works perfectly for my needs. Thank you for sharing!

Tanks a lot.!
It works like a charm with my new Reolink E1 Pro :hugs:!
Regards,
Jeff

Hi, i’m getting ‘NoneType’ object has no attribute ‘continuous’ to.
:S

I have a Sunba 405-ECO V2 PTZ and the below has worked for me with the addition of 2 presets. A short delay as the ONVIF feed is not truly live so avoid many button pushes.

RAW configuration fro HA

title: PTZ
views:
  - title: test
    path: test
    badges: []
    cards:
      - type: picture-glance
        title: Kitchen
        image: 'https://demo.home-assistant.io/stub_config/kitchen.png'
        entities:
          - entity: camera.ptz_profile_000
            tap_action:
              action: call-service
              service: onvif.ptz
              service_data:
                entity_id: camera.ptz_profile_000
                pan: LEFT
                speed: 0.5
                distance: 0.5
                move_mode: ContinuousMove
            name: Pan Left
            show_state: false
            icon: 'mdi:arrow-left'
            show_icon: true
          - entity: camera.ptz_profile_000
            tap_action:
              action: call-service
              service: onvif.ptz
              service_data:
                entity_id: camera.ptz_profile_000
                tilt: UP
                speed: 0.5
                distance: 0.5
                move_mode: ContinuousMove
            name: Pan Up
            show_state: false
            icon: 'mdi:arrow-up'
            show_icon: true
          - entity: camera.ptz_profile_000
            tap_action:
              action: call-service
              service: onvif.ptz
              service_data:
                entity_id: camera.ptz_profile_000
                tilt: DOWN
                speed: 0.5
                distance: 0.5
                move_mode: ContinuousMove
            name: Pan Down
            show_state: false
            icon: 'mdi:arrow-down'
            show_icon: true
          - entity: camera.ptz_profile_000
            tap_action:
              action: call-service
              service: onvif.ptz
              service_data:
                entity_id: camera.ptz_profile_000
                pan: RIGHT
                speed: 0.5
                distance: 0.5
                move_mode: ContinuousMove
            name: Pan Right
            show_state: false
            icon: 'mdi:arrow-right'
            show_icon: true
          - entity: camera.ptz_profile_000
            tap_action:
              action: call-service
              service: onvif.ptz
              service_data:
                entity_id: camera.ptz_profile_000
                preset: 1
                speed: 0.5
                distance: 0.5
                move_mode: GotoPreset
            name: Preset 1
            show_state: false
            icon: 'mdi:numeric-1-box'
            show_icon: true
          - entity: camera.ptz_profile_000
            tap_action:
              action: call-service
              service: onvif.ptz
              service_data:
                entity_id: camera.ptz_profile_000
                preset: 2
                speed: 0.5
                distance: 0.5
                move_mode: GotoPreset
            name: Preset 2
            show_state: false
            icon: 'mdi:numeric-2-box'
            show_icon: true
        camera_image: camera.ptz_profile_000
        camera_view: live

4 Likes

I can’t seem to get GotoPreset to work, ContinuousMove works fine - but is useless if I have to click like an idiot to get to my presets. I can access these fine with MotionEye and Keyboard Maestro, so I know its not an issue with the camera’s ability to reference presets. An idea what could be wrong?

Can you share the logs for when you run the service?
As well as the data you are using for it?

I haven’t actually put it in the config yet, only tested with the dev tool. As I said though, ContinuousMove works well, just GotoPreset that won’t fire anything.

Where would I find the logs?

Ok, so - simple button, simple code. Preset 6 pans fine from Keyboard Maestro and MotionEye.

type: entity
entity: camera.balcony_profile0
tap_action:
  action: call-service
  service: onvif.ptz
  service_data:
    entity_id: ccamera.balcony_profile0
    pan: RIGHT
    preset: 6
    speed: 1
    distance: 1
    continuous_duration: 1
    move_mode: GotoPreset
name: Preset 6
show_state: false
icon: 'mdi:numeric-6-box'
show_icon: true

Found the log entry:

Last logged: 12:55:34 PM

PTZ preset '6' does not exist on device 'Balcony'. Available Presets: preset0, preset1, preset2, preset3, preset4, preset5, preset6, preset7, preset8

ok so try set it like this :

preset: preset6

Hello @olijouve!

I finally figured it out late last night. I got it working doing exactly that preset: preset#… though I initially tried that immediately after seeing that mentioned in the logs and it was throwing me a very strange error - one that Google couldn’t help with;

Screen Shot 2021-03-19 at 2.27.50 PM

“Nousd”? What the hell is “Nousd”?! I Googled like crazy and found nothing. It wasn’t until I figured out that the preset numbers stored in the camera are different than those on my Security Spy or Keyboard Maestro references. They are stored in the order they are created. So trying another preset number worked, anything other than “preset6”.

…I think “Nousd” means “Un-used”.

Anyhow, thanks for your help!

I just copied and pasted PoorMattie’s config and replaced the camera entity with mine. Works perfectly straight away. thank you!

Hello how did you do for the preset because I can not do it ?

entity_id: camera.ipcam_profile1_2
pan: RIGHT
distance: 1
speed: 0.5
continuous_duration: 0.5
preset: position 1
move_mode: GotoPreset

here is the photo of my presets
Capture

This code works amazing!
The big question is though, can you also add audio from the camera in it?

1 Like

Hi guys, I am ultra noob in HA :slight_smile: can anybody write me, where I am supposted to write that code? In configuration.yaml?