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 Conditions - Home Assistant
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.
Would work great, just uncomment the time trigger.
Also not directed at you, I’m Not naysaying node red, but this is a simple automation, while node red will probably handle it just fine, it seems (to me), like a lot of overhead for simple automations. I feel like when people are starting out under standing these kind of automations are a good foundation to really understanding what is going on in the background.
You could also use a “garage open for x minutes” as a trigger. This would not send an notification if the garage is opened then closed within x minutes (when coming home late for example)
But it works if the garage has been opened at 20:59 and left open for x minutes:
- id: garageopenafter
alias: "Garage door open between 9pm and 5am"
trigger:
- entity_id: cover.sunsetgarage
for:
minutes: 5
from: 'off'
platform: state
to: 'on'
condition:
- condition: time
after: '21:00:00'
before: '05:00:00'
action:
- service: notify.telegram
data:
message: 'Garage door open, is that correct?'
Yes that might be a Problem indeed. Perhaps using the sun level as condition would be better? (need to have sun: somewhere in configuration.yaml)
- id: garageopenafter
alias: "Garage door open between 9pm and 5am"
trigger:
- entity_id: cover.sunsetgarage
for:
minutes: 5
from: 'off'
platform: state
to: 'on'
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- service: notify.telegram
data:
message: 'Garage door open, is that correct?
Thanks everyone, I agree with @ptdalen that it’s a good idea to understand the basics before moving onto something like Node Red. I guess based on post by @NigelL an ‘or’ wouldn’t work, per the below? I might just go for Node Red, as in this case it just seems much easier.
- 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: or
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?'
Why do you say that? After 2100 before 0500 is 9pm over the midnight then from midnight until 5am. Am I missing something somewhere else, I have many automations using that exact same logic
If I remember correctly (and this is something I have seen being talked about on here, not something I have direct experience of) the comparison is done to the current time, so it can’t be after 9PM, AND be before 5AM. The time comparison compares to the target times on the current day. (I could be misremembering, or just be flat out wrong)
So I believe the condition should be along the lines of (sorry, not testing this)
condition:
condition: or
conditions:
- condition: time
after: '21:00:00'
- condition:time
before: '05:00:00'
I hear what you’re saying and there are many, many examples exactly as you’ve said. Recently though I was shown than that is not necessary by a well trusted community member. I updated several of my automations to test, and they all still work, much simplier.
Thanks all, I’ve gone with the below, I’ll test it out tomorrow.
- 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?'
IFTTT integration is working, i.e. it response from the developer test interface, but the following automations are not generating any email notifications when they should be:
automation:
- id: 'garage_open_notification'
alias: 'Garage Door Open'
trigger:
- platform: state
entity_id: cover.garage_door
to: 'Open'
for:
minutes: 30
condition: []
action:
- service: ifttt.trigger
data: {"event": "GarageLeftOpen"}
- id: garageopenafter
alias: "Garage door open between 9pm and 8am"
trigger:
- platform: time_pattern
minutes: '/5'
condition:
- condition: time
after: '21:00:00'
before: '08:00:00'
- condition: state
entity_id: 'cover.garage_door'
state: 'Open'
action:
- service: ifttt.trigger
data: {"event": "GarageLeftOpen"}
- id: garage_opened
alias: 'Garage Door Opened'
trigger:
- platform: state
entity_id: cover.garage_door
to: 'Open'
condition:
condition: state
entity_id: cover.garage_door
state: 'Open'
action:
- service: timer.start
entity_id: timer.garage_door
- id: garage_closed
alias: 'Garage Door Closed'
trigger:
- platform: state
entity_id: cover.garage_door
to: 'Closed'
action:
- service: timer.cancel
entity_id: timer.garage_door
- id: garage_opened_timer_finished
alias: 'Garage Opened Timer Finished'
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.garage_door
condition:
condition: state
entity_id: cover.garage_door
state: 'Open'
action:
- service: ifttt.trigger
data: {"event": "GarageLeftOpen"}
- service: timer.start
entity_id: timer.garage_door
timer:
garage_door:
duration: '00:30:00'