Welcome Home Announcement Conditions

I’m setting up an automation to welcome me home. I have some conditions set, but the conditions still don’t seem to be getting met when I believe they should be. I’m thinking it could be a syntax issue with my AND, OR, and NOT statements:

condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state: disarmed
      - condition: not
        conditions:
          - condition: state
            entity_id: person.me
            state: home
            for:
              hours: 0
              minutes: 10
              seconds: 0
      - condition: state
        entity_id: person.me
        state: home
      - condition: or
        conditions:
          - condition: not
            conditions:
              - condition: state
                entity_id: person.roommate
                state: home
          - condition: state
            entity_id: person.roommate
            state: home
            for:
              hours: 0
              minutes: 10
              seconds: 0

What I am trying to program is if the HA_Alarm is disarmed, AND I have NOT been home for >10 minutes, AND I am home, AND my roommate is NOT home OR she has been home for >10 minutes. Any tips for getting this automation to trigger?

Check the automation trace:

But I suspect it is something to do with this logical inconsistency:

AND I have NOT been home for >10 minutes…AND I am home

Yeah. Maybe you’re right. I was trying to make a condition that I have been home for less than 10 minutes. Like saying “I have not been home for longer than 10 minutes, but I am home”.

I think I may have resolved this with the use of helpers:

Helpers:
input_booleon.me_away
input_booleon.roommate_away

Automations:

Me Away On:

trigger:
  - platform: state
    entity_id: person.me
    to: not_home
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition: []
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.me_away

Roommate Away On:

trigger:
  - platform: state
    entity_id: person.roommate
    to: not_home
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition: []
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.roommate_away

Scripts:

Welcome Home Me:

sequence:
  - condition: state    #alarm is disarmed
    entity_id: alarm_control_panel.ha_alarm
    state: disarmed
  - condition: state    #I have been "away" for 10 minutes
    entity_id: input_boolean.me_away
    state: 'True'
  - condition: state    #I am home now
    entity_id: person.me
    state: home
  - condition: or    #My roommate has not been away for 10 minutes OR she has been away for 10 minutes but she is not home
    conditions:
      - condition: state
        entity_id: input_boolean.roommate_away
        state: 'False'
      - condition: and
        conditions:
          - condition: state
            entity_id: input_boolean.roommate_away
            state: 'True'
          - condition: not
            conditions:
              - condition: state
                entity_id: person.roommate
                state: home
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: media_player.turn_on
    data: {}
    target:
      entity_id: media_player.kitchen_display
  - service: media_player.volume_set
    data:
      volume_level: 0.5
    target:
      entity_id: media_player.kitchen_display
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: tts.google_translate_say
    data:
      entity_id: media_player.kitchen_display
      message: Welcome home, me
  - delay:
      hours: 0
      minutes: 0
      seconds: 6
      milliseconds: 0
  - service: input_boolean.turn_off    #Turn off Me Away Booleon
    data: {}
    target:
      entity_id: input_boolean.me_away
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: media_player.turn_off
    data: {}
    target:
      entity_id: media_player.kitchen_display

Welcome Home Roommate:

sequence:    #Same as Welcome Home Me, but switched for roommate
  - condition: state
    entity_id: alarm_control_panel.ha_alarm
    state: disarmed
  - condition: state
    entity_id: input_boolean.roommate_away
    state: 'True'
  - condition: state
    entity_id: person.roommate
    state: home
  - condition: or
    conditions:
      - condition: state
        entity_id: input_boolean.me_away
        state: 'False'
      - condition: and
        conditions:
          - condition: state
            entity_id: input_boolean.me_away
            state: 'True'
          - condition: not
            conditions:
              - condition: state
                entity_id: person.me
                state: home
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: media_player.turn_on
    data: {}
    target:
      entity_id: media_player.kitchen_display
  - service: media_player.volume_set
    data:
      volume_level: 0.5
    target:
      entity_id: media_player.kitchen_display
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: tts.google_translate_say
    data:
      entity_id: media_player.kitchen_display
      message: Welcome home, roommate
  - delay:
      hours: 0
      minutes: 0
      seconds: 6
      milliseconds: 0
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.roommate_away
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: media_player.turn_off
    data: {}
    target:
      entity_id: media_player.kitchen_display

Welcome Home Me and Roommate:

sequence:
  - condition: state
    entity_id: alarm_control_panel.ha_alarm
    state: disarmed
  - condition: state    #I have been away for 10 minutes
    entity_id: input_boolean.me_away
    state: 'True'
  - condition: state    #Roommate has been away for 10 minutes
    entity_id: input_boolean.roommate_away
    state: 'True'
  - condition: state   #I am home now
    entity_id: person.me
    state: home
  - condition: state    #Roommate is home now
    entity_id: person.roommate
    state: home
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: media_player.turn_on
    data: {}
    target:
      entity_id: media_player.kitchen_display
  - service: media_player.volume_set
    data:
      volume_level: 0.5
    target:
      entity_id: media_player.kitchen_display
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: tts.google_translate_say
    data:
      entity_id: media_player.kitchen_display
      message: Welcome home, me and roommate
  - delay:
      hours: 0
      minutes: 0
      seconds: 6
      milliseconds: 0
  - service: input_boolean.turn_off    #Turn off Me Away Booleon
    data: {}
    target:
      entity_id: input_boolean.me_away
  - service: input_boolean.turn_off    #Turn off Roommate Away Booleon
    data: {}
    target:
      entity_id: input_boolean.roommate_away
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: media_player.turn_off
    data: {}
    target:
      entity_id: media_player.kitchen_display

Automation:

Laundry Door Open:

trigger:
  - platform: state
    entity_id: binary_sensor.laundry_door_sensor_open
    to: 'True'
condition:
  - condition: state
    entity_id: alarm_control_panel.ha_alarm
    state: disarmed
action:
  - service: media_player.turn_on
    data: {}
    target:
      entity_id: media_player.kitchen_display
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: media_player.volume_set
    data:
      volume_level: 0.5
    target:
      entity_id: media_player.kitchen_display
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: tts.google_translate_say
    data:
      entity_id: media_player.kitchen_display
      message: Laundry door open
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: media_player.turn_off
    data: {}
    target:
      entity_id: media_player.kitchen_display
  - service: script.welcome_home_me
    data: {}
  - service: script.welcome_home_roommate
    data: {}
  - service: script.welcome_home_me_and_roommate
    data: {}

A bit more work than I was expecting, but I think the logic is more straight-forward. It isn’t perfect though because I don’t think the input booleons will turn on if either of us somehow made it to one of the other “zones” I have pinned on the map in less than 10 minutes, which would cause the person.me or person.roommate states to change away from not_home.

Ironic that your name is Michael…

“Welcome home Marty! Lord of the Manor. King of the castle.”

Maybe this blueprint could shorten things: