Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add examples for UniFi Protect integration events #36029

Merged
merged 6 commits into from
Nov 27, 2024

Conversation

RaHehl
Copy link

@RaHehl RaHehl commented Nov 27, 2024

Proposed change

add examples for UniFi Protect integration

Type of change

  • Spelling, grammar or other readability improvements (current branch).
  • Adjusted missing or incorrect information in the current documentation (current branch).
  • Added documentation for a new integration I'm adding to Home Assistant (next branch).
  • Added documentation for a new feature I'm adding to Home Assistant (next branch).
  • Removed stale or deprecated documentation.

Additional information

Checklist

  • This PR uses the correct branch, based on one of the following:
    • I made a change to the existing documentation and used the current branch.
    • I made a change that is related to an upcoming version of Home Assistant and used the next branch.
  • The documentation follows the Home Assistant documentation standards.

Summary by CodeRabbit

  • New Features

    • Added example automation configurations for various events (camera motion, doorbell rings, NFC scans, fingerprint identification) in the UniFi Protect integration documentation.
    • Introduced new actions for managing doorbell texts and privacy zones.
  • Documentation

    • Expanded sections on event entities support, detailing various event types and their attributes.
    • Enhanced troubleshooting section addressing common issues like video feed delays and audio playback problems.

@home-assistant home-assistant bot added in-progress This PR/Issue is currently being worked on needs-rebase The PR has been branched of the wrong base branch or targets an incorrect target branch next This PR goes into the next branch labels Nov 27, 2024
@home-assistant
Copy link

It seems that this PR is targeted against an incorrect branch. Documentation updates which apply to our current stable release should target the current branch. Please change the target branch of this PR to current and rebase if needed. If this is documentation for a new feature, please add a link to that PR in your description.

Copy link

netlify bot commented Nov 27, 2024

Deploy Preview for home-assistant-docs ready!

Name Link
🔨 Latest commit 5dad2f1
🔍 Latest deploy log https://app.netlify.com/sites/home-assistant-docs/deploys/6747786187c6420008bf3a0f
😎 Deploy Preview https://deploy-preview-36029--home-assistant-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@RaHehl
Copy link
Author

RaHehl commented Nov 27, 2024

replaces my messed up PR #36027

Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request enhance the documentation for the UniFi Protect integration by adding example automation configurations and expanding the troubleshooting section. New YAML code snippets illustrate how to set up automations for various events, including camera motion detection, doorbell rings, NFC card scans, and fingerprint identification. Additionally, new actions related to doorbell text management and privacy zones have been introduced, along with their respective attributes.

Changes

File Path Change Summary
source/_integrations/unifiprotect.markdown Enhanced documentation with example automations for various events, expanded event entities support, and a more comprehensive troubleshooting section. New actions added: unifiprotect.add_doorbell_text, unifiprotect.remove_doorbell_text, unifiprotect.set_chime_paired_doorbells, and unifiprotect.remove_privacy_zone, each with specific attributes.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
source/_integrations/unifiprotect.markdown (3)

279-301: Enhance the notification automation example

The example is good but could be improved for better clarity and maintainability:

 title: "Security: Camera Motion Notification"
 description: "Sends a notification with video upon motion detection."
 triggers:
   - entity_id:
-      - binary_sensor.g5_bullet_motion (replace with your camera)
+      - binary_sensor.g5_bullet_motion  # Replace with your camera's motion sensor
     trigger: state
     from: "on"
     to: "off"
 actions:
   - data:
-      message: "Motion detected at Camera XXX"
+      message: "Motion detected at {{ trigger.entity_id.split('.')[1] | replace('_', ' ') | title }}"
       data:
         image: >-
           {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id)
           }}/{{ trigger.from_state.attributes.event_id }}{% endraw %}
         video: >-
           {% raw %}/api/unifiprotect/video/{{ config_entry_id(trigger.entity_id) }}/{{
           trigger.from_state.attributes.event_id }}{% endraw %}
