How to add a Camera Stream in Home Assistant


When my alarm triggers I would like to know if it is a false alarm or not. The best way is to have eyes on the ground. I will show you how you can take a camera stream and show it on your smartphone. I will also be adding in a silence button to de-activate the alarm.

 

What do I need to add a Camera Stream in Home Assistant

  • Home Assistant
  • An IP camera that is integrated into home assistant I’m using a Unifi Flex camera running on Unifi Protect
  • Smartphone with home assistant installed and notifications enabled
  • External Home Assistant instance

 

How to add to a White List in Home Assistant

First step go to your file editor and add a folder in the www folder under config. My folder is called photos, thereby my full path is /config/www/photos

Now we need to whitelist that folder in home assistant. Go to your configuration.yaml file and add the following:

homeassistant:
whitelist_external_dirs:
- /config/www/photos/

you might already have homeassistant in your config file.

Actionable Notifications on IOS in Home Assistant

This is specific to IOS, similar for android you can find the syntax here

The SILENCE_ALARM will be used when we are looking for the ios notification event in the last part of this post when we disarm the alarm.

Identifier ‘camera’ is used in our initial notification when we send the camera stream. Important setting to note is the authenticationRequired:true which means that you need to unlock your phone to silence an alarm. An extra security feature.

 

configuration.yaml

ios:
  push:
    categories:
        - name: Camera With Actions
          identifier: 'camera'
          actions:
            - identifier: 'SILENCE_ALARM'
              title: 'Silence Alarm'
              activationMode: 'background'
              authenticationRequired: true
              destructive: false
              behavior: 'textInput'
              textInputButtonTitle: 'Silence!'
              textInputPlaceholder: 'Send Text'

 

Restart HASS and then restart server and check on your app in the notification section that you can see ‘Camera With Actions’

Home Assistant Automation with Camera Stream and Alarm Silence Button

In your automations file create the following automation to send a notification when the alarm is triggered in the kitchen.

I’m using a binary sensor to find out if there is motion (to: ‘on’), condition is that the alarm panel is currently in triggered mode.

Our action is to take a snapshot of the camera with the service camera.snapshot, we need to pass the entity_id of the camera and the location in the filename.

The second service sends the notification out to your smartphone (change this accordingly). The test I’m using is “There is motion in the kitchen”, in the URL part of the attachment fill this in with your own details (externally exposed URL), I’m using Nabu Casa, which is a paid service at around $5 a month. The filename I’m using is uvc_flex.jpg feel free to change this too.

The push part of the automation enables the camera stream and the custom button set in the actionable notification.

alias: Send notifications when alarm is triggered in the kitchen
trigger: 
  - platform: state
    entity_id: binary_sensor.kitchen_motion_sensor
    to: 'on'
condition: 
  condition: state
  entity_id: alarm_control_panel.home_alarm
  state: 'triggered' 
action: 
  - service: camera.snapshot
    data: 
      entity_id: camera.uvc_flex
      filename: '/config/www/photos/uvc_flex.jpg'
  - service: notify.mobile_app_giordano_s_iphone_7
    data: 
      message: "There is motion in the kitchen"
      data: 
        attachment: 
          url: "https://YOURURL.ui.nabu.casa/local/photos/uvc_flex.jpg"
          content-type: jpeg
          hide-thumbnail: false
        push:
          category: camera
        entity_id: camera.uvc_flex

Silence an alarm panel in Home Assistant

To complete this project we need to read from the events and capture the SILENCE_ALARM actionName. This will trigger the alarm_disarm service to turn off the alarm.

You need to pass the entity id for the alarm panel and the secret code, which I stored in the secrets.yaml file.

alias: 'Silence Alarm'
trigger:
  platform: event
  event_type: ios.notification_action_fired
  event_data:
    actionName: SILENCE_ALARM
action:
  service: alarm_control_panel.alarm_disarm 
  data: 
    entity_id: alarm_control_panel.home_alarm
    code: !secret alarm_code

 

Gio

Gio loves rabbits, smart home tech, WWII, travelling to Thailand & my favourite pizza is margherita with parma ham!

Recent Posts