And or condition not working bug?

I want to have my lights turn on when no one is home. And NOT turn one when one person is home.
I made the following automation but it is not working: (I am using Bluetooth and a PI3B+)

alias: Home mode
trigger:
  - entity_id: device_tracker.iphone1
    platform: state
    to: home
trigger:
  - entity_id: device_tracker.iphone2
    platform: state
    to: home
condition:
  condition: or
  conditions:
    - condition: state
      entity_id: 'device_tracker.iphone1'
      state: 'home'
    - condition: state
      entity_id: 'device_tracker.iphone2'
      state: 'home'
action:
  - entity_id: scene.normaal
    service: scene.turn_on

but for some reason this is not working. It is not firing when one of us arrives home when the other is not home and it is firing when one of us IS home and the other comes home…

I also tried to split them like so but no succes either…

  alias: Home mode - 1
  trigger:
  - entity_id: device_tracker.iphone1
    platform: state
    to: home
  condition:
  - condition: state
    entity_id: device_tracker.iphone2
    state: away
  action:
  - entity_id: scene.normaal
    service: scene.turn_on

_

  alias: Home mode - 2
  trigger:
  - entity_id: device_tracker.iphone2
    platform: state
    to: home
  condition:
  - condition: state
    entity_id: device_tracker.iphone1
    state: away
  action:
  - entity_id: scene.normaal
    service: scene.turn_on

OK -

1 - You can’t have 2 trigger keys, but you can have multiple triggers under the same key.

2 - You only want this to fire where the first person comes home, so by definition the condition should be that the other person is not.

Try this…

alias: Home mode
trigger:
  - entity_id: device_tracker.iphone1
    platform: state
    to: 'home'
  - entity_id: device_tracker.iphone2
    platform: state
    to: 'home'
condition:
  condition: or
  conditions:
    - condition: state
      entity_id: device_tracker.iphone1
      state: 'not_home'
    - condition: state
      entity_id: device_tracker.iphone2
      state: 'not_home'
action:
  - entity_id: scene.normaal
    service: scene.turn_on
1 Like

I’d just put the two device-trackers in a group, use a trigger on the group basis and do away with the conditions.
That should take care of it.

I think that did the trick! Will test this later this week when I have some time again :slight_smile:

and @chainstracker, can you give an example on how you would do it?

1 Like

Create a group in your groups.yaml:

people:
  name: People & Devices
  entities:
    - device_tracker.device_1
    - device_tracker.device_2

This group will only show not_home when both devices are not home; if either or both of them are home it will show home, i.e. the first one coming home will trigger the automation the second one won’t.

Your automation would then look like this:

- alias: Home mode
  trigger:
    - platform: state
      entity_id: group.people
      to: 'home'
  action:
    - entity_id: scene.normaal
      service: scene.turn_on
1 Like

That makes so much more sense, this is much simpeler thanks!