-    action: notify.mobile_app_your_device (replace with your notification target)
+    service: notify.mobile_app_your_device  # Replace with your notification service
 mode: single
-max_exceeded: silent
+max_exceeded: silent  # Silently drop notifications if automation is triggered too frequently

Consider adding a brief explanation of the mode and max_exceeded settings in a comment, as they're important for preventing notification spam.


319-338: Improve the doorbell ring automation example

The example is functional but could be enhanced for better clarity:

 alias: G4 Doorbell Ring Triggered Automation
 description: Automation that triggers when the G4 Doorbell Pro rings
 triggers:
-  - event_type: state_changed
+  - platform: event
+    event_type: state_changed
     event_data:
-      entity_id: event.g4_doorbell_pro_poe_doorbell (replace with your camera)
+      entity_id: event.g4_doorbell_pro_poe_doorbell  # Replace with your doorbell entity
-    trigger: event
 conditions:
   - condition: template
     value_template: |
-      {% raw %}{{ 'ring' in trigger.event.data.new_state.attributes.event_types }}{% endraw %}
+      {% raw %}{{ trigger.event.data.new_state is not none and 'ring' in (trigger.event.data.new_state.attributes.event_types|default([])) }}{% endraw %}

The improved condition template adds null checks to prevent errors during Home Assistant restarts or when attributes are missing.


351-377: Enhance the NFC card scan automation example

The example is good, but the condition template could be more robust:

 triggers:
-  - event_type: state_changed
+  - platform: event
+    event_type: state_changed
     event_data:
-      entity_id: event.g4_doorbell_pro_poe_nfc  (replace with your camera)
+      entity_id: event.g4_doorbell_pro_poe_nfc  # Replace with your doorbell entity
-    trigger: event
 conditions:
   - condition: template
     value_template: >
-      {% raw %}{{ trigger.event.data.new_state.attributes.event_type == 'scanned' and
-      trigger.event.data.new_state.attributes.nfc_id == 'ABCDEF1234' }} (replace with your nfc_id){% endraw %}
+      {% raw %}{{ 
+        trigger.event.data.new_state is not none and
+        trigger.event.data.new_state.attributes.event_type == 'scanned' and
+        trigger.event.data.new_state.attributes.nfc_id == 'ABCDEF1234'  # Replace with your NFC card ID
+      }}{% endraw %}

The security warning about NFC card IDs is crucial and well-placed. Consider storing the NFC card ID in a separate input_text helper for easier management.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0cb4fe1 and 55b096a.

📒 Files selected for processing (1)
  • source/_integrations/unifiprotect.markdown (4 hunks)
🧰 Additional context used
🪛 LanguageTool
source/_integrations/unifiprotect.markdown

[uncategorized] ~303-~303: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...n. This ensures that the event has ended and the video is accessible; otherwise, you...

(COMMA_COMPOUND_SENTENCE_2)

🔇 Additional comments (1)
source/_integrations/unifiprotect.markdown (1)

Line range hint 277-416: Overall documentation improvements look great!

The added examples and documentation for event entities support are well-structured and provide valuable guidance for users implementing UniFi Protect integration features. The examples cover common use cases and include important security considerations.

source/_integrations/unifiprotect.markdown Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
source/_integrations/unifiprotect.markdown (3)

279-301: Enhance the notification automation example

The example could be improved for better clarity and user experience:

 ```yaml
+alias: "Security Camera Motion Notification"
+description: "Sends a notification with video clip when motion is detected on a security camera"
 triggers:
   - entity_id:
       - binary_sensor.g5_bullet_motion # Replace with your camera entity
     trigger: state
     from: "on"
     to: "off"
 actions:
   - data:
-      message: "Motion detected at Camera XXX"
+      message: >
+        Motion detected at {{ trigger.entity_id.replace('binary_sensor.','').replace('_motion','').title() }}
+        from {{ trigger.from_state.last_changed.strftime('%I:%M %p') }}
+        to {{ trigger.to_state.last_changed.strftime('%I:%M %p') }}
       data:
         image: >-
           {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id)

319-336: Enhance the doorbell ring automation example

The example could be improved with additional features and better notification content:

 ```yaml
 alias: G4 Doorbell Ring Triggered Automation
 description: Automation that triggers when the G4 Doorbell Pro rings
 triggers:
   - event_type: state_changed
     event_data:
       entity_id: event.g4_doorbell_pro_poe_doorbell # Replace with your doorbell entity
     trigger: event
 conditions:
   - condition: template
     value_template: |
       {% raw %}{{ 'ring' in trigger.event.data.new_state.attributes.event_types }}{% endraw %}
 actions:
   - data:
