I am pasting my code below and all the procedures. I hope I wont miss anything. If I do, just tell me what it is, so I will edit my post to keep this clean.
Some notes:
- Names and aliases and entities and paths etc, have to be changed to match yours. I am just pasting mine…
- My automations are split in different files, so the indentation is according to that. Dont be confused. All you have to do is to indent accordingly if you dont have your automations split as I do.
- Deleted usernames or passwords or IPs will be like this: [password]
You will have to replace the brackets too
Here we go:
First of all, you have to create and whitelist the folder where the snapshots will be created.
configuration.yaml
whitelist_external_dirs:
- /home/homeassistant/.homeassistant/www/images
Go to HA and open the side menu. Click on your profile picture and then go to Long-Lived
Access Tokens and create one. Copy the token and paste it in the step below.
Open motioneye and select your camera. Go to Motion Notifications and choose Run A Command.
paste this:
curl -X POST -k -H “Authorization: Bearer [TOKEN]” -H “Content-Type: application/json” -d ‘{“entity_id”: “[script.stairsmotion]”}’ https://[HomeAssistantIP]:8123/api/services/script/turn_on
Now every time MotionEye will detect motion, it will trigger the script you are about to create:
Script
stairsmotion:
alias: Stairs Camera Motion Detection ON
sequence:
- service: automation.trigger
entity_id: automation.stairs_camera_snapshot
The above script, triggers an automation. The reason I am triggering the script and not the automation, is because I have more actions in my sequence, but I am only pasting the automation here.
So, the purpose here is to create a script that will do a series of actions and one of them is take a snapshot and also notify you. And now lets create the automation to get the snapshot and the notification:
Snapshot Automation
- alias: 'Stairs Camera snapshot'
trigger: []
condition: []
action:
- service: camera.snapshot
data:
entity_id: camera.stairs
filename: /home/homeassistant/.homeassistant/www/images/snapshot.jpg
- condition: state
entity_id: group.presence_tracker
state: not_home
- delay: 00:00:01
- service: notify.telegram_argy
data:
message: 'Motion Detected.'
data:
photo:
file: /home/homeassistant/.homeassistant/www/images/snapshot.jpg
caption: 'Motion Detected.'
This Automation will create a snapshot and send it to me via Telegram if I am not home.
I know I could just tell you how to send a file using Telegram, but that wouldnt satisfy my need for sharing my method of using MotionEye, HA and Telegram