(2) Motion Sensors in same room automation

Hi all,

Following along with what other’s have suggested, but still running into issues. I have (2) Aqara Motion Sensors setup in the garage, and want to trigger the lights to come on if either motion sensor senses. I create a Group for the 2 motion sensors for the OR, but doesn’t seem to trigger. There’s also a condition based on the lux.

alias: Garage Group ON
description: ''
trigger:
  - platform: state
    entity_id:
      - binary_sensor.garage_motion_sensors
    from: 'off'
    to: 'on'
condition:
  - type: is_motion
    condition: device
    device_id: 1b4491b053dd6563a2c28f9492ce80c6
    entity_id: binary_sensor.lumi_lumi_motion_ac02_ias_zone
    domain: binary_sensor
  - type: is_motion
    condition: device
    device_id: 3c5a9a00cc1f456da38e3a4cbfdf0e26
    entity_id: binary_sensor.lumi_lumi_motion_ac02_376e4900_ias_zone
    domain: binary_sensor
  - type: is_illuminance
    condition: device
    device_id: 1b4491b053dd6563a2c28f9492ce80c6
    entity_id: sensor.lumi_lumi_motion_ac02_illuminance
    domain: sensor
    below: 50
  - type: is_illuminance
    condition: device
    device_id: 3c5a9a00cc1f456da38e3a4cbfdf0e26
    entity_id: sensor.lumi_lumi_motion_ac02_376e4900_illuminance
    domain: sensor
    below: 50
action:
  - type: turn_on
    device_id: 7664a5155cee99755e8f68d9773aedd7
    entity_id: switch.garage_test
    domain: switch
mode: single

Separately created another automation if there is no motion for (1) minute:

alias: Garage Group OFF
description: ''
trigger:
  - platform: state
    entity_id:
      - binary_sensor.garage_motion_sensors
    from: 'on'
    to: 'off'
condition:
  - type: is_no_motion
    condition: device
    device_id: 1b4491b053dd6563a2c28f9492ce80c6
    entity_id: binary_sensor.lumi_lumi_motion_ac02_ias_zone
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - type: is_no_motion
    condition: device
    device_id: 3c5a9a00cc1f456da38e3a4cbfdf0e26
    entity_id: binary_sensor.lumi_lumi_motion_ac02_376e4900_ias_zone
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
action:
  - type: turn_off
    device_id: 7664a5155cee99755e8f68d9773aedd7
    entity_id: switch.garage_test
    domain: switch
mode: single

Any suggestions?

Much appreciated,

The automation debugger should show if it’s failing to trigger or that one of the conditions isn’t passing.

hello you said you created a group with sensors.
but i see a binaries sensor “binary_sensor.garage_motion_sensors”, it should not be a “group.garage_motion_sensors” instead of?

Binary sensor groups created in the UI will be under domain binary_sensor. It is still possible to create legacy style groups through YAML that are under the domain group but this is not the recommended practice for any entity group type that can be created in the UI.

Thanks all. I did originally create the automation in the UI. Should I rename binary_sensor.garage_motion_senors in YAML to group?

Your “off” automation will never execute the actions because your trigger and conditions are working against one another. The trigger fires as soon as both motion sensors are ‘off’. But the conditions fail because they have not been off long enough. Conditions test the state of the entity at that exact moment… they do not wait around for things to change. Your “off” automation needs to have the duration moved to the trigger:

alias: Garage Group OFF
description: ''
trigger:
  - platform: state
    entity_id:
      - binary_sensor.garage_motion_sensors
    from: 'on'
    to: 'off'
    for: "00:01:00"
condition: []
action:
  - type: turn_off
    device_id: 7664a5155cee99755e8f68d9773aedd7
    entity_id: switch.garage_test
    domain: switch
mode: single

Similarly, the conditions in your “on” automation may be working against you. Triggering with the group means that only one of the motion sensors needs to be ‘on’ to fire, but the conditions require both to be ‘on’ to move on to the actions. Getting rid of the motion conditions will solve that:

alias: Garage Group ON
description: ''
trigger:
  - platform: state
    entity_id:
      - binary_sensor.garage_motion_sensors
    from: 'off'
    to: 'on'
condition:
  - type: is_illuminance
    condition: device
    device_id: 1b4491b053dd6563a2c28f9492ce80c6
    entity_id: sensor.lumi_lumi_motion_ac02_illuminance
    domain: sensor
    below: 50
  - type: is_illuminance
    condition: device
    device_id: 3c5a9a00cc1f456da38e3a4cbfdf0e26
    entity_id: sensor.lumi_lumi_motion_ac02_376e4900_illuminance
    domain: sensor
    below: 50
action:
  - type: turn_on
    device_id: 7664a5155cee99755e8f68d9773aedd7
    entity_id: switch.garage_test
    domain: switch
mode: single
1 Like

No, if you created the binary sensor group in the UI it is correct for it to be in the binary_sensor domain.

Thanks for your help, Drew. This all makes better sense now via YAML than in the visual editor.

For some reason in the Log Book, I see the Group of Motion Sensors being triggered, but it’s not running the automation.

Will continue to debug this, seems like an obvious and easy fix somewhere I’m not seeing.

Why don’t you just add two triggers?

And aqara motion only updates lux after motion is detected so the lux is 50 is probably an old value when this automation gets triggered.

Oddly enough the group ON automation is suddenly working. The group OFF automation is not - seems like it would be easier to troubleshoot since there are no conditions.

When you say just add two triggers, as in like Sensor 1 ON and Sensor 2 ON to initiate the automation?

yes to the triggers. I have in my bathroom 3 motion sensors, all are triggers for the light. Please check if the LUX is working consistently because this is a known ‘by design’ feature of Aqara sensors.

There are by the way a couple of nice blueprints to get this working too. For example: blueprint motion light brightness · GitHub

Thanks for the heads up @mhoogenbosch I’ll look into this.

1 Like

Thanks for all of your help on this. Finally got it to work - not exactly sure why it was not working as described initially after your guidance, but it eventually started to function.