Send an alert when my Garage Door has been left opened for 15 minutes

I think you replied above to the wrong person. I’m not the OP.

I was asking them why they didn’t like my code from post #3 above.

they said they were concerned about your code not repeating but my code does that.

Not a big deal I just wasn’t sure if they understood my code or not.

@finity Oh, sorry about that. It is late here :smiley:
By the way, your code on post 3 seems fine to me. I still spot some unnecessary lines, like the condition and the timer, but it is just me. I am trying to keep it as simple and less lines as possible.

Edit: And I just realized we WANT the automation to repeat itself every 30 minutes…
@FutureTense I missguided you! My code DOESNT repeat itself! If you want it to repeat, then I guess the code you posted is OK! Sorry!

I agree that they aren’t necessary if you want it to only fire once but if you want it to continuously send notifications at an interval you need the condition and timer…I think…

But no worries. We all have our ways of doing things.

@argykaraz

And yes I’m still not sure why @FutureTense needs all the different automations. I’m pretty sure my one automation will do exactly what they want. Unless I’m missing something… Which is entirely possible… Hence the question above… :laughing:

The only thing that stood out at me was having “30” repeated, as well as what happens if you open and close and open again. Maybe your code resets back to 30 minutes again. But I do like code being called from the same place, that is the timer expiring. Having the closed event trapped to disable the timer is a necessary evil.

Oh I found the problem moving the code to automation.ymal. seems the timer doesn’t go there.

This is what alerts are for. No need to reinvent the wheel

Better answer!

I looked at the alert component and it seemed that it was more complicated (to me at least) than what I’m doing.

And to answer your last question…

I guess it wouldn’t reset the timer in the condition that the door was opened, closed then reopened outside of the first 30 minute interval (the timer doesn’t get triggered to run until the after the door has been opened the first time for 30 minutes). So it could lead to a shorter time interval (less than 30 minutes) between notifications in that specific instance. But I don’t really see that as an issue. And I’ve never noticed it happening. But that may be because I don’t open & close my garage door that often. It’s usually closed.

If you are that OCD about it you could use another automation to kill the timer when the door closes…but why?

Again, either way, use what you feel best fits your needs. It just seemed that you were over complicating things and re-inventing my easier wheel I had shown you already existed. :grinning:

Because as a developer, I don’t like unexpected behavior, even if it’s unlikely to occur. However it’s not really a big deal. But I do think the alert code is far simpler than any of the other solutions proposed. The only problem is (so far) I don’t know how to make it work with an external service like IFTTT.

The problem with the alert component is that it needs a notifier. If there was a notify template, you would have been able to use the ifttt component and used a trigger that would then send the sms. This however seems complicated as well. There are other notify components that are able to send sms as well. Would that work? For example https://www.home-assistant.io/components/notify.twilio_sms/

Is it possible to use the alert component today with say either Pushbullet / Telegram or Pushover?

When I first created my garage door project, I wanted a way to send me a notification, so I use automations. I wrote about how I did that in THIS BLOG POST.

I’m not sure if it was my feature request that did it, but after setting up that I put in a feature request for something exactly like the alert component. And within a month of that, someone had actually created the alert component. So I wrote ANOTHER BLOG POST on using the alert component. After reading it just now, I realized that I need to update it. I was using an automation to notify when the condition no longer exists(garage door is closed). However, that automation is no longer necessary. It’s just a simple ‘done_message’ setting in the alert component.

You can take a look at both of those posts and see which one you prefer. And honestly, I couldn’t imagine anyone trying to do it any other way but the alert component. I’ve been using the alert component since it came out, and it’s been rock solid since then. It has alerted me every x minutes when my door is open, and again when it finally closes.

Let me know if you have any questions about using it.

Thought I’d share something with you that I learned today.

After seeing this snippet:

      value_template: >
        {% if is_state('cover.south_garage_door', 'closed') %}
          Closed
        {% elif is_state('cover.south_garage_door', 'open') %}
          Open
        {% endif %}