-      message: Someone is at the door!
+      message: >
+        Doorbell rang at {{ trigger.event.time_fired.strftime('%I:%M %p') }}
       title: Doorbell Notification
+      data:
+        image: >-
+          {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id)
+          }}/{{ trigger.event.data.new_state.attributes.event_id }}{% endraw %}
     action: notify.mobile_app_your_device # Replace with your notification target
+mode: single
+max_exceeded: silent

409-412: Fix warning message formatting

The warning message should be simplified and properly formatted:

-**Warning:**
-
-Similar to NFC, an event is triggered both when a fingerprint is recognized and when it is not recognized. However, unlike NFC, at the time of implementation, no fingerprint ID is included in the event if the fingerprint is unknown.
+{% warning %}
+Similar to NFC, an event is triggered both when a fingerprint is recognized and when it is not recognized. However, unlike NFC, at the time of implementation, no fingerprint ID is included in the event if the fingerprint is unknown.
+{% endwarning %}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 55b096a and 2e6bc23.

📒 Files selected for processing (1)
  • source/_integrations/unifiprotect.markdown (4 hunks)
🧰 Additional context used
🪛 LanguageTool
source/_integrations/unifiprotect.markdown

[uncategorized] ~303-~303: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...n. This ensures that the event has ended and the video is accessible; otherwise, you...

(COMMA_COMPOUND_SENTENCE_2)

source/_integrations/unifiprotect.markdown Outdated Show resolved Hide resolved
source/_integrations/unifiprotect.markdown Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
source/_integrations/unifiprotect.markdown (4)

279-301: Add error handling for missing event attributes

While the automation is well-structured, it should handle cases where event attributes might be missing.

 data:
   message: "Motion detected at Camera XXX"
   data:
     image: >-
       {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id)
-      }}/{{ trigger.from_state.attributes.event_id }}{% endraw %}
+      }}/{{ trigger.from_state.attributes.event_id | default('') }}{% endraw %}
     video: >-
       {% raw %}/api/unifiprotect/video/{{ config_entry_id(trigger.entity_id) }}/{{
-      trigger.from_state.attributes.event_id }}{% endraw %}
+      trigger.from_state.attributes.event_id | default('') }}{% endraw %}

319-336: Enhance the doorbell ring automation robustness

The automation could be improved with better error handling and a more robust condition check.

 conditions:
   - condition: template
     value_template: |
-      {% raw %}{{ 'ring' in trigger.event.data.new_state.attributes.event_types }}{% endraw %}
+      {% raw %}{{ 
+        trigger.event.data.new_state is not none and
+        trigger.event.data.new_state.attributes.event_types is defined and
+        'ring' in trigger.event.data.new_state.attributes.event_types 
+      }}{% endraw %}
 actions:
   - data:
       message: Someone is at the door!
       title: Doorbell Notification
+      data:
+        image: >-
+          {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id)
+          }}/{{ trigger.event.data.new_state.attributes.event_id | default('') }}{% endraw %}
     action: notify.mobile_app_your_device

351-376: Add logging for security monitoring

The automation handles NFC validation well, but could benefit from logging unsuccessful attempts for security monitoring.

 conditions:
   - condition: template
     value_template: >
       {% raw %}{{ 
          trigger.event.data.new_state is not none and
          trigger.event.data.new_state.attributes.event_type == 'scanned' and
          trigger.event.data.new_state.attributes.nfc_id in ['ABCDEF1234', 'OTHER_ALLOWED_ID']
        }}{% endraw %}
 actions:
