Checking for 'home' not working in automations

I have automations that should send an alert if my wife and I are both not home, so they have a condition:

condition:
  condition:
  - condition: and
    conditions:
    - condition: not
      conditions:
      - condition: state
        entity_id: person.myself
        state: home
    - condition: not
      conditions:
      - condition: state
        entity_id: person.my_wife
        state: home

I have a markdown card on lovelace to show our states:

Myself:  {{ states('person.myself') }}
My Wife:  {{ states('person.my_wife') }}

Currently it displays:
Myself: not_home
My Wife: home

The expectation is that the automation should not perform the action (raise an alert) unless both of us are not ‘home’, yet action is always taken when it is triggered. No change in behavior when I put home in quotes in the condition (‘home’).

Why wouldn’t the above logic work?

This will work as long as you don’t have other zones defined:

condition:
  - condition: state
    entity_id: person.myself
    state: not_home
  - condition: state
    entity_id: person.my_wife
    state: not_home

If you do have other zones, you will have to use:

condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: person.myself
        state: home
      - condition: state
        entity_id: person.my_wife
        state: home

I’ve simplified it as conditions are AND by default. This does not have to be declared.

Your main issue was the first two lines:

condition:
  condition:

That second condition: should not be there.

I do have other zones, so I would need to use the second option.

Great! I will give it a try now…

The AND is implied. I just edited my post. If you took out that second line it would work exactly the same.

Just tried the condition change, double checked the indentation levels- it’s identical to the second option you provided but the action still executes when triggered.

Automations reloaded normally per the log.

How did you trigger it?

Triggering manually skips all conditions and goes straight to the actions. There’s a trigger automation service you can use in the developer tools services menu where you can specify that the conditions not be skipped.

In my case it’s easy to trigger it ‘live’- I simply open the front door which updates a binary sensor. Alert fires immediately.

And at least one you is not home and you have this?

condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: person.myself
        state: home
      - condition: state
        entity_id: person.my_wife
        state: home

Hang on. I might have the logic wrong. When do you want the alert?

Yes, condition block is identical to that.

The markdown card still shows

Myself: not_home
My Wife: home

And you only want the alert when no one is home, correct?

I want it to alert only when both of us are not home and the trigger fires, otherwise it should be ignored (as is current state because one of us is home).

Put some quotes around both the states 'home' and try again.

Tried with quotes, no change.

According to the docs for the not condition both those conditions need to be false for it to pass.

So that’s really strange. Can you post your conditions please?

You could try this:

condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: person.myself
        state: home
  - condition: not
    conditions:
      - condition: state
        entity_id: person.my_wife
        state: home

Here’s the whole automation:

- id: '1583167744310'
  alias: Front Door Opened
  description: ''
  trigger:
  - entity_id: binary_sensor.front_door
    from: 'off'
    platform: state
    to: 'on'
  condition:
    - condition: not
      conditions:
        - condition: state
          entity_id: person.myself_thomas
          state: 'home'
        - condition: state
          entity_id: person.my_wife_thomas
          state: 'home'
  action:
  - data:
      message: Front Door Opened
      data:
        priority: 2
        retry: 1800
        expire: 3600
    service: notify.house_hassio

You may try to use groups, this is in my opinion much easier:

in groups.yaml

living_here:
  name: living_here
  entities:
    - person.myself
    - person.my_wife

in automations.yaml

condition:
  - condition: state
    entity_id: group.living_here
    state: 'not_home'

Good idea, but one thing at a time. There may be an issue with the not condition.

The conditions look correct.

I’d be interested to see the result of my suggestion above.

Hold on a sec- I think I might see my problem…

person.my_wife_thomas?

Is your wife called Thomas or are you using the wrong entity_id?

I must apologize- in the snippets I posted, I changed our actual names to ‘myself’ and ‘my_wife’- it turns out that in the markdown card I was using our correct real ‘person’ names, but in the automation I was using an older version of them that is slightly different. Correcting that appears to have fixed the issue.

Sorry to have had you chase my issue Tom :frowning:

1 Like