Automation condition: state for X hours

Hello everyone,

I am looking for an Automation condition that let me verify that the State has been on a certain value for X amount of time.

I am looking to do something like this:

  trigger:
    platform: time
    at: '10:00:00'
  condition:
    condition: state
    entity_id: device_tracker.nito
    state: not_home
    for:
      hours: 36

This would allow me to create daily alerts if I have been out for more than a 1.5 days.

This is possible on triggers:

  trigger:
    - platform: state
      entity_id: device_tracker.nito
      to: not_home
      for:
        hours: 36

However, triggers would only trigger once and I want to trigger the automation daily.
The current condition state does not seem to support “for value”.

I was thinking of using something like “last_updated”, but I guess it could be the case that the state was updated more recently but did not change value? So I guess it’s not the same.

Any ideas on how to workaround this?

Thanks!

The state condition does support the for: option. See the example here: https://www.home-assistant.io/docs/scripts/conditions/#state-condition

Oops. My bad, @tom_l. Thanks for the quick response.

You can create a boolean that will trigger “on” when you are away for more than 36 hours. Then create an automation that will trigger at 10:00:00 but with condition that boolean to be “on”.
Then you can go on with your actions.
To be able to trigger this daily, you can use the alert component:

EDIT: Actually, now that I am thinking of it, you may not need the alert at all. I think if you have a time trigger, it will be triggered daily… Anyway, you can try this and see for yourself. :wink:

That would also work @argykaraz, thanks. I’ve actually remembered that I did create such input_boolean to control that before.

However, it seems the condition state also can track time, so that would be an easier solution (unless it checks for equality, so I need to test it).

I use HTML5 notifications instead alert, but same concept for the use case anyway.

1 Like