+  - service: system_log.write
+    data:
+      message: >
+        {% raw %}NFC card scan: {{ trigger.event.data.new_state.attributes.nfc_id }}
+        {{ ' (unauthorized)' if trigger.event.data.new_state.attributes.nfc_id not in ['ABCDEF1234', 'OTHER_ALLOWED_ID'] else '' }}{% endraw %}
+      level: warning
   - data:
       message: >-
         {% raw %}The NFC card with ID {{ trigger.event.data.new_state.attributes.nfc_id

393-415: Enhance notification content with timestamp

The automation handles fingerprint validation well, but the notification could be more informative.

   - service: notify.mobile_app_your_device
     data:
-      {% raw %}message: "Fingerprint identified with ID: {{ trigger.event.data.new_state.attributes.ulp_id }}"{% endraw %}
+      {% raw %}message: >
+        Fingerprint identified at {{ trigger.event.time_fired.strftime('%I:%M %p') }}
+        ID: {{ trigger.event.data.new_state.attributes.ulp_id }}{% endraw %}
       title: "Fingerprint Scan Notification"
+      data:
+        image: >-
+          {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id)
+          }}/{{ trigger.event.data.new_state.attributes.event_id | default('') }}{% endraw %}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2e6bc23 and ec7fed3.

📒 Files selected for processing (1)
  • source/_integrations/unifiprotect.markdown (4 hunks)
🧰 Additional context used
🪛 LanguageTool
source/_integrations/unifiprotect.markdown

[uncategorized] ~303-~303: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...n. This ensures that the event has ended and the video is accessible; otherwise, you...

(COMMA_COMPOUND_SENTENCE_2)

🔇 Additional comments (1)
source/_integrations/unifiprotect.markdown (1)

303-303: LGTM!

The current sentence structure is clear and readable.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~303-~303: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...n. This ensures that the event has ended and the video is accessible; otherwise, you...

(COMMA_COMPOUND_SENTENCE_2)

@RaHehl
Copy link
Author

RaHehl commented Nov 27, 2024

@coderabbitai review

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
source/_integrations/unifiprotect.markdown (3)

279-299: Enhance the notification automation example with additional validation

The automation example is well-structured but could be more robust with additional validation.

Consider adding these improvements:

 trigger:
   - entity_id:
       - binary_sensor.g5_bullet_motion # Replace with your camera entity
     trigger: state
     from: "on"
     to: "off"
+condition:
+  - condition: template
+    value_template: >
+      {% raw %}{{
+        trigger.from_state.attributes.event_id is defined and
+        trigger.from_state.attributes.event_id != none
+      }}{% endraw %}
 actions:
   - data:
       message: "Motion detected at Camera XXX"
       data:
+        # Only include media if event_id exists
         image: >-
           {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.from_state.attributes.event_id }}{% endraw %}
         video: >-
           {% raw %}/api/unifiprotect/video/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.from_state.attributes.event_id }}{% endraw %}

317-334: Enhance the doorbell ring automation with richer notifications

The automation handles the basic case well but could provide more useful information in the notification.

Consider these improvements:

 actions:
   - data:
-      message: Someone is at the door!
+      message: >
+        {% raw %}Someone rang the doorbell at {{ trigger.event.time_fired.strftime('%I:%M %p') }}{% endraw %}
       title: Doorbell Notification
+      data:
+        image: >-
+          {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.event.data.new_state.attributes.event_id }}{% endraw %}
     action: notify.mobile_app_your_device # Replace with your notification target

391-413: Enhance fingerprint automation with richer notifications

The automation handles fingerprint identification well but could provide more context in the notification.

Consider these improvements:

 action:
   - service: notify.mobile_app_your_device
     data:
