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.
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"
}
]
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 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.
yep. you’re right. mindbending sometimes…
But your initial automation
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?'
If I remember correctly, in the condition section the default is to And the values, and I believe you want to Or them.
There is no time which is after 21:00 AND before 05:00
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?'
Oh, I must have missed that. If it works, then great, it simplifies things