TekOnline

Send Camera Video by Email From a Home Assistant Automation

Home Assistant can do more than send a push notification when a camera sees a person. You can record a short clip, attach that video to an email, and still keep phone alerts and lights limited to the hours you care about.

This pattern is useful for security cameras because it separates two concerns:

  • Evidence capture: record the clip every time and email it when email alerts are enabled.
  • Attention alerts: only push your phone or turn on lights during your chosen alert window.

The example below uses a front-yard person sensor, a camera entity, and an SMTP notifier. It is based on Home Assistant’s camera.recordcamera.snapshot, automation conditions, and SMTP notify actions.

In this setup, the front-yard person sensor always starts the recording automation. The phone notification and lights are controlled separately by an alert toggle and alert hours, while email delivery has its own toggle and recipient setting.

What You Need

You need these entities or equivalents:

binary_sensor.front_yard_person
camera.front_yard_clear
camera.front_yard_snapshots_fluent
notify.purelymail_camera_email
notify.mobile_app_your_phone

The person sensor usually comes from a camera integration such as Reolink, Frigate, UniFi Protect, or another integration that exposes AI detection entities.

How the Pieces Are Wired Together

At a high level, the automation works like this:

  1. The camera integration detects a person and turns binary_sensor.front_yard_person on.
  2. The automation creates a timestamp, such as 20260519-213012.
  3. Home Assistant saves a snapshot image to /config/www/snapshots/....
  4. Home Assistant records an MP4 video to /media/....
  5. The phone notification uses the snapshot URL so the notification can show a preview image.
  6. The email notification attaches the recorded MP4 file from disk.

The important idea is that Home Assistant has two different ways to refer to files:

Path typeExampleUsed for
Internal file path/config/www/snapshots/front_yard_latest.jpgSaving a file from an action such as camera.snapshot.
Browser/mobile URL/local/snapshots/front_yard_latest.jpgShowing an image in a mobile notification or browser.
Internal media path/media/HomeAssistant/Recordings/front_yard/front_yard_{{ ts }}.mp4Saving a camera recording and attaching it to email.

Files saved under /config/www are exposed by Home Assistant under /local. So this file:

/config/www/snapshots/front_yard_latest.jpg

is viewed by the phone app as:

/local/snapshots/front_yard_latest.jpg

The video is different. It does not need a public URL because the SMTP notifier is running inside Home Assistant. It can attach the file directly from the internal path:

/media/HomeAssistant/Recordings/front_yard/front_yard_20260519-213012.mp4

That is why the automation uses both snapshot_file and snapshot_url, but only one video_file.

Exposed Settings

These helpers make the automation adjustable from the Home Assistant UI without editing YAML.

HelperPurpose
input_boolean.front_yard_detection_alertsEnables phone alerts and light actions.
input_boolean.front_yard_email_alertsEnables video emails.
input_text.front_yard_email_recipientEmail address to send the video to.
input_datetime.front_yard_alert_startStart of the phone/light alert window.
input_datetime.front_yard_alert_endEnd of the phone/light alert window.
input_number.front_yard_recording_length_secondsLength of the recorded clip.
input_number.front_yard_recording_lookback_secondsSeconds to include before the event, if supported by the camera stream.
input_number.front_yard_light_on_minutesHow long the front-yard light stays on.
input_number.person_detection_debounce_minutesCooldown after a detection so repeated triggers are ignored.

You can find these under Settings > Devices & services > Helpers. For quick access, add them to a dashboard card.

Configure Email

Home Assistant’s SMTP notifier is configured in configuration.yaml. Keep passwords in secrets.yaml.

The example below uses Purelymail, but the same shape works for other SMTP providers. Change serverportencryptionsenderusername, and password to match your provider.

notify:
  - name: purelymail_camera_email
    platform: smtp
    server: smtp.purelymail.com
    port: 465
    timeout: 30
    encryption: tls
    sender: "noreply@example.com"
    sender_name: "Home Assistant"
    username: !secret purelymail_smtp_username
    password: !secret purelymail_smtp_password
    recipient:
      - "you@example.com"
