AND in Condition + automation once per day

Hi guys,

I have the following idea.

Trigger:
As soon as it gets darker in the evening than 100lx outside or at least it is 8pm

Conditon:
My wife or me are at home

Action:
Please turn on script.20h_oder_50lx_licht_wohnzimmer → This makes the light on and closes blinds.

alias: Wohnzimmer <100lx or 8pm
description: ''
trigger:
  - platform: time
    at: '20:00:00'
  - platform: numeric_state
    entity_id: sensor.signify_netherlands_b_v_sml004_5126d10b_illuminance
    below: '100'
condition:
  - condition: time
    before: '23:00:00'
    after: '15:00:00'
  - condition: and
    conditions:
      - condition: zone
        entity_id: device_tracker.jessicas_iphone
        zone: zone.home
      - condition: or
        conditions:
          - condition: zone
            entity_id: device_tracker.nicht_verbunden
            zone: zone.home
action:
  - service: script.turn_on
    data: {}
    target:
      entity_id: script.20h_oder_50lx_licht_wohnzimmer
mode: single

The problems now are:
A) As far as I know, the automation also starts, when we are not at home
B) The automation starts 2 times per day: 1. 20:00 2. when <100lx

Any idea how to solve those 2 issues A and B?

Issue A:

Or, And, and Not conditions only apply to the entries nested below them. As you have it now, all three of your conditions are effectively ANDed. Instead of thinking of it like a sentence (This AND That OR Other) think of it like distribution in algebra AND(This + OR(That + Other)). However, since the logical behavior of conditions is effectively AND, you do not need to use it in this case.

condition:
  - condition: time
    before: '23:00:00'
    after: '15:00:00'
  - condition: or
    conditions:
      - condition: zone
        entity_id: device_tracker.nicht_verbunden
        zone: zone.home
      - condition: zone
        entity_id: device_tracker.jessicas_iphone
        zone: zone.home

Issue B:

How is what you have described different than what you want?

Good idea! Thanks!

to B)
The Automation should just start 1 time per day:
Either <100lx or 8pm.

Ok, that can be accomplished by adding another condition that checks the last_triggered attribute of the automation itself.

condition:
  - condition: template
    value_template: |-
      {{ state_attr(this.entity_id, 'last_triggered') | default(today_at(), true) <= today_at() }}
  - condition: time
    before: '23:00:00'
    after: '15:00:00'
  - condition: or
    conditions:
      - condition: zone
        entity_id: device_tracker.nicht_verbunden
        zone: zone.home
      - condition: zone
        entity_id: device_tracker.jessicas_iphone
        zone: zone.home