I just got the new camera.snapshot service working with a shock sensor and thought this would be a fun little example for the folks here.
This uses a Monoprice Z-Wave Shock Detector and a D-Link DSC-933L IP camera, but it ought to work with pretty much any sensor and generic camera.
In configuration.yaml:
homeassistant:
whitelist_external_dirs:
- /tmp
camera:
- platform: mjpeg
name: DLink DSC-933L
still_image_url: http://192.168.x.x/image.jpg
mjpeg_url: http://192.168.x.x/video.cgi
username: xxx
password: xxx
In automations.yaml:
- alias: 'Notify when shock sensor triggers'
trigger:
platform: state
entity_id: sensor.shock1_alarm_level
from: '0'
to: '255'
action:
- service: notify.notify
data:
title: 'Shock Sensor'
message: 'Shock detected'
- service: camera.snapshot
data:
entity_id: camera.dlink_dsc933l
filename: '/tmp/shock1.{{ as_timestamp(now()) }}.jpg'
Next step would be to email the photo or add it to an ios: notification. But this works great so far!
Note that your chosen sensor will use some other state change probably - the Monoprice changes from 0 to 255 in āalarm_levelā but their door sensor (for example) changes āaccess_controlā from 23 to 22. You could also use the binary_sensor but I found that these donāt always trip reliably on the Monoprice sensorsā¦