Help with automation - can't make it work

Hi all,

i am pretty sure there is some stupid error in this automation but i can’t make it work.
Can someone provide help?

Basically the idea of this automation is to turn light on if one of the two member of the family is arriving home.
the “input_boolean.XXX_not_home” and “input_boolean.YYY_not_home” switch to on if someone is “away” for more than 30 mins.
This switches on correctly so i am quite keen this is not the issue.

- action:
  - data:
      entity_id:
      - light.luce_ingresso
      - light.lampadario_ingresso
    service: light.turn_on
  - data:
      entity_id: input_boolean.luce_ingresso_on_arrival
    service: input_boolean.turn_on
  alias: turn on lights when arriving home if dark
  condition:
  - after: sunset
    after_offset: -01:00:00
    before: sunrise
    before_offset: -01:00:00
    condition: sun
  - condition: or
    conditions:
    - condition: state
      entity_id: input_boolean.XXX_not_home
      state: 'on'
    - condition: state
      entity_id: input_boolean.YYY_not_home
      state: 'on'
  id: '1518118102032'
  trigger:
  - entity_id: device_tracker.iphone_XXX, device_tracker.iphone_YYY
    from: not_home
    platform: state
    to: home

What makes the boolean go to off? Share that automation. One possibility is that the boolean is going off at the same time that this automation triggers, meaning that the conditions stop it from running.

With what purpose did you implement the input_boolean?

Isn’t it easier to just use the device tracker? You can change the consider_home to 30 minutes (1800 secs) if you like in known_devices.yaml although 30 minutes is rather long if you ask me.

Use automation like this:

- alias: 'Lights on when home after sunset'
  trigger:
    - platform: state
      entity_id: device_tracker.iphone_XXX, device_tracker.iphone_YYY
      from: 'not_home'
      to: 'home'
    - platform: sun
      event: sunset
  condition:  
    condition: and
    conditions:
      condition: sun
      after: sunset
    - condition: or
      conditions:
    - condition: state
      entity_id: input_boolean.XXX_not_home
      state: 'on'
    - condition: state
      entity_id: input_boolean.YYY_not_home
      state: 'on'
  action:
    - service: light.turn_on
      entity_id: light.luce_ingresso, light.lampadario_ingresso

BTW: not sure about the indention when using both AND and OR conditions.

  - id: '1518118102032'
    alias: turn on lights when arriving home if dark
    trigger:
      platform: state
      entity_id: device_tracker.iphone_XXX, device_tracker.iphone_YYY
      from: 'not_home'
      to: 'home'
    condition:
      condition: and 
      conditions:
        - condition: sun
          after: sunset
          after_offset: "-1:00:00"
        - condition: sun
          before: sunrise
          before_offset: "-1:00:00"
        - condition: or
          conditions:
          - condition: state
            entity_id: input_boolean.XXX_not_home
            state: 'on'
          - condition: state
            entity_id: input_boolean.YYY_not_home
            state: 'on'	  	  
    action:
      service: light.turn_on
      data:
        entity_id:
          - light.luce_ingresso
          - light.lampadario_ingresso
      service: input_boolean.turn_on
      data:
        entity_id: input_boolean.luce_ingresso_on_arrival