Alert when garage door open between certain times?

Hi all, I’m trying to do exactly what I say in the title. If the garage door is open between 9pm and 5am, send me an alert via Telegram. So far, I’ve tried the following, but I don’t know what to put as the trigger, as I want it to simply monitor the state between those time.

- id: garageopenafter        
  alias: "Garage door open between 9pm and 5am"
  condition:
    condition: and
    conditions:
      - condition: time
        after: '21:00:00'
        before: '05:00:00'
      - condition: state
        entity_id: 'cover.sunsetgarage'
        state: 'open'
  action:
    - service: notify.telegram
      data:
        message: 'Garage door open, is that correct?'

Try using the garage door opening as the trigger and the times as the condition.

Thanks, but what happens if it’s open before 9pm?

If the condition is set to be after 9pm then nothing would happen.

Thanks! I changed it to the below. So can I confirm my understanding of the trigger then? Would this even trigger if it’s after 9pm and the garage door is in the state ‘open’?

- id: garageopenafter        
  alias: "Garage door open between 9pm and 5am"
  trigger:
    platform: state
    entity_id: 'cover.sunsetgarage'
    from: 'closed'
    to: 'open'
  condition:
    condition: and
    conditions:
      - condition: time
        after: '21:00:00'
        before: '05:00:00'
      - condition: state
        entity_id: 'cover.sunsetgarage'
        state: 'open'
  action:
    - service: notify.telegram
      data:
        message: 'Garage door open, is that correct?'

Good call. This would not go off if the garage was already open. You could also add a trigger to run at 9pm. That should work. Set the condition back to include the garage being open. But also have
The trigger for the door opening.

Or maybe I’m thinking about this incorrectly? Should I just run an automation every 5 minutes to check whether the door is open? Surely there’s a more efficient way to do this?

I’ve got this now. As I read it, it’ll trigger every 5 minutes, every day, 365 days a year. However, it will only alert if the time is between 9pm and 5am and the garage door is open.

- id: garageopenafter        
  alias: "Garage door open between 9pm and 5am"
  trigger:
    platform: time
    minutes: '/5'
    seconds: 00
  condition:
    condition: and
    conditions:
      - condition: time
        after: '21:00:00'
        before: '05:00:00'
      - condition: state
        entity_id: 'cover.sunsetgarage'
        state: 'open'
  action:
    - service: notify.telegram
      data:
        message: 'Garage door open, is that correct?'
1 Like

I know thiis should not be that hard. But it’s not coming to me. I’ll come back to this later. At the moment the only thing coming to mind is just two automatons

One is garage door trigger to open with the condition being the times you want

The second automation would be trigger at 9pm condition being garage door being open.

Those would definitely work. Again. I’m sure this could be done as a single automation too. Just coming to me at the moment

Just add a time trigger for 2100 to fire the automation.

Specifically have both a time trigger at 9pm and a door to open trigger. Then keep both conditions (door open and between 9 and 5).

That way it will check to see if the door is open at 9pm and check to see if the door goes to open between 9pm and 5 am.

As simple as this?

- id: garageopenafter        
  alias: "Garage door open between 9pm and 5am"
  trigger:
    - platform: time
      at: '21:00:00'
    - platform: state
      entity_id: 'cover.sunsetgarage'
      from: 'closed'
      to: 'open'
  condition:
    condition: and
    conditions:
      - condition: time
        after: '21:00:00'
        before: '05:00:00'
      - condition: state
        entity_id: 'cover.sunsetgarage'
        state: 'open'
  action:
    - service: notify.telegram
      data:
        message: 'Garage door open, is that correct?'

Have you tried Node Red? I was trying to setup something similar with HA automation but couldn’t get everything just right. Installed Node Red and was done in less than a minute.

1 Like

I do have node red! I just haven’t figured out how to use it. Could you share with me what you did?

I have mine set to send a notification to my iPhone. You will have to adjust yours accordingly.
Basically I used the poll state to set how often I want to check the state of the garage.
The current state then sets the proper “payload”. Open or Closed. If the state is closed to flow is halted.
Then you set which times you want the flow to be active. And add your preferred notification service.


You can import the flow below into node red using the hamburger icon, import, clipboard.

