Stop sensor repeating once triggered

Hi
First post and a total noob -
I have an automation for a motion sensor to trigger a google home text to voice message that 'there is someone at the gate"
It works well but
Once it has triggered - it will retrigger straight away - i.e. each time the sensor goes off and on again because the someone has not moved away yet. -
So the voice assistant keeps on informing me that there is someone at the gate - this get annoying.
.
How does one stop an automation from triggering for a few minutes once it has triggered the first time and then to resume the notifications once all has calmed down again. (say 5 minutes later)
Any assistance would be greatly appreciated
Thanks
Neil

Add action to set a boolean to on.
Then add this boolean as a condition so that it does not trigger when on.

Add a second automation that triggers when boolean is on ‘for 5 minutes’, action turn off the boolean.

Thanks - let me look into that
I am trying to figure out why I cannot get this and condition to work:

value_template: "{{ as_timestamp(now()) - as_timestamp(state_attr('automation.motiondetected', 'last_triggered')) | int > 10 }}"

So the action wont be invoked within 10 seconds of the automation being triggered - but as soon as I put this in then the automation doesnt work -
I am concerned it may be an incorrect time zone issue as the developer tools section shows the automation triggering on UTC time.

So maybe adding a boolean switch may be a better option - but the above is bugging me

What happens if you add them on different lines in the templates tool?
What does the values show?

I am not quite sure what you mean ? (sorry still learning so any information / advice is greatly appreciated

But the suggestion you made re- the boolean switch is working - so thank you for that - would still be interested in what you mean by putting them on different lines on the template tool

Thanks

So I worked out what you meant and placed the now() and last triggered attributes in the template tool and I got this:

value_template: "2020-10-28 22:24:06.634092+02:00"
value_template: "2020-10-28 20:17:21.350446+00:00"

So now is my local time zone (22:00) and last triggered is UTC time zone (20:00) - so this condition will never be true - the question is what to do?

If you add the as_timestamp() around the variable then you should get times that is close to each other.

Or just try

value_template: "{{ as_timestamp(now()) - as_timestamp(state_attr('automation.motiondetected', 'last_triggered')) | int }}"

And let’s see how many seconds it thinks there is between the two.

Great that you got the boolean method to work.

Hi
Thanks for all your help on this - if I run this:

now:            {{(now())}}
Time stamp now: {{as_timestamp(now())}}

Last Triggered:             {{(state_attr('automation.detect_motion', 'last_triggered'))}}
Time stamp Last triggered:  {{as_timestamp(state_attr('automation.detect_motion', 'last_triggered'))}}

Difference: {{ as_timestamp(now()) - as_timestamp(state_attr('automation.motiondetected', 'last_triggered')) | int }}

{{ utcnow() }}
{{ now() }}
{{ utcnow().astimezone() }}
{{ now().astimezone() }}
{{ utcnow().tzinfo }}
{{ now().tzinfo }}
{{ now().astimezone().tzinfo }}

I get this response

now:            2020-10-29 09:21:54.544020+02:00
Time stamp now: 1603956114.544284

Last Triggered:             2020-10-29 07:21:48.927104+00:00
Time stamp Last triggered:  1603956108.927104

Difference: 1603956114.545055

2020-10-29 07:21:54.545860+00:00
2020-10-29 09:21:54.546025+02:00
2020-10-29 09:21:54.546251+02:00
2020-10-29 09:21:54.546673+02:00
UTC
Africa/Johannesburg
SAST

So it appears that Now is in the correct time zone abut last triggered is in UTC
I am not sure how to interpret the difference

The thing is that when you use as_timestamp it should convert to UTC.

Looking at time stamp now vs last triggered you see the difference is seconds.
Yet the difference is… Way more.

Try this:

Difference: {{ (as_timestamp(now()) - as_timestamp(state_attr('automation.motiondetected', 'last_triggered'))) | int }}

Meaning wrapping the “math” in () before converting to int

A direct copy gives me the error
TypeError: unsupported operand type(s) for -: ‘float’ and ‘NoneType’

Will see if I can fix as wellI
I think then you have to convert both to int - tried toadd the " | int " for Now but the difference is still big

am going to try this:

{{ as_timestamp(utcnow()) - as_timestamp(state_attr('automation.motiondetected', 'last_triggered')) | int }}

So using utcnow rather than now solves the problem

However - I prefer the boolean switch option as this gives me the ability to display the boolean switch on the dashboard and switch it on / off as required

1 Like