Ok so you are at that level… Sigh…
Don’t be a dick, I’m asking because I’ve had no experience of them before and you said it was the same!
From your response I take it it’s not automatic?
Either way is obviously far easier than your first suggestion
I don’t know what you are talking about, but it doesn’t matter.
I will not argue anything with you.
The input_datetime does add an extra step, but, sadly, it’s the only “everything proof” way I’ve found of setting a time in the future to check for something or do something and not have it erased by restarts, reloads, automations being turned off/on, etc.
@123 FYI this now works without specifying states. It will work on any state.
- alias: Garage Door Has been closed for 6 hours on a monday
trigger:
- platform: state
entity_id: cover.garage
for: "06:00:00"
Even if Home Assistant is restarted during the 6-hour period?
As I understand this new feature is that it doesn’t care if the state is on
for 6 hours or off
for 6 hours; as long as it stays in the same state for 6 hours, it will trigger.
However, I think it’s still susceptible to being reset when Home Assistant is restarted. Anyway, one more thing to test.
That I don’t know. I just know that during the month of WTH someone ninja’d in the ability to use ‘for’ without specifying a state.
EDIT: I Just saw your edit
Yes, same goes for any other entity. Same state for 6 hours == trigger, regardless of state.
I just tested with an automation that had a “for: minutes: 5” in it and when I restarted HA after two minutes the 5 minutes started after HA restart so that method won’t work.
That said I think the best (most reliable) way is to use an input_datetime as suggested.
you’ll need two automations - one to set the input_datetime for the last time the garage was opened and then the automation for your notification.
input_datetime:
garage_opened:
name: Last Time Garage Opened
has_date: true
has_time: true
automation:
- alias: set_garage_opened_time:
trigger:
platform: state
entity_id: cover.your_gd
to: 'open'
action:
service: input_datetime.set_datetime
data:
entity_id: input_datetime.garage_opened
timestamp: "{{ now().timestamp() }}"
then modify the condition to check that now is later than 6 hours past the input_datetime:
condition:
- condition: template
value_template: >
{{ as_timestamp(now()) | int - state_attr('input_datetime.garage_opened', 'timestamp') | int > 21600 }}
- condition: time
weekday:
- mon
I haven’t fully tested it but I think it should work.
The only thing I’m not sure about is the timezone that is used using the timestamp option for now(). I assume it’s your local TZ but if it seems off by an hour or hours (depending on your TZ) you can use the slightly more complex method to be sure:
data:
entity_id: input_datetime.garage_opened
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
All timestamps are in unix time. Shouldn’t need any conversion with what you’re doing.
using automations last_triggered attributes myself to check in conditions, I do agree with @Bobby_Nobble this would be most straightforward and failsafe.
simple create an input_boolean.garage_open
have it set by automation on open/close, and use that automation’s last_triggered to check in the condition. Fool and fail/faul proof.
Yeah, your right. I should have known that.
error, wrong topic. Sorry!