Receiving camera snapshots as a notification in the IOS app

Hi first of all I wasn’t too sure which category to put this in but here goes.

When someone rings my doorbell which is an ESP8266 which fires off a MQTT message, i’d like my camera which points at the door to take a snapshot and send it as an IOS notification using the home assistant app to my iPhone.

I have had it setup up previously where it sends a notification with a live feed for the camera, which is no good for me as the person that rung the bell may have left by the time I get to view the notification.

I know there is several threads relating to this already but none seem to have a conclusive answer and the ones I’ve tried just send a notification without a snapshot.

My system is based on ubuntu server with everything in docker containers, using the code below the snapshot gets taken and written to the correct path.

- id: test
  alias: test
  trigger:
  - platform: mqtt
    topic: HOME/doorbell/status
action:
- service: camera.snapshot
  data:
    entity_id: camera.hallway
    filename: /tmp/snapshot1.jpg
- delay: 5
- service: notify.ios_scotts_iphone
  data:
    title: Doorbell
    message: Somebody is at the door
    data:
      photo:
      - file: /tmp/snapshot1.jpg
        capture: Snapshot

This was mostly copied and pasted and then adjusted to fit my use case, I’ll eventually move this automation over to node-red as I like to keep the frontend clean.

thanks
Scott

  - service: notify.ios_myiosdevice
    data_template:
      message: >
         Motion Detected at Front Door
      data:
        attachment:
          content-type: jpeg
          url: "https://MYURL/local/cam_captures/porch_{{ as_timestamp(states.automation.camera_motion_push.attributes.last_triggered)|int }}.jpg"
        entity_id: camera.porch

This is mine…, formatting may not work I’m on mobile… the snapshot uses the trigger time as the name to save also because it was retaking the pic and Overwriting the pertinent one … I believe you need to be able to access from your www dir…

2 Likes

@Scott_Pavey does that actually work outside your local network?

According to the docs you can only send URLs, not actual attachments. And for the image to be available outside your local network it needs to be in the config/www directory.

The other advantage of doing it this way is that you dont need a delay. By the time you receive the notification link the snapshot will be ready. This is my doorbell snapshot automation:

- id: doorbell_alert
  alias: 'Doorbell Alert'  
  trigger:
    entity_id: binary_sensor.doorbell
    platform: state
    to: 'on'
  condition:
    condition: template
    value_template: "{{ (as_timestamp(now()) - as_timestamp(state_attr('automation.doorbell_alert', 'last_triggered') | default(0)) | int > 5)}}"
  action:
  - service: camera.snapshot
    data:
      entity_id: camera.front
      filename: '/config/www/doorbell.jpg'
  - service: notify.all_ios_devices
    data:
      message: Someone has pressed the doorbell.
      data:
        push:
          sound: "Doorbell.wav"
        attachment:
          url: https://mydomain.duckdns.org/local/doorbell.jpg

The condition stops me receiving notifications any more than once every 6 seconds in case an impatient person is hammering on the button.

3 Likes

Hi thanks for the replies, as it happens and probably an oversight is that I don’t want/need my home assistant accessible from outside the network, I use HomeKit / appleTV to control anything I need to externally, of course that means that I won’t get notifications using the home assistant app away from home.

I setup DuckDNS when I used HASSIO and was very straightforward, but now my setup is more complex with the containers and the other components it won’t be as straightforward…

I’ll copy and adapt your automation if I may, I’m guessing replacing the url with my local url should still work when I’m on my home network?

massive thanks to you both, I have it working within my local network, just needed to change the url to http://192.168.1.81:8123/local/doorbell.jpg.

Now I better try and get the external access sorted.

Actually I think you will still be able to receive notifications as the push server can maintain a connection between your phone and HA.

You won’t be able to view or control your system from outside your local network though. And actionable notifications will not work outside your network.

Any of you move this over to Node Red yet? Would like to see how you created the notification and formatted the the code for including the picture.

I did move it over to node-red see below, I haven’t had a chance to fine tune it yet but it works as needed, the delay is there to make sure the picture is saved to file before the notification is sent to the iOS app.

this is what is inside the data field in the notify node

{"data": { "attachment": { "url": "http://192.168.1.81:8123/local/doorbell.jpg" }, "push": { 			"sound": "Doorbell.wav" } }, "message": "Someone has pressed the doorbell." }
1 Like

Hi Tom,

I got this to work using your code however when I tap the notification it opens the ios app but that’s it. I was expecting it to show a larger pic from the notification. Is that not the case?

On my iPhone 7 Plus, I press and hold the notification and a larger picture pops up, this may be a feature only of 3D Touch so I don’t know, if I simply tap on the notification it opens the home assistant app

For older phones without 3D touch swipe left.

That worked thanks. Silly that I didn’t try that.

Any way to receive snapshot of camera without opening a port on my router?

Yes, use the cloud component.
https://www.nabucasa.com/

Thanks for the recommendation, I am already using nabu casa, but only for Google Assistant. What should I look for, webhooks?

I’ll try to test it tomorrow but webhooks sounds about right.

1 Like

This is correct. My Home Assistant is only working on IPv6 and my iphone when on 4G only does IPv4. Yet I do get HA notifications as per normal. This is awesome actually. Using the iOS app and siri doesn’t work though as it needs a connection direct to the HA Server. I can use Google Assistant as per normal though.

I can confirm that I can receive notifications on external network (4G) trough Nabu Casa, but attached camera image is not going trough.

1 Like

Were you able to get anywhere with webhooks?

I was able to get camera snapshots to work using Nabu Casa as suggested. First, make sure you have the cloud component enabled AND active!

In configuration.yaml:

  whitelist_external_dirs:
    - /opt/homeassistant/config/www/tmp

For the automation:

- alias: doorbell pressed, send notification
  trigger:
    - platform: state
      entity_id: binary_sensor.doorbell
      to: 'on'
  action:
    - service: camera.snapshot
      data:
        entity_id: camera.frontdoor
        filename: "/opt/homeassistant/config/www/tmp/snapshot.jpg"
    - service: notify.ios_phone
      data:
        title: "Doorbell"
        message: "Ding dong..."
        data:
          attachment:
            content-type: jpeg
            url: "https://MYNABUINSTANCE.ui.nabu.casa/local/tmp/snapshot.jpg"
2 Likes