I have an automation which triggers my home alarm when a security sensor is triggered. I’d like to extend it by sending a screenshot from the relevant security camera to my phone, depending on which sensor was triggered. For example, if the motion sensor in the kitchen is triggered I want to send a snapshot from the kitchen camera. If the lounge motion sensor is triggered I want to send a snapshot from the lounge camera.
I currently use this code (in a script) to send a snapshot to my phone from my doorbell camera when someone presses the doorbell:
- service: camera.snapshot
data:
filename: /config/www/doorbell_snapshot.jpg
target:
entity_id: camera.doorbell
- service: notify.mobile_app_moto_g_5g_plus
data:
message: Someone at the front door
title: Doorbell Pressed
data:
image: /local/doorbell_snapshot.jpg
I want to add similar logic to the automation below, which currently triggers the home alarm when any of the security sensors are triggered. Any idea whether/how I can add logic which sends a specific camera snapshot depending on which sensor triggered the alarm?
alias: Trigger alarm while armed (home or away)
trigger:
- platform: state
entity_id: binary_sensor.pir_kitchen
to: "on"
- platform: state
entity_id: binary_sensor.kitchen_window
to: "on"
- platform: state
entity_id: binary_sensor.kitchen_window
to: "off"
- platform: state
entity_id: binary_sensor.kitchen_external_door
to: "on"
- platform: state
entity_id: binary_sensor.front_door
to: "on"
- platform: state
entity_id: binary_sensor.lounge_sliding_doors
to: "on"
- platform: state
entity_id: binary_sensor.lounge_sliding_doors2
to: "on"
- platform: state
entity_id: binary_sensor.pir_study
to: "on"
- platform: state
entity_id: binary_sensor.pir_lounge
to: "on"
- platform: state
entity_id: binary_sensor.pir_garage
to: "on"
- platform: state
entity_id: binary_sensor.garage_internal_door
to: "on"
condition:
- condition: or
conditions:
- condition: state
entity_id: alarm_control_panel.home_alarm
state: armed_away
- condition: state
entity_id: alarm_control_panel.home_alarm
state: armed_home
action:
- service: alarm_control_panel.alarm_trigger
entity_id: alarm_control_panel.home_alarm
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.alarm_triggered
mode: single
Should be possible, I guess a lot will depend on what type of cameras you have, how they have been added, local / cloud etc.
I would start by giving each trigger an ID, so for example if you are looking to send a pic from a the same 1 kitchen camera when any of the kitchen triggers give them all an trigger ID the same (kitchen) for example.
Then you could use a choose option in the actions to choose what actions to take depending on what the trigger id was / is.
With regards the snapshot I guess it depends on make, integration etc. But don’t forget you could use the snapshot service (assuming your cameras support this), have the choose action take a snapshot from the appropriate camera and maybe then a small delay and a follow up action to send the snapshot you have just saved.
Lots of variables here, so just spitting out some randoms thoughts really
Thanks for that - using trigger id’s in that way sounds like a good idea. I didn’t know that multiple triggers could use the same id. I’ll also look into the Choose Option syntax - I actually hadn’t come across it before.
I was wondering whether there was any way of passing a parameter/variable to a script? I was thinking I could then repurpose the script that I have for the doorbell press, so that I can use the snapshot notifications in other contexts when I need to? The idea would be to pass the name of the camera to the script.
Yes there is and that would make sense, I have only dabbled in passing variables to scripts so probably not gonna be much help there, but most of what you need can be found here:
Thanks for the link. It explains how to declare and use variables within a script, but doesn’t seem to explain how a variable can be passed to a script (e.g. from an automation, or from another script)??
Thanks. I’ve been playing around with it but I haven’t managed to pass the trigger id as a parameter to the script, which would be the most efficient way of doing this.
I’ll open a separate thread with more specific query about passing variables/parameters to scripts