Camera watchdog help

Hi,
I have an issue with frigate that will crash my home assistant VM due to out of memory caused by frigate. It occurs when some camera become unavailable for x reason.

So I thought of making an automation that will check if the camera becomes unavailable, turn off all frigate features and turn them back on when it becomes available again.

I don’t know anything about blueprints, so I asked AI to write and of course it has errors.

If someone could help my fix this, I would appreciate!
Thanks!!

blueprint:
  name: Frigate Camera Availability Automation with Delay and Extra Condition
  description: Automates Frigate settings based on camera availability with a delay and extra condition.
  domain: automation
variables:
  camera_entity:
    description: The entity ID of the camera to monitor.
    required: true
  frigate_motion_entity:
    description: The entity ID of the Frigate motion entity for the camera.
    required: true
  frigate_object_detection_entity:
    description: The entity ID of the Frigate object detection entity for the camera.
    required: true
  frigate_record_entity:
    description: The entity ID of the Frigate record entity for the camera.
    required: true
  notification_title:
    description: Title of the notification to send.
    default: "Camera Unavailable"
  notification_message:
    description: Message of the notification to send.
    default: "Camera '{{ camera_entity }}' is unavailable."
  delay_time:
    description: Delay time in seconds before turning off Frigate features.
    default: 30
  extra_condition_entity:
    description: The entity ID of the extra condition to check.
    default: ''
  extra_condition_state:
    description: The desired state of the extra condition entity.
    default: ''

trigger:
- platform: state
  entity_id: '{{ camera_entity }}'
  to: 'unavailable'
- platform: state
  entity_id: '{{ camera_entity }}'
  to: 'available'

action:
- service: notify.mobile_app_your_device_name
  data:
    title: '{{ notification_title }}'
    message: '{{ notification_message }}'
- if:
    condition:
      condition: template
      value: "{{ trigger.to_state.state == 'unavailable' }}"
  then:
    - delay:
        seconds: '{{ delay_time }}'
    - service: frigate.set_motion
      data:
        entity_id: '{{ frigate_motion_entity }}'
        state: 'off'
    - service: frigate.set_object_detection
      data:
        entity_id: '{{ frigate_object_detection_entity }}'
        state: 'off'
    - service: frigate.set_record
      data:
        entity_id: '{{ frigate_record_entity }}'
        state: 'off'
- elif:
    condition:
      condition: and
      conditions:
        - condition: template
          value: "{{ trigger.to_state.state == 'available' }}"
        - condition: template
          value: "{{ extra_condition_entity.state == extra_condition_state }}"
  then:
    - service: frigate.set_motion
      data:
        entity_id: '{{ frigate_motion_entity }}'
        state: 'on'
    - service: frigate.set_object_detection
      data:
        entity_id: '{{ frigate_object_detection_entity }}'
        state: 'on'
    - service: frigate.set_record
      data:
        entity_id: '{{ frigate_record_entity }}'
        state: 'on'

I spent some time reading about blueprints and I came up with this, but the automation doesn’t get triggered when the camera becomes unavailable or available

blueprint:
  name: Frigate Watchdog
  description: Automates Frigate settings based on camera availability with a delay and extra condition.
  domain: automation

  input:
    # ==========================
    # Camera Section
    # ==========================
    camera_section:
      name: Cameras
      icon: mdi:camera
      description: Configure the camera parameters
      collapsed: false

      # ==========================
      # Camera inputs
      # ==========================
      input:
        camera_entity:
          name: Camera
          description: The camera to check availability
          selector:
            entity:
              filter:
                - domain:
                    - camera
              multiple: false
        frigate_detect_entity:
          name: Frigate Detect
          description: Entity for frigate detect
          selector:
            entity:
              filter:
                - domain:
                    - switch
              multiple: false
        frigate_motion_entity:
          name: Frigate Motion
          description: Entity for frigate motion
          selector:
            entity:
              filter:
                - domain:
                    - switch
              multiple: false
        frigate_recordings_entity:
          name: Frigate Recordings
          description: Entity for frigate recordings
          selector:
            entity:
              filter:
                - domain:
                    - switch
              multiple: false
        frigate_snapshots_entity:
          name: Frigate Snapshots
          description: Entity for frigate recordings
          selector:
            entity:
              filter:
                - domain:
                    - switch
              multiple: false
    # ==========================
    # Delay section
    # ==========================
    delay_section:
      name: Delays
      icon: mdi:clock
      description: Configure the camera parameters
      collapsed: true
      # ==========================
      # Delays inputs
      # ==========================
      input:
        delay_off:
          name: Delay Off
          description: Delay before turning off frigate features.
          selector:
            number:
              min: 0
              max: 60
              unit_of_measurement: seconds

        delay_on:
          name: Delay On
          description: Delay before turning on frigate features.
          selector:
            number:
              min: 0
              max: 60
              unit_of_measurement: seconds

        send_notification:
          name: Send Notication
          description: Sends a notification when camera becomes unavailable
          selector:
            boolean:

        #security_level:
        # name: Security Level
        #description: Input security level
        #selector:
        # entity:
        #  filter:
        #   - domain:
        #      - input_select
    # ==========================
    # Notification inputs
    # ==========================

# =========================
# Variables
# =========================
variables:
  camera_state: "{{ states[camera_entity]}}"
  camera_name: "{{ states[camera_entity].name }}"
  camera_available: "{{ states[camera_entity] != 'unavailable'}}"
  camera_unavailable: "{{ states[camera_entity] == 'unavailable'}}"
  enable_notifications: !input send_notification
  #security_off: "{{ states[security_level] == 'Off' }}"
  #security_on: "{{ states[security_level] != 'Off' }}"

# =========================
# Triggers
# =========================
triggers:
  - trigger: state
    entity_id:
      - !input camera_entity
    from: null
    to: unavailable
    for:
      hours: 0
      minutes: 0
      seconds: 10
  - trigger: state
    entity_id:
      - !input camera_entity
    from: unavailable
    to: null
    for:
      hours: 0
      minutes: 0
      seconds: 0

# =========================
# Actions
# =========================
actions:
  # Camera becomes unavailable
  - if:
      - condition: state
        entity_id: !input camera_entity
        state: unavailable
    then:
      - action: switch.turn_off
        metadata: {}
        data: {}
        target:
          entity_id:
            - !input frigate_detect_entity
            - !input frigate_motion_entity
            - !input frigate_recordings_entity
            - !input frigate_snapshots_entity

      - if:
          - condition: template
            value_template: "{{ states(enable_notifications) == true }}"

        then:
          - action: notify.notify
            metadata: {}
            data:
              message: Boom!
              title: Camera state changed
    # camera becomes available
    else:
      - if:
          - condition: not
            conditions:
              - condition: state
                entity_id: !input camera_entity
                state: unavailable
        then:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id:
                - !input frigate_detect_entity
                - !input frigate_motion_entity
                - !input frigate_recordings_entity
                - !input frigate_snapshots_entity

mode: restart

ok I found the issue.
was missing !input in front camera_entity here

  camera_state: "{{ states[camera_entity]}}"
  camera_name: "{{ states[camera_entity].name }}"
  camera_available: "{{ states[camera_entity] != 'unavailable'}}"
  camera_unavailable: "{{ states[camera_entity] == 'unavailable'}}"