-      {% raw %}message: "Fingerprint identified with ID: {{ trigger.event.data.new_state.attributes.ulp_id }}"{% endraw %}
+      {% raw %}message: >
+        Fingerprint identified at {{ trigger.event.time_fired.strftime('%I:%M %p') }}
+        ID: {{ trigger.event.data.new_state.attributes.ulp_id }}{% endraw %}
       title: "Fingerprint Scan Notification"
+      data:
+        image: >-
+          {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.event.data.new_state.attributes.event_id }}{% endraw %}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ec7fed3 and 7e7becd.

📒 Files selected for processing (1)
  • source/_integrations/unifiprotect.markdown (4 hunks)
🧰 Additional context used
🪛 LanguageTool
source/_integrations/unifiprotect.markdown

[uncategorized] ~301-~301: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...n. This ensures that the event has ended and the video is accessible; otherwise, you...

(COMMA_COMPOUND_SENTENCE_2)

🔇 Additional comments (1)
source/_integrations/unifiprotect.markdown (1)

349-374: LGTM! Well-structured NFC automation with proper security considerations

The automation implements good security practices by validating the NFC ID against a whitelist and includes proper null checks.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
source/_integrations/unifiprotect.markdown (3)

279-299: Enhance the notification automation example with better error handling and messaging

The automation example could be improved with additional error handling and a more informative notification message.

 alias: "Security: Camera Motion Notification"
 description: "Sends a notification with video upon motion detection."
 triggers:
   - entity_id:
       - binary_sensor.g5_bullet_motion # Replace with your camera entity
     trigger: state
     from: "on"
     to: "off"
 actions:
   - data:
-      message: "Motion detected at Camera XXX"
+      message: >-
+        {% raw %}Motion detected at {{ trigger.entity_id.split('.')[1]|replace('_', ' ')|title }}
+        Duration: {{ (as_timestamp(trigger.to_state.last_changed) - as_timestamp(trigger.from_state.last_changed))|round(1) }} seconds{% endraw %}
       data:
         image: >-
-          {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.from_state.attributes.event_id }}{% endraw %}
+          {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.from_state.attributes.event_id|default('') }}{% endraw %}
         video: >-
-          {% raw %}/api/unifiprotect/video/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.from_state.attributes.event_id }}{% endraw %}
+          {% raw %}/api/unifiprotect/video/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.from_state.attributes.event_id|default('') }}{% endraw %}
     action: notify.mobile_app_your_device # Replace with your notification target
 mode: single
 max_exceeded: silent

317-334: Enhance the doorbell automation with media content and better error handling

The doorbell automation could be improved by including the event thumbnail in the notification and adding null checks.

 alias: G4 Doorbell Ring Triggered Automation
 description: Automation that triggers when the G4 Doorbell Pro rings
 triggers:
   - event_type: state_changed
     event_data:
       entity_id: event.g4_doorbell_pro_poe_doorbell # Replace with your doorbell entity
     trigger: event
 conditions:
   - condition: template
     value_template: |
-      {% raw %}{{ 'ring' in trigger.event.data.new_state.attributes.event_types }}{% endraw %}
+      {% raw %}{{ 
+        trigger.event.data.new_state is not none and
+        'ring' in (trigger.event.data.new_state.attributes.event_types|default([])) 
+      }}{% endraw %}
 actions:
   - data:
       message: Someone is at the door!
       title: Doorbell Notification
+      data:
+        image: >-
+          {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.event.data.new_state.attributes.event_id|default('') }}{% endraw %}
     action: notify.mobile_app_your_device # Replace with your notification target

390-412: Enhance the fingerprint notification with timestamp information

The fingerprint automation could be improved by including the timestamp in the notification message.

 action:
   - service: notify.mobile_app_your_device # Replace with your notification target
     data:
-      {% raw %}message: "Fingerprint identified with ID: {{ trigger.event.data.new_state.attributes.ulp_id }}"{% endraw %}
+      {% raw %}message: >-
+        Fingerprint identified with ID: {{ trigger.event.data.new_state.attributes.ulp_id }}
+        Time: {{ trigger.event.time_fired.strftime('%I:%M %p') }}{% endraw %}
       title: "Fingerprint Scan Notification"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7e7becd and d1c9fc6.