[
{
    "id": "48a5b8.0d208a48",
    "type": "api-call-service",
    "z": "38ba64c4.52010c",
    "name": "Notify iPhone",
    "server": "6882cc0e.116284",
    "service_domain": "notify",
    "service": "ios_iphone",
    "data": "{}",
    "mergecontext": "",
    "x": 1140,
    "y": 600,
    "wires": [
        []
    ]
},
{
    "id": "75978159.6ad6f",
    "type": "function",
    "z": "38ba64c4.52010c",
    "name": "Data",
    "func": "msg.payload = \n{\n  \"data\": \n  {\n    \"message\": \"Garage Open\",\n    \"data\": \n    {\n      \"push\": \n      {\n        \"badge\": 5,\n        \"category\": \"garage\"\n      },\n    }\n  }\n}\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "x": 830,
    "y": 600,
    "wires": [
        [
            "48a5b8.0d208a48"
        ]
    ]
},
{
    "id": "55f844f3.4c2e4c",
    "type": "api-current-state",
    "z": "38ba64c4.52010c",
    "name": "Garage Door",
    "server": "6882cc0e.116284",
    "halt_if": "closed",
    "override_topic": true,
    "override_payload": true,
    "entity_id": "cover.garage",
    "x": 350,
    "y": 600,
    "wires": [
        [
            "713b399f.437ed8"
        ]
    ]
},
{
    "id": "7a022668.b6cb48",
    "type": "poll-state",
    "z": "38ba64c4.52010c",
    "name": "Poll Garage Door",
    "server": "6882cc0e.116284",
    "updateinterval": "900",
    "outputinitially": false,
    "outputonchanged": false,
    "entity_id": "cover.garage",
    "x": 120,
    "y": 600,
    "wires": [
        [
            "55f844f3.4c2e4c"
        ]
    ]
},
{
    "id": "713b399f.437ed8",
    "type": "time-range-switch",
    "z": "38ba64c4.52010c",
    "name": "9:30PM-5AM",
    "lat": "53.63279",
    "lon": "-113.60596",
    "startTime": "21:30",
    "endTime": "05:00",
    "startOffset": 0,
    "endOffset": 0,
    "x": 650,
    "y": 600,
    "wires": [
        [
            "75978159.6ad6f"
        ],
        []
    ]
},
{
    "id": "6882cc0e.116284",
    "type": "server",
    "z": "",
    "name": "Home Assistant",
    "url": "http://hassio/homeassistant",
    "pass": "xxxxxxx"
}
]
2 Likes

Thanks, I’ll give it a try this evening.

Yes, I’m pretty sure that will do want you want.

HI, chiming in.
You dont need to state the ‘and’ in the condition part, since the is default with multiple conditions.
So

condition:
    condition: and
    conditions:
      - condition: time
        after: '21:00:00'
        before: '05:00:00'
      - condition: state
        entity_id: 'cover.sunsetgarage'
        state: 'open'

could be:

condition:
  - condition: time
    after: '21:00:00'
    before: '05:00:00'
  - condition: state
    entity_id: 'cover.sunsetgarage'
    state: 'open'

that being said, you always have to be careful with these timings, since you’re crossing the 24 hour mark. Have to look up if this is the correct way for defining that period. see https://www.home-assistant.io/docs/scripts/conditions/#time-condition

about the 21 hour trigger: what would you expect this to do? Since the conditions are the same, the automation would only lead to action under the same conditions…
You might even be able to take out the from: to: statement.
Triggering on the 12 hour mark, and on the state of the door (can only be open or closed? or is there another state)

the condition will check if the door is open or not, and if open, fire the action.

so id try:

- id: garageopenafter        
  alias: "Garage door open between 9pm and 5am"
  trigger:
    #- platform: time
    #  at: '21:00:00'
    - platform: state
      entity_id: 'cover.sunsetgarage'
  condition:
    - condition: time
      after: '21:00:00'
      before: '05:00:00'
    - condition: state
      entity_id: 'cover.sunsetgarage'
      state: 'open'
  action:
    - service: notify.telegram
      data:
        message: 'Garage door open, is that correct?'

If the garage door was already open at 21:00, this would not send an alert. That was the purpose of the time trigger. But I do like the idea of just triggering on any state change of the garage door, then using the condition of open.

not sure here. since the conditions take care it starts checking at the specified time, 21 included, and the state being open. Doesn’t matter what the state the door was in before or at 21 hour then.
i think…

A condition is not a trigger. So you need something to trigger the automation. In the case you have the garage door state as a trigger. But if at 20:59 the door was opened, and stayed open, it would not trigger again.