Multiple states in automation

Hi i’m struggling to find out if i can have multiple entities on one automation.

I have two motion sensors in my lounge and if either change state to “on” then i want my light to turn on.

I have one in there at the moment which works well just wondering how I add second one or do i have to create whole new automation for the second sensor?

Thanks!

No, you can have a single automation with two triggers.

awesome do you know how i’d code it.
I have this at the minute

- alias: Turn lamp on when motion in lounge
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d0003202853
    to: 'on'
  condition:
    condition: state  # from sunset until sunrise
    entity_id: sun.sun
    state: 'below_horizon'
  action:
    - service: homeassistant.turn_on
      entity_id: switch.lounge
- alias: Turn lamp on when motion in lounge
  trigger:
    platform: state
    entity_id: 
      - binary_sensor.motion_sensor_158d0003202853
      - binary_sensor.motion_sensor_the_other_one
    to: 'on'
  condition:
    condition: state  # from sunset until sunrise
    entity_id: sun.sun
    state: 'below_horizon'
  action:
    - service: homeassistant.turn_on
      entity_id: switch.lounge

i tried that initially but it didn’t like it.

I was wondering if there is an OR statement aka if sensor 1 or sensor 2 turns to on then turn the lamp on?

Try this then:

  trigger:
    - platform: state
      entity_id: binary_sensor.motion_sensor_158d0003202853
      to: 'on'
    - platform: state
      entity_id: binary_sensor.motion_sensor_the_other_one
      to: 'on'

afraid not i just get

duplicated mapping key at line 167, column 5:
platform: state
^

Paste your actual code.

I have this and it works:

  trigger:
  - platform: state
    entity_id: binary_sensor.pir_stairs
    to: 'off'
    for:
      minutes: 3
  - platform: state
    entity_id: light.lifx_bottom_of_stairs
    to: 'on'
    for:
      minutes: 4

I also have this and it works:

  trigger:
    platform: state
    entity_id:
    - binary_sensor.pir_drive
    - binary_sensor.pir_washing_line
    from: 'off'
    to: 'on'

Put your entity_ids on the same line separated by a comma.

entity_id: sensor.1, sensor.2

edit: was on phone

2 Likes

Yep that should work too (without the capital ‘E’ in entity).

Typing on your phone?

this is my code

- alias: Turn lamp on when motion in lounge
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d0003202853, entity_id: binary_sensor.motion_sensor_158d0003466812
    to: 'on'
  condition:
    condition: state  # from sunset until sunrise
    entity_id: sun.sun
    state: 'below_horizon'
  action:
    - service: homeassistant.turn_on
      entity_id: switch.lounge

sorry removed the second entity and got a tick! Will test it now

Legends works like a treat thanks guys!