📒 Files selected for processing (1)
  • source/_integrations/unifiprotect.markdown (4 hunks)
🧰 Additional context used
🪛 LanguageTool
source/_integrations/unifiprotect.markdown

[uncategorized] ~301-~301: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...n. This ensures that the event has ended and the video is accessible; otherwise, you...

(COMMA_COMPOUND_SENTENCE_2)

🔇 Additional comments (1)
source/_integrations/unifiprotect.markdown (1)

349-373: LGTM! Well-structured NFC automation example

The NFC automation example is well-implemented with proper null checks, ID validation, and security considerations.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
source/_integrations/unifiprotect.markdown (2)

279-299: Add error handling for missing event attributes

The automation could be more robust by adding checks for missing event attributes.

 trigger:
   - entity_id:
       - binary_sensor.g5_bullet_motion # Replace with your camera entity
     trigger: state
     from: "on"
     to: "off"
+condition:
+  - condition: template
+    value_template: >
+      {% raw %}{{
+        trigger.from_state.attributes.event_id is defined and
+        trigger.from_state.attributes.event_id != none
+      }}{% endraw %}
 actions:
   - data:
       message: "Motion detected at Camera XXX"
       data:
         image: >-
           {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.from_state.attributes.event_id }}{% endraw %}
         video: >-
           {% raw %}/api/unifiprotect/video/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.from_state.attributes.event_id }}{% endraw %}
     action: notify.mobile_app_your_device # Replace with your notification target

390-412: Enhance fingerprint notification with event media and timestamp

While the security implementation is solid, the notification could be more informative.

 action:
   - service: notify.mobile_app_your_device # Replace with your notification target
     data:
-      {% raw %}message: "Fingerprint identified with ID: {{ trigger.event.data.new_state.attributes.ulp_id }}"{% endraw %}
+      {% raw %}message: >
+        Fingerprint identified at {{ trigger.event.time_fired.strftime('%I:%M %p') }}
+        Access granted for user with ID {{ trigger.event.data.new_state.attributes.ulp_id }}.{% endraw %}
       title: "Fingerprint Scan Notification"
+      data:
+        image: >-
+          {% raw %}/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id) }}/{{ trigger.event.data.new_state.attributes.event_id }}{% endraw %}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d1c9fc6 and 5dad2f1.

📒 Files selected for processing (1)
  • source/_integrations/unifiprotect.markdown (4 hunks)
🧰 Additional context used
🪛 LanguageTool
source/_integrations/unifiprotect.markdown

[uncategorized] ~301-~301: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...Waiting ensures that the event has ended and the video is accessible; otherwise, you...

(COMMA_COMPOUND_SENTENCE_2)

🔇 Additional comments (1)
source/_integrations/unifiprotect.markdown (1)

349-373: LGTM! Secure implementation with proper validation

The automation correctly implements security best practices by validating NFC IDs against a whitelist and including proper null checks.

source/_integrations/unifiprotect.markdown Show resolved Hide resolved
@bdraco bdraco added this to the 2024.12 milestone Nov 27, 2024
@bdraco bdraco removed in-progress This PR/Issue is currently being worked on needs-rebase The PR has been branched of the wrong base branch or targets an incorrect target branch labels Nov 27, 2024
@home-assistant home-assistant bot added the has-parent This PR has a parent PR in a other repo label Nov 27, 2024
@bdraco bdraco merged commit 6058457 into home-assistant:next Nov 27, 2024
7 checks passed
@frenck frenck added the cherry-picked This PR has been manually picked and merged into the current branch label Nov 28, 2024
frenck pushed a commit that referenced this pull request Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked This PR has been manually picked and merged into the current branch has-parent This PR has a parent PR in a other repo next This PR goes into the next branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants