Actionable automation with timeout for an auto (or manual) garage door opener

Hi all,

I’m having a couple of issues with an automation that automatically opens my over-head garage door. It will open my garage door under these conditions:

  1. I press the open door now button within 4 minutes of being close to home (i.e less than 1.5 km)
  2. I arrive home home within 4 minutes (i.e. my phone connects to my home wifi)

Problem is:

  1. I added some conditions in the “if” part to check to see if the garage door is already open/opening before it opens it…but having that condition leads to the else action of cancelling the door opening, even though the garage door is closed and no action was taken. I’m not sure why or where to put the condition to check if the overhead garage door is open/opening right before then call service send the command to open the overhead head garage door. I do not want the command to be sent if my overhead garage door is already open or opening.

  2. On timeout scenarios, there are errors that are logged related to this. Not sure why these are showing up:

Logger: homeassistant.helpers.template
Source: helpers/template.py:535
First occurred: 8:18:06 AM (2 occurrences)
Last logged: 8:18:06 AM

Template variable error: 'dict object' has no attribute 'event' when rendering '{{ wait.trigger is not none and wait.trigger.event.data.action == action_stop }}'
Template variable error: 'dict object' has no attribute 'event' when rendering '{{ wait.trigger is not none and wait.trigger.event.data.action == action_open }}'

Here’s the automation and script:

Automation
alias: Open Overhead Garage Door when Approaching Driveway
description: Open Overhead Garage Door when Approaching Driveway
trigger:
  - platform: numeric_state
    entity_id: proximity.my_name
    below: "1.5"
condition:
  - condition: state
    entity_id: proximity.my_name
    attribute: dir_of_travel
    state: towards
  - condition: state
    entity_id: cover.overhead_garage_door_controller
    state:
      - closed
      - closing
  - condition: state
    entity_id: device_tracker.android
    state: not_home
action:
  - service: script.notify_android_actionable_auto_garage_door
    data: {}
mode: single

And the associated script

Script
alias: Notify Android Actionable Auto-Garage Door
description: Sends an actionable notification to ZX1 about opening the overhead garage door
sequence:
  - alias: Set up variables for the actions
    variables:
      action_stop: "{{ \"STOP_\" ~ context.id }}"
      action_open: "{{ \"OPEN_\" ~ context.id }}"
  - alias: Ask what to do about opening the overhead garage door
    service: notify.mobile_app_sony_xperia_zx1
    data:
      message: >-
        Your overhead garage door will automatically open if you arrive home
        within 4 minutes.
      data:
        channel: Garage
        tag: garage
        actions:
          - action: "{{ action_stop }}"
            title: Stop
          - action: "{{ action_open }}"
            title: Open Now
  - service: notify.mobile_app_sony_xperia_zx1
    data:
      message: TTS
      data:
        tts_text: >-
          Your overhead garage door will automatically open if you arrive home
          within 4 minutes.
  - alias: Wait for a response or trigger
    timeout: "00:04:00"
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_stop }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_open }}"
      - platform: state
        entity_id:
          - device_tracker.android
        to: home
  - alias: Perform the action on button press or timeout
    choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ wait.trigger is not none and wait.trigger.event.data.action ==
              action_stop }}
        sequence:
          - delay: 1
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: clear_notification
              data:
                channel: Garage
                tag: garage
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: Your overhead garage door auto-open service has been cancelled.
              title: Overhead Garage Door
              data:
                channel: Garage
                notification_icon: mdi:garage-alert
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: TTS
              data:
                tts_text: >-
                  Your overhead garage door auto-open service has been
                  cancelled.
      - conditions:
          - condition: template
            value_template: >-
              {{ wait.trigger is not none and wait.trigger.event.data.action ==
              action_open }}
          - condition: state
            entity_id: cover.overhead_garage_door_controller
            state:
              - closed
              - closing
        sequence:
          - service: cover.open_cover
            data: {}
            target:
              entity_id: cover.overhead_garage_door_controller
          - delay: 1
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: clear_notification
              data:
                channel: Garage
                tag: garage
    default:
      - if:
          - condition: template
            value_template: "\"{{ wait.trigger is not none }}\""
          - condition: state
            entity_id: cover.overhead_garage_door_controller
            state:
              - closed
              - closing
        then:
          - service: cover.open_cover
            data: {}
            target:
              entity_id: cover.overhead_garage_door_controller
          - delay: 1
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: clear_notification
              data:
                channel: Garage
                tag: garage
        else:
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: TTS
              data:
                tts_text: >-
                  Your overhead garage door auto-open service has been
                  cancelled.
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: Your overhead garage door auto-open service has been cancelled.
              title: Overhead Garage Door
              data:
                channel: Garage
                notification_icon: mdi:garage-alert
          - delay: 1
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: clear_notification
              data:
                channel: Garage
                tag: garage
mode: single
icon: mdi:garage

any ideas what is going on? thanks for your help.

here’s an example trace where I made it home within the 4 minutes and the moment my phone connects to wifi, it goes to the else commands (i.e. cancels the overhead garage door opening)…its like the conditions in the ‘if’ are failing, buts not the case (i.e. the garage was closed, so the wait trigger was not ‘not’ none?..lol I’m confused myself I admit!

ok, I was able to solve the first issue, but changing the forming in the if statement to this:

    default:
      - if:
          - condition: state
            entity_id: cover.overhead_garage_door_controller
            state:
              - closed
              - closing
          - "{{ wait.trigger is not none }}"

for some reason, the extra code was not liking it.

Here is a working trace:

Problem 2, is still there, I get log errors on timeout conditions:

Logger: homeassistant.helpers.template
Source: helpers/template.py:135
First occurred: 8:26:53 AM (12 occurrences)
Last logged: 10:20:29 AM

Template variable warning: 'action_stop' is undefined when rendering '{{ action_stop }}'
Template variable warning: 'action_open' is undefined when rendering '{{ action_open }}'
Logger: homeassistant.helpers.template
Source: helpers/template.py:536
First occurred: 8:22:01 AM (4 occurrences)
Last logged: 10:14:53 AM

Template variable error: 'dict object' has no attribute 'event' when rendering '{{ wait.trigger is not none and wait.trigger.event.data.action == action_stop }}'
Template variable error: 'dict object' has no attribute 'event' when rendering '{{ wait.trigger is not none and wait.trigger.event.data.action == action_open }}'

seems like its rendering the value, that does not exist because its a time out.

some more progress, thanks to a fellow redditor, by adding this:

| default('None')

to each of the actionable items as below:

{{ wait.trigger is not none and wait.trigger.event.data.action ==
action_stop | default('None') }}

{{ wait.trigger is not none and wait.trigger.event.data.action ==
action_open | default('None') }}

seems to have now reduced the number of log errors to 2 everytime the script runs (from 6!). These errors now appear only when the script has started, and not after.

Logger: homeassistant.helpers.template
Source: helpers/template.py:135
First occurred: 10:04:22 PM (2 occurrences)
Last logged: 10:04:22 PM

Template variable warning: 'action_stop' is undefined when rendering '{{ action_stop }}'
Template variable warning: 'action_open' is undefined when rendering '{{ action_open }}

Progress has been made. Not sure why I’m still getting the errors above, when I’ve defined the default as ‘None’…?

1 Like