Multiple Condition Options

Which way would be the correct way to use multiple conditions?

Config1:

condition:
  condition: and
  conditions:
    - condition: state
      entity_id:
        - 'device_tracker.me'
        - 'group.us'
      state: 'home'

Config2:

condition:
  condition: and
  conditions:
    - condition: state
      entity_id: 'device_tracker.me'
      state: 'home'
    - condition: state
      entity_id: 'group.us'
      state: 'home'

I don’t think config 1 is valid off the top of my head, but it kinda looks like it should be so worth a punt.

Config 2 definitely works, but should be simplified to:

condition:
  - condition: state
    entity_id: 'device_tracker.me'
    state: 'home'
  - condition: state
    entity_id: 'group.us'
    state: 'home'

If config 1 does work it should be simplified to:

condition:
  condition: state
  entity_id:
    - 'device_tracker.me'
    - 'group.us'
  state: 'home'

All that extra text is just mess :wink:

Hope this helps.

EDIT:
Never mind, just saw the following in the docs.

If you do not want to combine AND and OR conditions, you can also just list them sequentially, by default all conditions have to be true. The following configuration works the same as the one listed above:

Any idea why the first config is invalid compared to the second?

  action:
    - condition:
        condition: state
        entity_id: 'group.us'
        state: 'home'

  action:
    - condition: or
      conditions:
        - condition: state
          entity_id: 'device_tracker.me'
          state: 'home'
        - condition: state
          entity_id: 'device_tracker.you'
          state: 'home'

The following turns out to be invalid.

condition:
  condition: state
  entity_id:
    - 'device_tracker.me'
    - 'group.us'
  state: 'home'

2018-06-06 00:07:00 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Entity ID ['device_tracker.me', 'group.us'] is an invalid entity id for dictionary value @ data['condition'][0]['entity_id']. Got None
extra keys not allowed @ data['condition'][0]['state']. Got None
not a valid value for dictionary value @ data['condition'][0]['condition']. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 274). Please check the docs at https://home-assistant.io/components/automation/

Because you’re adding the condition block to the action, which is wrong. You just want the condition itself:

action:
  - condition: state
    entity_id: 'group.us'
    state: 'home'
1 Like

Thought so. That’s because conditions only accept one entity_id :+1:

1 Like

Thank you, this clears up a lot.