Add PTZ functionality to the camera platform

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