Send a notification with a picture when someone enters the house

Hello,

I’ve created an automation which sends an image to my phone when someone enters the house in a given time interval (the cleaning lady)

I am using webcam to take a snapshot of the entrance of my house. It is very easy to setup the webcam on raspberry pi. Use lsusb command to see if your webcam is usable after connecting it through usb. If there is an entry it is usable.
For instance mine has an entry like this, It is an action cam from gearbest.

Bus 001 Device 004: ID xxxx:xxxx Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Silicon Motion Camera

You install with:

sudo apt-get install fswebcam

After that you can play around with fswebcam commands but don’t forget to save the image under www folder. Otherwise the ios notification will not be able to access it. If any one knows a better way they are welcome to contribute.

The configuration parameter to add the webcam. This just takes a snapshot and puts it in folder.

shell_command:
  take_snapshot: fswebcam --no-banner -r 1280x720 /home/pi/.homeassistant/www/image.jpg

Also using the time sensor to get the current time and setup the ios notification service

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
notify:
   - platform: ios
     name: ios
     target: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx

Finaly the automation is as follows:
binary_sensor.door_window_sensor_xxxxxxxxxx is a xiaomi contact sensor which let’s me understand when the door is opened. The cleaning lady comes around 9:30-10. So if the door opens between 9-12 I send a message. The web cam takes a shot 3 seconds after the door is opened to ensure the person enters the house, otherwise it would just be a picture of the door. There is also a 3 seconds delay after the snapshot to ensure that the picture is saved on the pi (it takes around 1 seconds to capture and save the picture)

- id: 'auto33'
  alias: 'If doors opens at (9-12) on monday send message'
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_xxxxxxxxxxxxx
    to: 'on'
  condition:
    condition: and
    conditions:
      - condition: time
        weekday:
          - mon
      - condition: time
        after: '09:00:00'
      - condition: time
        before: '12:00:00'
  action:
  - delay: 00:00:03
  - service: shell_command.take_snapshot
  - delay: 00:00:03
  - service: notify.ios
    data:
      title: 'Cleaning lady'
      message: '{{ states("sensor.date__time") }} Cleaning lady @home'
      data:
        attachment:
          url: https://xxxxxxxx.ddns.net/local/image.jpg
          content-type: jpg
          hide-thumbnail: false

The cleaning lady leaves around 3 o’clock. So I set the automation as follows. There is no delay before taking a snapshot here because the door is being opened from the inside this time.

- id: 'auto34'
  alias: 'If door opens at (12-16) send message'
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_xxxxxxxxxxxx 
    to: 'on'
  condition:
    condition: and
    conditions:
      - condition: time
        weekday:
          - mon
      - condition: time
        after: '12:00:00'
      - condition: time
        before: '16:00:00'
  action:
  - service: shell_command.take_snapshot
  - delay: 00:00:03
  - service: notify.ios
    data:
      title: 'Cleaning gone'
      message: '{{ states("sensor.date__time") }} Cleaning done'
      data:
        attachment:
          url: https://xxxxxx.ddns.net/local/image.jpg
          content-type: jpg
          hide-thumbnail: false   

One thing I don’t like about this setup is that the picture saved in www folder is accessible from the internet, without the need of a password. That is also the reason why ios notification is able to access it. Is there any other method to do this more securely?

Thanks.

2 Likes

If you randomly name the file with a long name it becomes a little more difficult to guess.

1 Like

Great idea. I will definitely use this.