I have an automation that opens/closes a patio umbrella depending on some wind conditions. I created a template condition to de-bounce
the automation if it re-triggers within a certain period of time (60 seconds). The issue i am seeing is that it is still triggering multiple times and my condition does not seem to evaluate. Here is the automation, please excuse all the extra variables and such i was just trying to troubleshoot the issue.
alias: AREA - OUTSIDE - Umbrella actions
description: open umbrella if winds less than 10
triggers:
- entity_id:
- binary_sensor.umbrella_sunrise
from: "off"
to: "on"
id: sunrise
trigger: state
for:
minutes: 1
- entity_id:
- binary_sensor.umbrella_sunset
from: "off"
to: "on"
id: sunset
trigger: state
for:
minutes: 1
- entity_id:
- sensor.pirateweather_wind_gust_0h
- sensor.pirateweather_wind_gust_1h
above: input_number.umbrella_high_wind_limit
id: high_wind_close
trigger: numeric_state
- trigger: state
entity_id:
- sensor.pirateweather_wind_speed_0h
- sensor.pirateweather_wind_speed_1h
- sensor.pirateweather_wind_gust_0h
- sensor.pirateweather_wind_gust_1h
id: wind_changes
conditions:
- condition: state
entity_id: binary_sensor.people_any_family_home
state: "on"
enabled: true
- condition: template
value_template: >
{{ (as_timestamp(now()) -
as_timestamp(state_attr('sensor.global_variables',
'variables')['umbrella_last_triggered'].timestamp | default(0))) >
state_attr('sensor.global_variables',
'variables')['umbrella_debounce_time'].value | int(60)}}
alias: De-Bounce condition
actions:
- variables:
local_debug: false
timestamp_orig: >-
{{ as_timestamp(state_attr('sensor.global_variables',
'variables')['umbrella_last_triggered'].timestamp) }}
debounce_orig: >-
{{ state_attr('sensor.global_variables',
'variables')['umbrella_debounce_time'].value }}
diff_orig: "{{ (as_timestamp(now()) - timestamp_orig) }} "
condition_orig: "{{ diff_orig > debounce_orig }}"
- event: set_global_variable
event_data:
key: umbrella_last_triggered
value: true
set_timestamp: true
alias: Set the timestamp fired
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- variables:
local_debug: false
timestamp_new: >-
{{ as_timestamp(state_attr('sensor.global_variables',
'variables')['umbrella_last_triggered'].timestamp) }}
debounce_new: >-
{{ state_attr('sensor.global_variables',
'variables')['umbrella_debounce_time'].value }}
diff_new: "{{ (as_timestamp(now()) - timestamp_orig) }} "
condition_orig: "{{ diff_new > debounce_new }}"
old_diff: "{{ diff_orig }}"
- target:
entity_id: script.unified_notifications
data:
variables:
title: DEBUG MESSAGE on {{now().strftime('%x at %X')}}
message: "TRIGGERING AUTOMATION: {{this.attributes.friendly_name}}"
method: >-
{{ 'all' if is_state('binary_sensor.people_only_seb_home', 'on') else
'mobile' }}
severity: "{{ 'INFO' if local_debug else 'DEBUG' }}"
group: DEBUG
alias: DEBUG MESSAGE - triggering automation
action: script.turn_on
- choose:
- conditions:
- condition: trigger
id:
- sunrise
- condition: numeric_state
entity_id: sensor.pirateweather_wind_gust_0h
below: input_number.umbrella_high_wind_limit
- condition: numeric_state
entity_id: sensor.pirateweather_wind_gust_1h
below: input_number.umbrella_high_wind_limit
- condition: state
entity_id: cover.deck_umbrella
state: closed
sequence:
- metadata: {}
data: {}
target:
entity_id: cover.deck_umbrella
action: cover.open_cover
enabled: false
- action: script.turn_on
target:
entity_id: script.unified_notifications
data:
variables:
who: seb
severity: INFO
method: voice
alexa_device: media_player.living_room_echo
alert_volume: 0.7
message: >-
It looks like the weather is nice, do you want me to put up
the patio umbrella?
confirm_text: Yes, please put up the umbrella
confirm_action:
- action: script.turn_on
metadata: {}
data:
variables:
who: seb
severity: INFO
method: voice
alexa_device: media_player.living_room_echo
alert_volume: 0.7
message: >-
Ok, i will raise the umbrella in about 2 minutes,
please make sure the strap on the umbrella is
disconnected.
dismiss_text: No, please leave the umbrella down
target:
entity_id: script.unified_notifications
- delay:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- action: script.turn_on
metadata: {}
data:
variables:
who: seb
severity: INFO
method: voice
alexa_device: media_player.living_room_echo
alert_volume: 0.7
message: Opening umbrella now!
target:
entity_id: script.unified_notifications
- action: cover.open_cover
metadata: {}
data: {}
target:
entity_id: cover.deck_umbrella
alias: Open Umbrella
- conditions:
- condition: trigger
id:
- sunset
- high_wind_close
- wind_changes
enabled: true
- condition: state
entity_id: cover.deck_umbrella
state: open
sequence:
- alias: NOTIFICATION MESSAGE - closing umbrella
action: script.turn_on
data:
variables:
who: seb
severity: INFO
method: all
message: >-
Closing the patio umbrella now, please make sure the strap is
connected
group: NOTIFICATION
target:
entity_id: script.unified_notifications
- target:
entity_id:
- cover.deck_umbrella
data: {}
action: cover.close_cover
alias: Close Umbrella
default:
- action: script.turn_on
alias: DEBUG MESSAGE - umbrella not opened cause
data:
variables:
who: seb
severity: INFO
method: >-
{{ 'all' if is_state('binary_sensor.people_only_seb_home', 'on')
else 'mobile' }}
message: >-
umbrella not opened or closed due to weather conditions.
Automation triggered by- {{ trigger.id | default('NO TRIGGER')
}}, wind 0h- {{ states('sensor.pirateweather_wind_gust_0h') }},
wind 1h- {{ states('sensor.pirateweather_wind_gust_1h') }}
group: DEBUG
target:
entity_id: script.unified_notifications
mode: queued
max: 10
Every time the wind forecast updates, I could get up to 4 triggers that happen at the same time. the De-Bounce condition
(copied below) should prevent the automation from continuing, but for some reason it does not. the automation is set to queued
, so my expectation was that it would run on the first occurence of the trigger, then the automation would update the timestamp in the de-bounce condition, and the next run of the automation would not pass that condition. i went as far as adding a small delay in the automation to see if that would fix it, but that doesn’t work either. Anyone have any ideas why it would trigget multiple times?
value_template: >
{{ (as_timestamp(now()) -
as_timestamp(state_attr('sensor.global_variables',
'variables')['umbrella_last_triggered'].timestamp | default(0))) >
state_attr('sensor.global_variables',
'variables')['umbrella_debounce_time'].value | int(60)}}