Queued automation mode not working as expected

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)}}

It isn’t clear from what you’ve posted, but I think at least part of the issue is how you are setting the external variable’s value.

You should be able throttle the automation with the following template:

condition: template
value_template: |
  {% set offset_min = state_attr('sensor.global_variables','variables')['umbrella_debounce_time'].value | int(60) %}
  {{ this.attributes.last_triggered | default(as_datetime(0), 1)
   < now() - timedelta(minutes = offset_min) }}

Your triggers are probably not helping. The numeric state trigger is surplus to requirement if you are also going to trigger off every state and attribute change of the same entities with an open State trigger…

I don’t use Pirate Weather, so I’m not familiar with how it’s sensors update. If it is like other weather integrations, they likely all update at the same time, usually around the top of the hour for hourly forecasts. If that is the case for your integration, I would suggest something like the following instead of the open State trigger shown in you example.

  - trigger: state
    entity_id:
      - sensor.pirateweather_wind_gust_1h
    to:
    for: "00:00:30"
    id: wind_changes
1 Like

regarding the triggers, they are for two different cases, one is a high wind threshold to call a close to the umbrellas, the other was meant to trigger if the wind falls below the wind threshold to open the umbrella, hence no state. i am certain i can simplify the triggers, but in theory, even if they get triggered multiple times, i should not have the automation pass the de-bounce condition.

i guess an explanation on how that variable works is in order. i have a template that takes an event to set variables into the template. below is how that looks. That part is working, i can see the last update time of the variable at the time it is triggered by the automation, so i don’t think it is that.

- trigger:
    - platform: event
      event_type: set_global_variable
    - platform: event
      event_type: remove_global_variable
    - platform: event
      event_type: clear_global_variables
  condition:
    - condition: template
      value_template: >
        {{
            (
              trigger.event.event_type == 'set_global_variable'
              and trigger.event.data is defined
              and trigger.event.data.key is defined
              and trigger.event.data.value is defined
            )
            or
            (
              trigger.event.event_type == 'remove_global_variable'
              and trigger.event.data is defined
              and trigger.event.data.key is defined
            )
            or 
            trigger.event.event_type == 'clear_global_variables'
        }}
  action:
    - if: "{{ trigger.event.data.get('log', state_attr('sensor.global_variables', 'log_events')) }}"
      then:
        - service: logbook.log
          data:
            name: "{{ trigger.event.event_type }}:"
            message: >
              {{ trigger.event.data.key | default('All variables removed') }}
              {%- if trigger.event.event_type == 'set_global_variable' -%}
                : {{ trigger.event.data.value }}.
              {%- endif -%}
  sensor:
    - unique_id: ui_beach_global_variables
      name: Global Variables
      state: Variables
      attributes:
        default_timestamp: false
        log_events: false
        variables: >
          {% set others = dict(
              (this.attributes.get('variables', {}) if this is defined and this.attributes is defined else {}).items()
              | rejectattr('0', 'eq', trigger.event.data.key)
          ) %}
          {% if trigger.event.event_type == 'set_global_variable'
              and trigger.event.data.get('set_timestamp', this.attributes.get('default_timestamp', false))
          %}
            {% set value  = trigger.event.data.value %}
            {% set value = value.isoformat() if value is datetime else value %}
            {% set new = {trigger.event.data.key: {'value': value, 'timestamp': now().isoformat()}} %}
            {{ dict(others, **new) }}
          {% elif trigger.event.event_type == 'set_global_variable' %}
            {% set new = {trigger.event.data.key: trigger.event.data.value} %}
            {{ dict(others, **new) }}
          {% elif trigger.event.event_type == 'remove_global_variable' %}
            {{ others }}
          {% elif trigger.event.event_type == 'clear_global_variables' %}
            {}
          {% endif %}

let me try your suggested condition and see if it works…