Automation run only if not already run before

Hi,

use HA since some days now, awesome ! I really like it and it just works.
Brilliant work here done ! :+1:

Now i have a small problem with an automation, more with the thinking behind it.

This is my automation right now, works fine, if my wife or me is getting home, the light turns on, if it is 45 minutes before sunset and between 16.30 and 23 PM.
So far so good.

But if someone is already home, i would like to not run this automation.

So, only run this, if someone comes home, its 45 minutes before sunset and between 16.30 and 23 PM and no one else is already home.

I am not sure how to manage this… maybe someone can help.

- alias: Turn on Floor after Sunset
  trigger:
    - platform: sun 
      event: sunset
      offset: "-00:45:00"
    - platform: state
      entity_id: device_tracker.babesiphone
      state: 'home'
    - platform: state
      entity_id: device_tracker.iphonefritzbox
      state: 'home'
  condition:
    condition: and
    conditions:
      - condition: time
        after: '16:30:00'
        before: '23:00:00'
      - condition: or
        conditions: 
          - condition: state
            entity_id: device_tracker.babesiphone
            state: 'home'
          - condition: state
            entity_id: device_tracker.iphonefritzbox
            state: 'home'
  action:
      service: light.turn_on
      entity_id: 
        - light.floor
        - light.hallway
      data:
        brightness: 255

Thanks in advance

Regards
Crey

why not put yours and the wife’s devices in a group and use the group status instead? I think this should give you what you want.

2 Likes

If trackers act like other groups, the group’s state should be “home” if any one tracker is home. Add a condition to your existing conditions that checks the group’s state.

1 Like

Hi,

to work with group is brilliant, that was the missing part.
Thank you for that.

And the Columbo question…
One last question:

Today i cam home at around 16.33 so the automation was armed.
From my understanding it should not have been going on, as the sunset will be in more then 45 minutes. But the lights went on, any idea why ?

I think you may want the sunset as a condition not as a trigger.

1 Like

exactly - change it round so the trigger is the group changing state to home, and the condition being 45 minutes before sunset.

1 Like

So,

this is my new Automation, this should work as expected.
Thanks for the Help, will try it this evening.

- alias: Turn on Floor after Sunset
  trigger:
    - platform: state
      entity_id: group.familiy
      state: 'home'
  condition:
    condition: and
    conditions:
      - condition: time
        after: '16:30:00'
        before: '23:00:00'
      - condition: sun
        after: sunset
        # Optional offset value
        after_offset: "-00:45:00"
  action:
    service: light.turn_on
    entity_id: 
      - light.floor
      - light.hallway
    data:
      brightness: 255

Regards
Crey

For any reaon, this does not work.

Nothing is happening.

I changed the Automaton to make it more easy, but this did not worked either, if i trigger it via hand, the lights go on.

This is the current setting:

- alias: Turn on Floor after Sunset
  trigger:
    - platform: state
      entity_id: group.familiy
      state: 'home'
  condition:
    condition: and
    conditions:
      - condition: time
        after: '16:30:00'
        before: '23:00:00'
      - condition: state
        entity_id: sun.sun
        state: 'below_horizon'
  action:
    service: light.turn_on
    entity_id: 
      - light.floor
      - light.hallway
    data:
      brightness: 255

the automation will only fire when the state of the family group changes - so if anyone in the group is home already, it won’t fire, which I guess you know as that is what you wanted. I.e. it won’t fire if everyone is home as the group state won’t change.

Other difference I have in a similar automation is I use
from:
to:

in the state trigger.

You could lose the time check and condition to simplify even more… you don’t really need that as the sunset should work and is almost always going to be within that time span anyway.

HI,

i am using this one know, this is working fine.
The Time check i just do, as i do not want to use later then 23PM,so do not wake someone with the light, i’d rather turn it on by hand then.

- alias: Turn on Floor after Sunset
  trigger:
    - platform: state
      entity_id: group.family
      from: 'not_home'
      to: 'home'
  condition:
    condition: and
    conditions:
      - condition: time
        after: '16:30:00'
        before: '23:00:00'
      - condition: state
        entity_id: sun.sun
        state: 'below_horizon'
  action:
    service: light.turn_on
    entity_id: 
      - light.floor
      - light.hallway
    data:
      brightness: 255