Automation using not_home state

Morning all, I just updated my HomeAssistant from an old version to the last one.
To move all automations I moved manually all files from a backup on the Hassio folder, through SFTP.

With the old HA version, my automations worked properly, now not.
Pseudo code:
Automation 1: if me AND my wife leave home, turn on a smart plug:

- id: '222'
  alias: Turn ON smartPlug when last family member leaves home
  description: Turn ON smartPlug when last family member leaves home
  trigger:
  - platform: state
    entity_id:
    - device_tracker.life360_me
    to: not_home
  - platform: state
    entity_id:
    - device_tracker.life360_wife
    to: not_home
  condition:
  - condition: device
    type: is_off
    device_id: a2
    entity_id: switch.smartPlug
    domain: switch
  - condition: and
    conditions:
    - condition: state
      entity_id: device_tracker.life360_me
      state: not_home
  - condition: and
    conditions:
    - condition: state
      entity_id: device_tracker.life360_wife
      state: not_home
  action:
  - type: turn_on
    device_id: a2
    entity_id: switch.smartPlug
    domain: switch
  - service: notify.mobile_app_iphone_di_me
    data:
      message: Turn ON smartPlug when last family member leaves home
  mode: single

Automation 1: if me OR my wife get home, turn OFF a smart plug:

- id: '111'
  alias: Turn off smartPlug when first family member gets home
  description: Turn off smartPlug when first family member gets home
  trigger:
  - platform: state
    entity_id: device_tracker.life360_wife
    to: home
  - platform: state
    entity_id: device_tracker.life360_me
    to: home
  condition:
  - condition: device
    type: is_on
    device_id: a2
    entity_id: switch.smartPlug
    domain: switch
  action:
  - type: turn_off
    device_id: a2
    entity_id: switch.smartPlug
    domain: switch
  - service: notify.mobile_app_iphone_di_me
    data:
      message: Turn off smartPlug when first family member gets home
  mode: single

Could you please tell me how I can test it? should I we have to leave home to test it?

Change your conditions to this in the ON automation:

  condition:
  - condition: device
    type: is_off
    device_id: 382a0c5296e5bb61800dbf8198b921a2
    entity_id: switch.smartPlug
    domain: switch
  - condition: state
    entity_id: device_tracker.life360_me
    state: not_home
  - condition: state
    entity_id: device_tracker.life360_wife
    state: not_home

Conditions are AND by default.

You can test them by changing the state of your trackers in Developer Tools → States. Then looking at the automation trace.

1 Like

Hey Tom, editing the code as suggested from you and changing states manually, it works :smiley:
So basically what was the main problem in my old code?

Likely the odd conditions.