# secrets.yaml
purelymail_smtp_username: "noreply@example.com"
purelymail_smtp_password: "your-mailbox-or-app-password"

Restart Home Assistant after adding a new SMTP notifier. A plain automation reload is not enough for a new notify platform.

Create the Helpers

Add helpers for alert hours, toggles, recipient, recording length, lookback, light duration, and debounce.

input_datetime:
  front_yard_alert_start:
    name: Front yard alert start
    has_date: false
    has_time: true
    initial: "21:00:00"

  front_yard_alert_end:
    name: Front yard alert end
    has_date: false
    has_time: true
    initial: "05:00:00"

input_boolean:
  front_yard_detection_alerts:
    name: Front yard detection alerts
    initial: true

  front_yard_email_alerts:
    name: Front yard email video alerts
    initial: true

input_text:
  front_yard_email_recipient:
    name: Front yard email recipient
    initial: "you@example.com"
    max: 255

input_number:
  person_detection_debounce_minutes:
    name: Person detection debounce minutes
    min: 1
    max: 60
    step: 1
    mode: box
    initial: 5

  front_yard_recording_length_seconds:
    name: Front yard recording length seconds
    min: 5
    max: 120
    step: 5
    mode: box
    initial: 30

  front_yard_recording_lookback_seconds:
    name: Front yard recording lookback seconds
    min: 0
    max: 60
    step: 5
    mode: box
    initial: 20

  front_yard_light_on_minutes:
    name: Front yard light on minutes
    min: 1
    max: 30
    step: 1
    mode: box
    initial: 3

The time-window template below handles both same-day ranges and overnight ranges like 21:00 to 05:00.

Optional Dashboard Card

This card gives you a compact control panel for the front-yard alert behavior.

type: entities
title: Front yard camera alerts
entities:
  - entity: input_boolean.front_yard_detection_alerts
    name: Phone and light alerts
  - entity: input_boolean.front_yard_email_alerts
    name: Email video alerts
  - entity: input_text.front_yard_email_recipient
    name: Email recipient
  - entity: input_datetime.front_yard_alert_start
    name: Alert start
  - entity: input_datetime.front_yard_alert_end
    name: Alert end
  - entity: input_number.front_yard_recording_length_seconds
    name: Recording length
  - entity: input_number.front_yard_recording_lookback_seconds
    name: Recording lookback
  - entity: input_number.front_yard_light_on_minutes
    name: Light duration
  - entity: input_number.person_detection_debounce_minutes
    name: Debounce

Automation: Record, Email, and Conditionally Alert

This automation is intentionally split into small steps. Read it as a pipeline:

  1. Build file names.
  2. Save the snapshot.
  3. Optionally send the phone alert.
  4. Record the video.
  5. Optionally send the email with the video attached.
  6. Wait for the debounce period before accepting another trigger.
- alias: Front yard record and notify
  trigger:
    - platform: state
      entity_id: binary_sensor.front_yard_person
      to: "on"
  condition: []
  action:
    - variables:
        ts: "{{ now().strftime('%Y%m%d-%H%M%S') }}"
        snapshot_file: /config/www/snapshots/front_yard_latest.jpg
        snapshot_url: /local/snapshots/front_yard_latest.jpg
        video_file: /media/HomeAssistant/Recordings/front_yard/front_yard_{{ ts }}.mp4
        email_recipient: "{{ states('input_text.front_yard_email_recipient') | trim }}"

    - action: camera.snapshot
      target:
        entity_id: camera.front_yard_snapshots_fluent
      data:
        filename: "{{ snapshot_file }}"

    - if:
        - condition: state
          entity_id: input_boolean.front_yard_detection_alerts
          state: "on"
        - condition: template
          value_template: >
            {% set start = today_at(states('input_datetime.front_yard_alert_start')) %}
            {% set end = today_at(states('input_datetime.front_yard_alert_end')) %}
            {% set current = now() %}
            {{ (start <= end and start <= current < end)
               or (start > end and (current >= start or current < end)) }}
      then:
        - action: notify.mobile_app_your_phone
          data:
            title: Front yard camera
            message: Person detected in the front yard. Tap to open the live camera.
            data:
              image: "{{ snapshot_url }}"
              attachment:
                url: "{{ snapshot_url }}"
                content-type: jpeg
              url: /more-info/camera.front_yard_clear
              clickAction: /more-info/camera.front_yard_clear
              tag: front-yard-camera-person

    - action: camera.record
      target:
        entity_id: camera.front_yard_clear
      data:
        duration: "{{ states('input_number.front_yard_recording_length_seconds') | int(30) }}"
        lookback: "{{ states('input_number.front_yard_recording_lookback_seconds') | int(20) }}"
        filename: "{{ video_file }}"

    - if:
        - condition: state
          entity_id: input_boolean.front_yard_email_alerts
          state: "on"
        - condition: template
          value_template: >
            {{ email_recipient not in ['unknown', 'unavailable', '']
               and '@' in email_recipient }}
      then:
        - action: notify.purelymail_camera_email
          data:
            title: Front yard camera person detected
            message: Person detected in the front yard. Video attached.
            target:
              - "{{ email_recipient }}"
            data:
              images:
                - "{{ video_file }}"

    - delay:
        minutes: "{{ states('input_number.person_detection_debounce_minutes') | int(5) }}"
  mode: single

