Doorbell - Notify Google and send camera snapshot to app

Tags: #<Tag:0x00007f3274364428> #<Tag:0x00007f3274364338>

Blueprint to make a TTS announcement when a binary sensor goes from off to on, e.g. a doorbell sensor and to take a snapshot from a camera and send it to your official home assistant mobile app.

You can select a binary sensor, a google device to make the announcement and customise the announced message, a camera, a mobile device to receive the snapshot as a notification (either android or iOS) and customise the notification title and message.

You can announce to multiple devices by inputting a comma separated list or a group.

Blueprint screen:

Blueprint to import:

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Doorbell - Notify Google and send camera snapshot to app
  description: 'Make an announcement over Google devices when the doorbell is pushed and send a camera snapshot to your app.'

  domain: automation
  input:
    doorbell:
      name: Doorbell
      description: This is the doorbell binary sensor
      selector:
        entity:
          domain: binary_sensor
    google_device:
      name: Google
      description: The Google device to make the announcement on. Make a comma seperated list to announce on multiple devices.
      selector:
        entity:
          domain: media_player
      default: ""
    message:
      name: Message (Optional)
      description: 'Default: "There is Somebody at the Door!"'
      default: There is Somebody at the Door
    camera:
      name: Camera
      description: The camera which creates the snapshot
      selector:
        entity:
          domain: camera
    notify_device:
      name: Device to notify
      description: Device needs to run the official Home Assistant app to receive notifications
      selector:
        device:
          integration: mobile_app
    is_ios:
      name: Is it an iOS device?
      description: Toggle if your selected device runs iOS, default is Android
      selector:
        boolean:
      default: false
    notification_title:
      name: Notification title (Optional)
      description: 'Default: "There is Somebody at the Door!"'
      default: "There is Somebody at the Door!"
    notification_message:
      name: Notification message (Optional)
      description: 'Default: "There is Somebody at the Door!"'
      default: "There is Somebody at the Door!"      
    delay:
      name: Delay (Optional)
      description: Wait before creating camera snapshot
      default: ""
      selector:
        number:
            min: 0
            max: 60
            unit_of_measurement: seconds
            mode: slider

  source_url: https://gist.github.com/seamus65/fd6d9341f0f8be76d8b81c2e3ef03624

mode: single

trigger:
- platform: state
  entity_id: !input 'doorbell'
  from: "off"
  to: "on"

variables:
  camera: !input camera
  notify_device: !input notify_device
  is_ios: !input is_ios
  notification_title: !input notification_title
  notification_message: !input notification_message
  delay: !input delay
  snapshot_create_file_path: "/config/www/tmp/snapshot_{{ states[camera].object_id }}.jpg"
  snapshot_access_file_path: "{{ snapshot_create_file_path | replace('/config/www','/local') }}"

action:
  - service: tts.google_translate_say
    data:
      entity_id:
        - !input 'google_device'
      message: !input message

  - delay: "{{ delay }}"

  - service: camera.snapshot
    entity_id: !input camera
    data:
      filename: "{{ snapshot_create_file_path }}"

  - device_id: !input notify_device
    domain: mobile_app
    type: notify
    title: "{{ notification_title }}"
    message: "{{ notification_message }}"
    data: >
      {% set android_data = {"image": "%s"} | format(snapshot_access_file_path) %}
      {% set ios_data = {"attachment": {"url": "%s", "content_type": "JPEG"}} | format(snapshot_access_file_path) %}
      {{ ios_data if is_ios else android_data }}

5 Likes

Thanks! Getting an error though:

Logger: homeassistant.components.automation.doorbell_notify_google_and_send_camera_snapshot_to_app
Source: helpers/script.py:1138
Integration: Automation (documentation, issues)
First occurred: 9:15:59 PM (1 occurrences)
Last logged: 9:15:59 PM

Doorbell - Notify Google and send camera snapshot to app: Error executing script. Service not found for call_service at pos 1: Unable to find service tts.google_say
1 Like

Try changing
tts.google_say
to
tts.google_translate_say

I have this in my configuration.yaml

tts:
  - platform: google_translate
    service_name: google_say

You would need to check what you have as yours.

I have changed the blueprint to tts.google_translate_say as that is the default

1 Like

