AlexxIT / WebRTC

Home Assistant custom component for real-time viewing of almost any camera stream using WebRTC and other technologies.
https://github.com/AlexxIT/Blog
MIT License
1.36k stars 161 forks source link

PTZ controls with the official HASS Reolink integration #609

Open threnbo opened 7 months ago

threnbo commented 7 months ago

Is it possible to use PTZ controls when using the official Relink integration (camera model E1 Zoom)?

The integrations adds button entities for PTZ controls. I tried using the example posted here https://github.com/AlexxIT/WebRTC/issues/167 but it doesn't work.

When adding the camera with the official Onvif integration the above mentioned example works, but I want to use several entites only added by the Reolink integration.

Thank you!

threnbo commented 7 months ago

It seems to work with this code:

type: custom:webrtc-camera
entity: camera.e1_zoom_main
ui: true
ptz:
  service: button.press
  data_left:
    entity_id: button.e1_zoom_ptz_left
  data_right:
    entity_id: button.e1_zoom_ptz_right
  data_up:
    entity_id: button.e1_zoom_ptz_up
  data_down:
    entity_id: button.e1_zoom_ptz_down
  data_zoom_in:
    entity_id: button.e1_zoom_ptz_zoom_in
  data_zoom_out:
    entity_id: button.e1_zoom_ptz_zoom_out

Remaining problem is that one button press means full movement in each direction.

muzzy124 commented 7 months ago

I see in the reolink integration docs that: "PTZ left, right, up, down, zoom in and zoom out will continually move the camera in the respective position until the PTZ stop is called or the hardware limit is reached."

So the issue could be solved with calling script like this:

e1_zoom_ptz_up_with_stop:
  alias: e1_zoom_ptz_up_with_stop
  sequence:
  - service: button.press
    target:
      entity_id: button.e1_zoom_ptz_up
  - delay:
      seconds: 0.5
  - service: button.press
    target:
      entity_id: button.e1_zoom_ptz_stop

The question is how to call that script from webrtc camera card?

tunip commented 5 months ago

You can use an automation for that.

Bildschirmfoto 2024-02-08 um 21 24 56
porly1985 commented 1 month ago

Hi all,

I solved it with calling script from webrtc camera card like this:

type: custom:webrtc-camera
url: camera.garage_main
ui: true
background: true
muted: true
ptz:
  service: script.toggle
  data_left:
    entity_id: script.reolink_left
  data_right:
    entity_id: script.reolink_right
  data_up:
    entity_id: script.reolink_up
  data_down:
    entity_id: script.reolink_down

Here is my script example:

alias: Reolink Down
sequence:
  - service: button.press
    data: {}
    target:
      entity_id:
        - button.garage_ptz_down
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 500
  - service: button.press
    data: {}
    target:
      entity_id: button.garage_ptz_stop
mode: single
icon: mdi:arrow-down

So I have one script for each direction. Working well.

Greetings

Paul

groover0815 commented 3 weeks ago

@porly1985

could you please provide the complete YAML code with all the commands for the PTZ Control of the Reolink camera? I have the Reolink E1 Outdsoor pro.

That would be great!

porly1985 commented 3 weeks ago

WebRTC Card:

type: custom:webrtc-camera
url: camera.garage_main
ui: true
poster: camera.garage_snapshots_main
background: false
muted: true
persist: false
ptz:
  service: script.toggle
  data_left:
    entity_id: script.reolink_left
  data_right:
    entity_id: script.reolink_right
  data_up:
    entity_id: script.reolink_up
  data_down:
    entity_id: script.reolink_down
shortcuts:
  - name: Set Guard Position
    icon: mdi:crosshairs-gps
    service: button.press
    service_data:
      entity_id: button.garage_guard_set_current_position
  - name: Light
    icon: mdi:spotlight-beam
    service: light.toggle
    service_data:
      entity_id: light.garage_floodlight
  - name: Set Focus
    icon: mdi:focus-field
    service: number.set_value
    service_data:
      entity_id: number.garage_focus
      value: '74'
  - name: Record
    icon: mdi:record-circle-outline
    service: script.toggle
    service_data:
      entity_id: script.record_garage
style: |

  .ptz {
    opacity: 1;
  }
  .pictureinpicture {
    display: none;
  }
  .shortcuts {
    position: absolute;
    top: unset;
    bottom: 1%;
    left: 50%;
    transform: translateX(-50%); 
    display: flex;
    flex-direction: row;
    gap: 20px;
    opacity: 1;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 5px;
    padding: 5px; 
    justify-content: center;

  }

Scripts:

alias: Reolink Down
sequence:
  - service: button.press
    data: {}
    target:
      entity_id:
        - button.garage_ptz_down
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 500
  - service: button.press
    data: {}
    target:
      entity_id: button.garage_ptz_stop
mode: single
icon: mdi:arrow-down
alias: Reolink Left
sequence:
  - service: button.press
    data: {}
    target:
      entity_id: button.garage_ptz_left
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 500
  - service: button.press
    data: {}
    target:
      entity_id: button.garage_ptz_stop
mode: single
icon: mdi:arrow-left
alias: Reolink Right
sequence:
  - service: button.press
    data: {}
    target:
      entity_id: button.garage_ptz_right
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 500
  - service: button.press
    data: {}
    target:
      entity_id: button.garage_ptz_stop
mode: single
icon: mdi:arrow-right
alias: Reolink Up
sequence:
  - service: button.press
    data: {}
    target:
      entity_id: button.garage_ptz_up
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 500
  - service: button.press
    data: {}
    target:
      entity_id: button.garage_ptz_stop
mode: single
icon: mdi:arrow-up
groover0815 commented 2 weeks ago

thank you @porly1985

Should I copy this code in a new YAML file with my camera "Kamera Haustür" complete?