Automation optimalisation

Hi Guys,

Since a few weeks i am spending more and more time in HA and setting it up with automations. Slowly getting a hang of it and really liking it!

A few days back i made an automation that basicly does this:

When we leave the house it starts prescense Simulation lights. As soon as we get back it turns off. This will only be done when it’s dark out.

Now i sat thinking. i have triggered this automation with A status atribute basicly saying when ‘home’ changes to 0.

But what happens when we are out for a week and the status of ‘home’ is already 0 for the second night?

You will understand we want this automation to run every nighttime when we are not in. Maybe some tweaks and little tips? If this is already the way to go and this works like i want please let me know!

This is the automation in YAML:

description: ""
triggers:
  - trigger: state
    entity_id:
      - zone.home
    to:
      - "0"
    id: Everybody Left Home
  - trigger: numeric_state
    entity_id:
      - zone.home
    above: 0
conditions: []
actions:
  - if:
      - condition: trigger
        id:
          - Everybody Left Home
      - condition: time
        after: sensor.sun_next_dusk
        before: sensor.sun_next_rising
    then:
      - action: switch.turn_on
        target:
          entity_id: switch.choose_a_unique_name
        data: {}
    else:
      - action: switch.turn_off
        target:
          entity_id: switch.choose_a_unique_name
        data: {}
mode: single
type or paste code here

Thanks!
Tim

Then design it to trigger at nighttime and have it check if you are in or not.

In other words, the triggers should be time-based (sunset and sunrise) and the condition should be based on zone (or person).

okay that sounds very logical to me :grinning: Thanks!

So this should be more like it:

alias: Turn on Presence lightning
description: ""
triggers:
  - trigger: time
    at: sensor.sun_next_dusk
    id: Light Presence On
  - trigger: time
    at: sensor.sun_next_rising
  - trigger: numeric_state
    entity_id:
      - zone.home
    above: 0
conditions: []
actions:
  - if:
      - condition: and
        conditions:
          - condition: trigger
            id:
              - Light Presence On
          - condition: state
            entity_id: zone.home
            state:
              - "0"
    then:
      - action: switch.turn_on
        metadata: {}
        target:
          entity_id: switch.choose_a_unique_name
        data: {}
    else:
      - action: switch.turn_off
        metadata: {}
        target:
          entity_id: switch.choose_a_unique_name
        data: {}
mode: single

Note! i also want the presence to automaticly stop as soon as we get home or when it starts to get light out. Should be fine now right?

but now i am thinking. what if it is already dark and i am leaving. i want the automation to pick it up from there.

for example;

now my automation triggers as soon as it gets dark out. but let’s say tomorrow it gets dark at 18:00 so my automation triggers at 18:00. but i am home at that time so the presence lightning is not turned on. 1 hour later i leave for a few hours. autmation won’t trigger again because it is triggered at 18:00 and won’t trigger again.

how can i make my automation to include everything i have in my changed automation but also covers me leaving after the start trigger already is done.

Okay,

Threw it all around.

Basicly made 1 automation with 4 triggers:

  1. when time is after sun down
  2. when time is after sun up
  3. when home value is higher than 0
  4. when home value changes to 0

after that i used the choices option and made 3 options where the different options where connected to the different triggers with their trigger ID’s.

It’s quite complex but it looks like it will get complicated anyway.

alias: Presence lightning
description: ""
triggers:
  - trigger: time
    at: sensor.sun_next_dusk
    id: Light Presence Trigger 1
  - trigger: time
    at: sensor.sun_next_rising
    id: Light Presence Trigger 2
  - trigger: numeric_state
    entity_id:
      - zone.home
    above: 0
    id: Light Presence Trigger 3
  - trigger: state
    entity_id:
      - zone.home
    to:
      - "0"
    id: Light Presence Trigger 4
conditions: []
actions:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - Light Presence Trigger 1
              - condition: state
                entity_id: zone.home
                state:
                  - "0"
        sequence:
          - action: switch.turn_on
            metadata: {}
            target:
              entity_id: switch.choose_a_unique_name
            data: {}
        alias: Action when 'Sun Volgende schemering' Trigger is used
      - conditions:
          - condition: trigger
            id:
              - Light Presence Trigger 2
              - Light Presence Trigger 3
        sequence:
          - action: switch.turn_off
            metadata: {}
            target:
              entity_id: switch.choose_a_unique_name
            data: {}
        alias: >-
          Action when 'Sun Volgende opkomst' or 'Wanneer Thuis hoger is dan 0'
          trigger is used
      - conditions:
          - condition: trigger
            id:
              - Light Presence Trigger 4
          - condition: time
            after: sensor.sun_next_dusk
            before: sensor.sun_next_rising
        sequence:
          - action: switch.turn_on
            metadata: {}
            target:
              entity_id: switch.choose_a_unique_name
            data: {}
        alias: Action when 'Wanneer Thuis verandert naar 0' trigger is used
mode: single