Disable Voice Annoucement If Door Opens FIRST

Hi all,

I have setup an automation where if a person is detected at my front door, Alexa will announce that someone is at the door. I also have a helper toggle so that I can temporarily disable that (ie: mowing the lawn…etc).

My question is, is there a way to disable this announcement but only if the front door opens first. I want to make sure it keeps working for people approaching the front door but if I leave the house, it still does it which is the scenario I’d like to turn off or disable the announcement but only for a few seconds.

I thought of creating a helper if the door contact senses the door open, I can toggle a helper and then reference the toggle in my automation but I wonder if anyone has figured out a better way to do this. This feels…cumbersome so I thought I’d check with this group of experts first.

Add a condition, e.g. if the door contact changed more than 60 seconds ago, this will allow the actions to occur:

conditions:
 - condition: template
   template: "{{ as_datetime(states.door_contact.last_changed) > now() - timedelta(seconds=60) }}"
2 Likes

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.

1 Like

Really?

Two automations and a helper instead of one condition?

That’s the solution. :smiley: yes, it can be done differently.

Thank you both. I’ll give each of those options a try later today and will come back to flag the suggestion I went with. Much appreciated.

Unfortunately, I was unable to get the template to return the last event datetime. I have Third Reality contact sensors connected via a Tuya Matter integration and the only parameters available to me are open/closed and battery (which is always at 100%). I do see the data in the logs with timestamp of last series of state changes but nothing that appears accessible to me.

Every home assistant entity has a last_changed property , note this in not an attribute hence having to access it via the state object in my post above.

See: Last_updated State and last-changed in Lovelace - #2 by petro

Sweet! I was able to get that, thanks. Now the problem is the time is 4hrs off. It shows the last state change a few minutes ago at 5:36PM as 9:36PM.

This is my timezone setting…

And this is the output of the template…

I’ve even rebooted the VM running HAOS but doesn’t matter. The time remains 4hrs off which suggests this is likely happening for all logged events.

Any suggestions on how to fix this time issue? If I can get that to work correctly, then I will have a solution to my voice message.

It is shown in UTC. Your time zone is UTC - 4

The template is time zone aware. It should not matter. But if it does then do this:

template: "{{ as_datetime(states.door_contact.last_changed)|as_local > now() - timedelta(seconds=60) }}"

You rock! That did the trick. Much appreciated!

You should not need it. I just tested it. Both the templates return the same result because the template is aware of the time zone:

template: "{{ as_datetime(states.door_contact.last_changed) > now() - timedelta(seconds=60) }}"
template: "{{ as_datetime(states.door_contact.last_changed)|as_local > now() - timedelta(seconds=60) }}"
1 Like