The default configuration is `tts.google_translate_say’, so if you are sharing, its best to stick to default naming, otherwise everyone will have the same problem as @luchtgitaar

I have changed it. Didn’t realise as that has been in my config for 4 years.

2 Likes

I haven’t used blueprints yet, but I do like how you’ve added a ‘variables’ section in there. That does make things much easier :blush:

I have been playing with them since the conference, I am not involved in the creation of blueprints, but it does feel good to be able to give back some to the community.

I think blueprints could be hugely powerful for a lot of people.

Thanks. I am getting a different error now. Also I am not able to select groups or comma separate devices. I have same sort of automation in NodeRed now, so thanks for your hard work settings this up in HA itself.

Logger: homeassistant.components.automation.doorbell_notify_google_and_send_camera_snapshot_to_app
Source: helpers/script.py:1138
Integration: Automation (documentation, issues)
First occurred: 10:22:39 PM (2 occurrences)
Last logged: 10:23:26 PM

Doorbell - Notify Google and send camera snapshot to app: Error executing script. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data['entity_id']
Logger: homeassistant.components.automation.doorbell_notify_google_and_send_camera_snapshot_to_app
Source: core.py:1399
Integration: Automation (documentation, issues)
First occurred: 10:22:39 PM (1 occurrences)
Last logged: 10:22:39 PM

While executing automation automation.doorbell_notify_google_and_send_camera_snapshot_to_app
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 404, in async_trigger
    await self.action_script.async_run(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1026, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 242, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 250, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 457, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1399, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: not a valid value for dictionary value @ data['entity_id']

I have raised a PR on the documation, as the service name in the example configuration.yaml shows the incorrect name, which may lead to issues with blueprints.
https://github.com/home-assistant/home-assistant.io/pull/15995

I have a similar but perhaps more advanced system if you want to copy?
The main differences:

  1. I broadcast the local doorbell message, only when we are at home.
  2. I cast the camera to local media devices, I.E Google Homes (I did also try the TV, which was fun), only we are at home.
  3. Device notify is via pushover and is split into two messages, text only, then the image, so the image does not delay the message (saves ~5 seconds).

My Home Assistant Configuration

House Doorbell Button Local Notify

alias: House Doorbell Button Local Notify
description: >-
  CCTV needs to have anonymous viewer enabled or I need to pass the username in
  the media_content_id. Note, during testing you need to turn off the
  media_player device after each test, else is will not show the video again.
trigger:
  - device_id: b03ab12c707340e8849888171a79caed
    domain: binary_sensor
    entity_id: binary_sensor.doorbell_button
    platform: device
    type: turned_on
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: person.richard
        state: home
      - condition: state
        entity_id: person.lucy
        state: home
action:
  - data:
      cache: false
      entity_id: media_player.living_room_speaker
      message: Ding! Dong! Someone is at the door
    service: tts.google_translate_say
  - data:
      media_content_id: 'http://192.168.4.11/axis-cgi/mjpg/video.cgi'
      media_content_type: image/jpg
    entity_id: media_player.office_display
    service: media_player.play_media
  - data:
      media_content_id: 'http://192.168.4.11/axis-cgi/mjpg/video.cgi'
      media_content_type: image/jpg
    entity_id: media_player.bedroom_display
    service: media_player.play_media
  - data:
      media_content_id: 'http://192.168.4.11/axis-cgi/mjpg/video.cgi'
      media_content_type: image/jpg
    entity_id: media_player.kitchen_display
    service: media_player.play_media
  - data:
      cache: false
      entity_id: media_player.lucys_room_speaker
      message: Ding! Dong! Someone is at the door
    service: tts.google_translate_say
  - data:
      cache: false
      entity_id: media_player.garage
      message: Ding! Dong! Someone is at the door
    service: tts.google_translate_say
mode: single

and

House Doorbell Button External Notify

alias: House Doorbell Button External Notify
description: 'https://github.com/home-assistant/core/issues/32236'
trigger:
  - device_id: b03ab12c707340e8849888171a79caed
    domain: binary_sensor
    entity_id: binary_sensor.doorbell_button
    platform: device
    type: turned_on
condition: []
action:
  - data:
      message: Ding Dong! Someone is at the door. Get the biohazard suit out!
      title: Doorbell Alert☣️
    service: notify.pushover_notify_doorbell
  - data:
      filename: /config/www/tmp/front_door.jpg
    service: camera.snapshot
    entity_id: camera.front_door_11
  - data:
      data:
        attachment: /config/www/tmp/front_door.jpg
      message: Photo of the infectious!
      title: Doorbell CCTV Photo
    service: notify.pushover_notify_doorbell
mode: single

1 Like

Nice. Thank you

@seamus65, are you able to add a variable to raise the volume to a predefined level for the Google device?
Perhaps some basic logic as follows:

  1. turn on the Google device
  2. get the original volume level
  3. set a new volume level
  4. play TTS
  5. set original volume level

I’ll spend 5 mins looking at it now myself & might post back…

Maybe something like this using a scene?

blueprint:
  name: Doorbell - Notify Google and send camera snapshot to app
  description: Make an announcement over Google devices when the doorbell is pushed
    and send a camera snapshot to your app.
  domain: automation
  input:
    doorbell:
      name: Doorbell
      description: This is the doorbell binary sensor
      selector:
        entity:
          domain: binary_sensor
    google_device:
      name: Google
      description: The Google device to make the announcement on. Make a comma seperated
        list to announce on multiple devices.
      selector:
        entity:
          domain: media_player
      default: ''
    message:
      name: Message (Optional)
      description: 'Default: "There is Somebody at the Door!"'
      default: There is Somebody at the Door
    camera:
      name: Camera
      description: The camera which creates the snapshot
      selector:
        entity:
          domain: camera
    notify_device:
      name: Device to notify
      description: Device needs to run the official Home Assistant app to receive
        notifications
      selector:
        device:
          integration: mobile_app
    is_ios:
      name: Is it an iOS device?
      description: Toggle if your selected device runs iOS, default is Android
      selector:
        boolean: {}
      default: false
    notification_title:
      name: Notification title (Optional)
      description: 'Default: "There is Somebody at the Door!"'
      default: There is Somebody at the Door!
    notification_message:
      name: Notification message (Optional)
      description: 'Default: "There is Somebody at the Door!"'
      default: There is Somebody at the Door!
    delay:
      name: Delay (Optional)
      description: Wait before creating camera snapshot
      default: ''
      selector:
        number:
          min: 0.0
          max: 60.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
    volume:
      name: Volume (Optional)
      description: Volume for announcement
      default: ''
      selector:
        number:
          min: 0
          max: 100
          unit_of_measurement: "%"
          mode: slider
          step: 5
  source_url: https://community.home-assistant.io/t/doorbell-notify-google-and-send-camera-snapshot-to-app/257953
mode: single
trigger:
- platform: state
  entity_id: !input 'doorbell'
  from: 'off'
  to: 'on'
variables:
  camera: !input 'camera'
  notify_device: !input 'notify_device'
  is_ios: !input 'is_ios'
  notification_title: !input 'notification_title'
  notification_message: !input 'notification_message'
  delay: !input 'delay'
  volume: !input 'volume'
  snapshot_create_file_path: /config/www/tmp/snapshot_{{ states[camera].object_id
    }}.jpg
  snapshot_access_file_path: '{{ snapshot_create_file_path | replace(''/config/www'',''/local'')
    }}'
action:
- service: media_player.turn_on
  data:
    entity_id:
    - !input 'google_device'
- delay:
    seconds: 1
- service: scene.create
  data:
    scene_id: before
    snapshot_entities:
    - !input 'google_device'
- service: media_player.volume_set
  data:
    entity_id:
    - !input 'google_device'
    volume_set: '{{ volume }}'
- service: tts.google_translate_say
  data:
    entity_id:
    - !input 'google_device'
    message: !input 'message'
- delay: '{{ delay }}'
- service: camera.snapshot
  entity_id: !input 'camera'
  data:
    filename: '{{ snapshot_create_file_path }}'
- device_id: !input 'notify_device'
  domain: mobile_app
  type: notify
  title: '{{ notification_title }}'
  message: '{{ notification_message }}'
  data: '{% set android_data = {"image": "%s"} | format(snapshot_access_file_path)
    %} {% set ios_data = {"attachment": {"url": "%s", "content_type": "JPEG"}} | format(snapshot_access_file_path)
    %} {{ ios_data if is_ios else android_data }}'
- service: scene.turn_on
  data:
    entity_id: scene.before
    transition: 2.5

Is there a way that this automation can be setup with the following:

  1. Music player is playing some music like a radio station of spotify.
  2. someone rings de doorbel and google uses TTS to tell that there is someone at the door.
    3.Music player goes back to the music services that was playing.
1 Like

That is how it works with Alexa, but I haven’t been able to check with Google yet.

I tried it here.

when there is music playing and the automation is triggerd the TTS speaks, but never returns to the music that was playing before the TTS.

Sorry, I am not as experienced with the google devices and can’t see how to do it.

i almost have the same setup, except a nice addition would be to show snapshot on nesthub or chromecast for 1 minute , which i have setup.