Problems with automation that keeps checking for a certain amount of time

Hey!

I can’t get an automation to work.
In short, I want an automation to check if my group.family is away from home for 20 minutes and I want it to keep checking this between 8am and 9am.

I use service: light.turn_off to turn off lights when this is met but the automation doesn’t seem to continue after 8am. Is it mode that needs to be changed?

I’ve tried doing a bootlean.

Thanks in advance! :slight_smile:

Why don’t you share the automation here to make easier for people to help you?
Just remember to remove any private info.

alias: ""
description: ""
trigger:
  - platform: state
    entity_id:
      - group.family
    to: not_home
    for:
      hours: 0
      minutes: 20
      seconds: 0
condition:
  - condition: time
    after: "08:00:00"
    before: "09:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  - condition: state
    entity_id: input_boolean.away_mode
    state: "on"
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.all_lights_indoor
mode: single

The only trigger you have is the family group changing to not_home, so if that happens outside the time range your automation will never trigger.

Try to add another trigger to run every day at 8AM (and perhaps one more when away mode changes to ‘on’) and add a condition to only run when family group is not_home.

The solution to that people are already 20 mins away before the time frame is to also add a time trigger at the start of the time frame and check again for 20 minutes not home in the conditions.

basically if there’s more than one condition, all should be added both as a trigger and as a condition.

It is only during these times that I want the automation (lights off) to run, between 8 and 9 when everyone has left the house.

Yeah, I understand that, but if everyone leaves at 07:30AM, the automation will be triggered 20m late (07:50AM) and won’t run as it is outside the time interval you selected. This is fine.
However, in this case, the group home will stay not_home until someone gets back home, and during this time, you don’t have any new trigger…

So, basically, your automation will work only if the last person leaves home between 07:40AM and 08:40AM. If the last person leaves outside this time window, it won’t run.

You probably want the lights to turn off at 08:00AM if the house is empty, right? For this you need a new trigger to run at 8AM and a new com diction to check if the group is not_home (so you prevent turning off at 8AM if someone still at home).

Try this:

alias: ""
description: ""
trigger:
  - platform: state
    entity_id:
      - group.family
    to: not_home
    for:
      hours: 0
      minutes: 20
      seconds: 0
  - platform: time
    at: "08:00:00"
condition:
  - condition: time
    after: "08:00:00"
    before: "09:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  - condition: state
    entity_id: input_boolean.away_mode
    state: "on"
  - condition: state
    entity_id: group.family
    state: not_home
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.all_lights_indoor
mode: single

Or even better:

alias: ""
description: ""
trigger:
  - platform: state
    entity_id:
      - group.family
    to: not_home
    for:
      hours: 0
      minutes: 20
      seconds: 0
  - platform: time
    at: "08:00:00"
  - platform: state
    entity_id:
      - input_boolean.away_mode
    to: "on"
condition:
  - condition: time
    after: "08:00:00"
    before: "09:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  - condition: state
    entity_id: input_boolean.away_mode
    state: "on"
  - condition: state
    entity_id: group.family
    state: not_home
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.all_lights_indoor
mode: single

With this, if any of your conditions changes, it will re-evaluate all the conditions and, if all met, it will turn off the lights.

Aha, now I’m starting to understand!

I don’t need the lights to turn off at exactly 8:00 but sometime between 8 and 9, assuming we’ve been gone for 20 minutes.

I’ll try your “Or even better:” automation! Sees that there are several different triggers that can now affect, e.g. bootlean which is started after 20 min in another automation. I’ll get back to you!

1 Like

Or have the time-frame start 20 mins earlier?

This one is handled by the gone for 20 minutes trigger. The problem is when you leave more tha 20 mins before 8:00. That’s what the time trigger is for. But the condition to check if you’re gone also needs the 20 minutes duration test. Otherwise when you leave 0:01 before 8:00, the light will go off at 8:00.

The same is for the away mode test. When that changes, you might need to reevaluate again if the light needs to go off.

So each test needs a trigger to check if it has changed, and all the conditions need to be there at the same time too, because whatever just changed may not be enough.

1 Like