Hey, I’d solve this using an input_boolean to track whether the door was opened first. Then, I’d use two automations:
1. First automation
– If the door opens, it sets the input_boolean to on and keeps it that way for 30 seconds.
2. Second automation
– If motion is detected, it only triggers the voice announcement if the input_boolean is still off.
This way, if the door opens first, the motion sensor won’t trigger any announcement. But if motion is detected first, it will announce as usual.
⸻
1. Create an input_boolean
You can add this in configuration.yaml or through the UI under Helpers:
input_boolean:
door_opened_first:
name: Door Opened First
icon: mdi:door
2. Automation: Mark the door as opened first
If the door opens, we turn input_boolean.door_opened_first on and reset it after 30 seconds.
alias: "Set door opened first"
trigger:
- platform: state
entity_id: binary_sensor.door_sensor
from: "off"
to: "on"
action:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.door_opened_first
# Keep it "on" for 30 seconds before resetting
- delay: "00:00:30"
- service: input_boolean.turn_off
target:
entity_id: input_boolean.door_opened_first
3. Automation: Play voice announcement only if the door wasn’t opened first
alias: "Voice Announcement on Motion"
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor
from: "off"
to: "on"
condition:
# Only continue if the door was NOT opened first
- condition: state
entity_id: input_boolean.door_opened_first
state: "off"
action:
- service: tts.google_translate_say
data:
entity_id: media_player.living_room_speaker
message: "Motion detected!"
How this works:
• If the door opens first, the input_boolean is set to on for 30 seconds.
• If motion is detected while the boolean is on, nothing happens.
• If motion is detected and the boolean is off, the voice announcement plays.
This makes sure the announcement only happens when motion is detected first, but not if the door was opened beforehand.