I have a couple of presence automations that work well though sometimes my HA has a fit and starts triggering the ‘welcome home person’ notifications every few minutes.
Now as I have Alexa announcing this it’s becoming proper annoying, so annoying in fact that the wife has banished me to the couch because my ‘sh*t never works right’ lol
So while I have this recently found time to reflect on a resolution I was wondering if there is a way of preventing an automation from running if it has been run in the last ten minutes … maybe utilising the last triggered event ?
Any pointers would be greatly received as I would like my bed back
In this case it’s not the automation running too often but that presence detection is flapping. You could try to make it more stable, for example by using a combination of device trackers for each person.
To build anti flapping you could read the concept in this openHAB forum thread.
Here is the setup I use to keep my security cameras from turning the lights on when it notices them being turned off. When my camera detects motion, it turns on the light for 5 minutes. When the 5 minutes expires, it set a 1 minute de-bounce timer, then turns off the light. If the de-bounce timer is running when motion is detected, the light won’t turn on.
Added the following to the automations, and i must say its been much better today.
condition:
- condition: template # only notify once every 10 minutes at most
value_template: “{{ ( as_timestamp(now()) - as_timestamp(state_attr(‘automation.andrews_home_notification’, ‘last_triggered’)) |int(0) ) > 3600 }}”
Still getting it happening but its been 3 times through course of today rather than constant yesterday so progress.
Just need to dig into the presence trackers see what is going on.
Move all your actions into a script and call the script as the automation action. Note that is how my actions are done in the example above. The problem seems to be that the last triggered state does not update until all the actions have finished. With that delay in your actions this takes some time and the automation can be retriggered before this happens. It only takes a fraction of a second to call a script. Then the automation is done and the condition should prevent it firing right away again.
# Andrew is home notification
- alias: 'Andrews Home notification'
initial_state: true
trigger:
platform: state
entity_id: person.andrew_vint
from: 'not_home'
to: 'home'
for:
seconds: 60
condition:
- condition: template # only notify once every 10 minutes at most
value_template: "{{ ( as_timestamp(now()) - as_timestamp(state_attr('automation.andrews_home_notification', 'last_triggered')) |int(0) ) > 3600 }}"
action:
- service: notify.all
data:
message: 'Daddy is home YES!'
- service: script.audio_notify
data_template:
tts_msg: "Welcome Home Andrew"
id: turn_on_garden_lights_on_movement_in_the_morning
alias: "Lichten: Tuinverlichting 's morgens aan op beweging"
trigger:
platform: state
entity_id: binary_sensor.det_living
to: "on"
condition:
- condition: and
conditions:
- condition: time
after: "06:00:00"
before: "08:00:00"
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
below: 1
- condition: state
entity_id: light.tuinverlichting
state: "off"
action:
- service: homeassistant.turn_on
entity_id: light.tuinverlichting
My automation is turning on my lights too often, say it starts at 7, and when i want to turn off the lights, cause its clear enough at 7:40, then it autoturns on my light again
How can i make sure this automation only runs once ?
I need to add delay of 2 hours after the action or?
Can someone help with this one ? I have a relay which shouldn’t be switched on more often than 2 times on minute. And only 2 seconds at time.
This is not working…