I saw a few similar questions posted here, but the answer seem to direct to the for:
directive. Here is what I’m trying to achieve. I have an automation based on my Unifi G4 Pro doorbell. If the doorbell detects a person, it sends a picture to my phone, sends a picture to the tv and plays an alert on the Google home. This works well, but it also alerts if I walk out the front door. I’d like to prevent that. What I was thinking was if the front door had been unlocked within the last X seconds, then that means I probably left the house. The state of the lock when the doorbell sees me may be locked though, so I don’t want to just check that it’s unlocked for X seconds. I want to say, was it changed from locked to unlocked within the last X seconds. How can I add that into the conditions?
Thanks!
Here’s my current automation in YAML:
alias: Front Door - Person Detected
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.front_door_person_detected
from: "off"
to: "on"
condition: []
action:
- parallel:
- service: shell_command.get_image_full
data:
entity_id: sensor.front_door_camera_snap
ha_token: xyz
ha_url: xyz
img_ext: jpeg
img_url: http://192.168.2.36/snap.jpeg
save_loc: /mnt/ha_www_images/
alias: Get Image
- type: turn_on
device_id: a9af91ad9b9edd85013e47022d41934f
entity_id: light.porch_light
domain: light
enabled: true
- parallel:
- service: media_player.play_media
target:
entity_id: media_player.kitchen_display
data:
media_content_id: media-source://tts/google_translate?message=Person
media_content_type: provider
metadata:
title: Doorbell
thumbnail: https://brands.home-assistant.io/_/google_translate/logo.png
media_class: app
children_media_class: null
navigateIds:
- {}
- media_content_type: app
media_content_id: media-source://tts
- media_content_type: provider
media_content_id: media-source://tts/google_translate?message=Person
- service: notify.living_room_tv
data:
message: Person Detected
title: Home Assistant
data:
color: grey
duration: 5
image:
url: http://192.168.2.36/snap.jpeg
fontsize: large
interrupt: 1
position: bottom-right
transparency: 25%
alias: Put image on TV
- service: shell_command.notify
data:
message: Person at front door
space: xyz
file_name: "{{ states('sensor.front_door_camera_snap') }}"
token: xyz
type: image
alias: Send to Phone
enabled: true
enabled: true
mode: single