Two details matter:

  • camera.record must write to a path Home Assistant can access, such as /media/....
  • The email action runs after camera.record, so the file exists before SMTP tries to attach it.
  • The target field in the SMTP notify action overrides the default recipient, which lets the automation use input_text.front_yard_email_recipient.

Home Assistant’s SMTP notifier documents the images list for attachments. Despite the name, this setup was verified with an .mp4 path as a normal email attachment. If your Home Assistant version or mail provider rejects video files, reduce clip length or send a snapshot instead.

Automation: Turn Lights On During Alert Hours

Keep lighting separate from recording. That way the video still gets emailed even if alerts are disabled.

- alias: Front lawn person detection lights on
  trigger:
    - platform: state
      entity_id: binary_sensor.front_yard_person
      to: "on"
  condition:
    - condition: state
      entity_id: input_boolean.front_yard_detection_alerts
      state: "on"
    - condition: template
      value_template: >
        {% set start = today_at(states('input_datetime.front_yard_alert_start')) %}
        {% set end = today_at(states('input_datetime.front_yard_alert_end')) %}
        {% set current = now() %}
        {{ (start <= end and start <= current < end)
           or (start > end and (current >= start or current < end)) }}
  action:
    - action: switch.turn_on
      target:
        entity_id: switch.front_yard_lights
    - delay:
        minutes: "{{ states('input_number.front_yard_light_on_minutes') | int(3) }}"
    - action: switch.turn_off
      target:
        entity_id: switch.front_yard_lights
    - delay:
        minutes: "{{ states('input_number.person_detection_debounce_minutes') | int(5) }}"
  mode: single

Testing

After editing YAML:

  1. Run Developer Tools > YAML > Check configuration.
  2. Reload helpers and automations, or restart if you added SMTP.
  3. Confirm the notify service exists under Developer Tools > Actions.
  4. Send a plain email through notify.purelymail_camera_email.
  5. Trigger a short test recording and confirm the video arrives as an attachment.

For a first test, set these helpers to small values:

front_yard_recording_length_seconds: 5
front_yard_recording_lookback_seconds: 0
person_detection_debounce_minutes: 1

That keeps test emails small and avoids waiting through a long cooldown while you are debugging.

Troubleshooting

If the SMTP notify service does not appear after restart, check these first:

  • The SMTP username is the full mailbox address.
  • The password is the mailbox password or app password.
  • The sender address is allowed by the mail provider.
  • Home Assistant was restarted after adding the SMTP notifier.

If email sends but the video is missing:

  • Confirm the clip exists at the video_file path.
  • Keep the clip short enough for your provider’s attachment limit.
  • Check that your mail provider accepts .mp4 attachments.
  • Try a plain text attachment first to prove SMTP attachments work.

If phone alerts or lights do not fire:

  • Confirm input_boolean.front_yard_detection_alerts is on.
  • Confirm the current time falls between front_yard_alert_start and front_yard_alert_end.
  • Check the automation trace for the if block that gates the phone notification.

References


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *