Sensor Automation #2

Hello everyone, I have 2 door sensors, one at the main gate and one at the front door, today I get an alert as soon as someone opens the main gate, I want to automate that as soon as someone opens the main gate Alexa will say “Someone at the main gate” in TTS (and the action I Know how to do)
But there’s a problem here because it’s a bit complicated, I do not want Alexa to say that I leave the house, sometimes my girlfriend sleeps and I go to work, I do not want the action to be taken if someone leaves the house, what to need to do Seconds, then the action RUN,
If the main door is opened in the last 30 seconds the automation will not work.

thank you very much

Does this return anything in template tool?

{{ states.sensor.door.last_changed }}

Yes, show me the last change

Maybe you can check if you are in the house, the alert its not firing. but if you are not, then fire the alert. this can be done if your phone its already connected to your wifi or not.

In that case you could probably have a template condition:

{{ (now().timestamp() -  as_timestamp(states.sensor.door.last_changed))/60 > 30 }}

Doesn’t that amount to 30 minutes (not seconds)?

1 Like

Ohh… Yes… I was not in a clear state of mind there…

Remove the /60 part.

1 Like

Can you write me all the automation?
I can 't do it right

It’s hard for when we don’t know the entity names and types,but here is some assumptions.

alias: New Automation
description: ''
mode: single
trigger:
  - platform: state
    entity_id: binary_sensor.gate
    to: 'on'
condition:
  - condition: template
    value_template: >
      {{ (now().timestamp() - 
      as_timestamp(states.binary_sensor.door.last_changed)) > 30 }}
action:
  - service: tts.cloud_say
    data: something....

thank you! its working