The tittle says it all. I am trying to figure it out with no success.
Here is what I have:
When motion is detected a script triggers. This script is triggering one notify service, one shell command, one counter and one automation (lets call it A). This automation (A), is to take a camera snapshot. << All this is the standard procedure.
Now, I am trying to send the snapshot on my phone only when I am not home. I created another automation (call it B) that sends me the file with success. The problem is that I cant trigger this automation (B) when (A) triggers.
Can it be done or there is another trickier method?
EDIT: Just to clarify, you may need to turn logging to debug to catch the event and use the proper trigger attributes. the service may not be turn_on and the domain may be different as well. But the platform and event_type are correct.
@anon43302295 This was the obvious way to do this and I also thought it would work when I created the automation yesterday. While it triggers the automation, it bypasses the condition (when i am not home) written in automation (B).
@petro Something tells me that your automation will work, but I didnt understand what this is going to do exactly. While I copied your automation, it didnt work but had no errors when I triggered it.
OK… To be more specific I will paste my current configuration here:
scripts.yaml
stairsmotion:
alias: Stairs Camera Motion Detection ON
sequence:
- data:
data:
method: alarm
message: chime
service: notify.jarvis_lenovo
- service: shell_command.cctv_kodi_stairs
- service: counter.increment
entity_id: counter.motioncounter_stairs
- service: automation.trigger
entity_id: automation.sys_stairs_camera_snapshot (this is automation A - it takes the snapshot)
automations.yaml
- id: 'pushsendimagecamerasnapshotfromstairs' <<< (This is Automation B)
alias: '[PUSH] Stairs Camera snapshot Send'
trigger: []
condition:
- condition: state
entity_id: group.presence_tracker
state: home <<< I have this at "home" state for testing purposes. When it works I will have it "not_home"
action:
- delay: 00:00:01
- service: notify.pushbullet
data:
data:
file: '/home/homeassistant/.homeassistant/www/images/snapshot.jpg'
title: Stairs Motion Sensor Triggered
target: device/Argy
message: Take this snapshot of the stairs.
Yes, I’m not sure if the trigger data is correct. I’d have to see event data in the home assistant logs (with debug on) to correctly write the trigger, which is why I mention that in the bottom of the post.
All automation be is doing is triggering when automation.a is fired. They will be executed at the same time essentially.
The difference between the 2 methods is that @anon43302295’s method will fire the automation sequentially. The method I posted should fire them in parallel.
If you don’t want the headache of dealing with the event_data, go with @anon43302295’s solution.
@petro I cant work because of that. It just triggers the automation no matter if I am home or not.
I still want all the things in the script to work no matter what, but when I am not home, I want this extra automation (send me the file) to trigger.
@anon43302295 It looks like it didnt work. It did nothing… not even errors. I tried both “home” and “not_home” for testing purposes.
@petro My log is full of this frustrating “Failed to parse headers” thing when you have a generic camera, so I didnt bother searching for the right part to paste.
Anyway I found another workaround.
I created a boolean booleans.yaml
sendmesnapshots:
name: When on sends photos of camera
initial: off
I added 3 extra lines on the previous script where it turns on the boolean for 5 seconds and then turns it off: scripts.yaml
And then I had automation B sending me the snapshot using the boolean as a trigger and condition when I am not home. Automation A remains the same as before, that means always save the snapshot no matter what.
automations.yaml
- id: 'camerasnapshotfromstairs' <<< **This is automation A**
alias: '[SYS] Stairs Camera snapshot'
trigger: []
condition: []
action:
- service: camera.snapshot
data:
entity_id: camera.stairs
filename: /home/homeassistant/.homeassistant/www/images/snapshot.jpg
- id: 'pushsendimagecamerasnapshotfromstairs' <<< **This is Automation B**
alias: '[PUSH] Stairs Camera snapshot Send'
trigger:
- platform: state
entity_id: input_boolean.sendmesnapshots
to: 'on'
condition:
- condition: state
entity_id: group.presence_tracker
state: not_home
action:
- delay: 00:00:02
- service: notify.pushbullet
data:
data:
file: '/home/homeassistant/.homeassistant/www/images/snapshot.jpg'
title: Stairs Motion Sensor Triggered
target: device/Argy
message: Take this snapshot of the stairs.
This is working for me, but I feel like it could be much simpler. If you guys have another idea, I am willing to discuss it. Thank you for your suggestions so far!
That said, now I think I understand your use case, the second automation is irrelevant. All you need is one automation with a conditional final action…
- id: 'camerasnapshotfromstairs'
alias: '[SYS] 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:02
- service: notify.pushbullet
data:
data:
file: '/home/homeassistant/.homeassistant/www/images/snapshot.jpg'
title: Stairs Motion Sensor Triggered
target: device/Argy
message: Take this snapshot of the stairs
I will try this ASAP! You are an eyeopener! I had no idea this could be done! I have seen the documentation for the actions a lot of times (and the page is small with just 2 examples) but I never really saw how important is the second example! I was just not reading it!
Thank you for your suggestions.
- alias: 0 Close blind at dusk
condition:
- condition: state
entity_id: cover.garden_blinds
state: open
trigger:
platform: numeric_state
entity_id: sun.sun
value_template: '{{ state.attributes.elevation }}'
below: 2
action:
- service: tts.google_say
data:
entity_id: media_player.googlehome5819
message: Hi All, The sun has set, closing the blinds in 3 minutes, please close
the back doors
- delay: 00:03:00
- service: cover.close_cover
entity_id: cover.garden_blinds
Blank lines added just to highlight the changes…
- alias: 0 Close blind at dusk
condition:
- condition: state
entity_id: cover.garden_blinds
state: open
trigger:
platform: numeric_state
entity_id: sun.sun
value_template: '{{ state.attributes.elevation }}'
below: 2
action:
- service: tts.google_say
data_template:
entity_id: media_player.googlehome5819
message: >
Hi All, The sun has set,
closing the blinds in 3 minutes.
{% if is_state('sensor.back_door' , 'open') %}
Please close the back doors.
{% endif %}
- delay: 00:03:00
- service: cover.close_cover
entity_id: cover.garden_blinds