It made me wonder if there’s a filter to capitalize the first letter of each word in a sentence. In other words, something to convert front door to Front Door.

A quick search turned up title. So this converts the states opened and closed to Opened and Closed.

value_template: "{{ states('cover.south_garage_door') | title }}"

Neat!

3 Likes

Thanks! that can come in useful. If I can only remember it again when I need it. :older_man:

I don’t use that particular code anymore since the MyQ component is so unstable I built my own control system and the MQTT binary position sensor uses on & off that I convert to Open & Closed.

1 Like

Does anyone have an example of how to use the Alert feature with a basic phone notification (via the companion app)? The doc is lacking and the examples in this thread alert via other methods I’m not using.

Below is what I’ve been using for a while, actionable notification to the companion app.

automation:
  # Garage Actionable Notification - Garage door left open
  - alias: Notify iOS Garage Door Open
    initial_state: true
    trigger:
      - platform: state
        entity_id: cover.garage_door
        to: 'open'
        for:
          minutes: 15
    condition: []
    action:
      - service: notify.ios_all
        data:
          title: "Garage door open"
          message: "The garage door has been open for more than 15 minutes. Close the garage door?"
          data:
            push:
              badge: 0
              category: "garageclose"

  - alias: iOS App Notification Action Garage Left Open
    initial_state: true
    trigger:
      platform: event
      event_type: ios.notification_action_fired
      event_data:
        actionName: CLOSE_GARAGE
    action:
      - service: cover.close_cover
        entity_id: cover.garage_door


ios:
  push:
    categories:
      - name: garageclose
        identifier: 'garageclose'
        actions:
          - identifier: 'CLOSE_GARAGE'
            title: 'Close Garage Door'
            activationMode: 'background'
            authenticationRequired: yes
            destructive: yes
            behavior: 'default'
      - name: garageopen
        identifier: 'garageopen'
        actions:
          - identifier: 'OPEN_GARAGE'
            title: 'Open Garage Door'
            activationMode: 'background'
            authenticationRequired: yes
            destructive: yes
            behavior: 'default'
1 Like

Nice. Like the notification interaction to close the door. That’s phase 2 for me.

Do you know of a way to get it to keep reminding you every 15 minutes if it remains open? My understanding is that’s what Alerts are designed for which is why I’m trying to get those working.

I haven’t tried this myself, but check out this thread - Best practices for Repeating Alerts until Acknowledged

edit: actually there’s a relevant example in the doco - https://www.home-assistant.io/integrations/alert

1 Like

Yeah Alerts have a significant limitation of not being able to call services, scripts and other such things directly. There are work arounds but they’re abstractions that make the setup unclear and harder to trace if you need to troubleshoot or change later.

Have relented to trying to use Automations instead hence my question about triggering the examples here at different intervals.

I might just go with the basic approach of setting a delay at the end of the Automation that re-calls itself or maybe better options would be to use a time pattern and have it just repeat the automation ever 15 minutes (for example) with a condition that the door be open. Both have disadvantages over Alerts but allow me to do what I want in the resulting action much easier than Alerts do.

I did multiple triggers (via the UI) but it only triggers the first time after 15 minutes, not at 30/45 like I would have expected.

- id: '1600463929200'
  alias: 'Security: Garage Door Remains Open'
  description: ''
  trigger:
  - platform: state
    entity_id: cover.garage_door
    to: open
    for: 00:15:00
  - platform: state
    entity_id: cover.garage_door
    to: open
    for: 00:30:00
  - platform: state
    entity_id: cover.garage_door
    to: open
    for: 00:45:00
...

Did you ever get this going?

The reason it only called once, is that the action was met already, it would have to be a separate automation for the above to work as a trigger.

I have been unsuccessful in my attempts for repeat notifications and hoping you made progress.