Unifi G4 Doorbell Stream to Google / Nest Hubs

So I was able to successfully setup an automation where in if a button press happens on my Unifi G4 Doorbell, it will then stream to my Nest Hub(s) / Android TV(s).

The “issue” I have is, I only want it to stream on those devices for 30 seconds and then automatically stop.

Here is the YAML for what I currently have setup:

alias: Doorbell Ring
description: ""
trigger:
  - type: occupied
    platform: device
    domain: binary_sensor
condition: []
action:
  - service: media_player.play_media
    target:
      entity_id: media_player.kitchen_display
    data:
      media_content_id: media-source://camera/camera.g4_doorbell_high
      media_content_type: application/vnd.apple.mpegurl
    metadata:
      title: G4 Doorbell High
      thumbnail: /api/camera_proxy/camera.g4_doorbell_high
      media_class: video
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://camera
  - service: media_player.play_media
    target:
      entity_id: media_player.shield
    data:
      media_content_id: media-source://camera/camera.g4_doorbell_high
      media_content_type: application/vnd.apple.mpegurl
    metadata:
      title: G4 Doorbell High
      thumbnail: /api/camera_proxy/camera.g4_doorbell_high
      media_class: video
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://camera
mode: single

Welcome at the forum!

Nice automation you got there, try to take a snapshot first, stream the video to the media player and after 30s restore the snapshot.

In my automation to activate my sonos player when the doorbell is pressed I use the same technique.

alias: "Security: Deurbel geactiveerd"
description: ""
trigger:
 - platform: state
   entity_id:
     - binary_sensor.voordeur_doorbell
   to: "on"
condition: []
action:
 - service: sonos.snapshot
   data:
     entity_id: media_player.eetkamer
   alias: Momentopname van Eetkamer
 - service: media_player.volume_set
   data:
     volume_level: 0.75
   target:
     entity_id:
       - media_player.eetkamer
 - service: media_player.play_media
   target:
     entity_id:
       - media_player.eetkamer
   data:
     media_content_id: /local/chime.mp3
     media_content_type: audio/mpeg
 - delay:
     hours: 0
     minutes: 0
     seconds: 2
     milliseconds: 0
 - service: sonos.restore
   data:
     entity_id: media_player.eetkamer
   alias: Momentopname herstellen op Eetkamer
mode: single