Motion Sensor Routinely Goes Unavailable, Breaking Automation

I’m using an Aqara P1 motion detector in a guest room to control lights. The automation to turn lights on works great, but the automation to turn them off is not working.

In looking into the cause, I noticed a pattern in the history… it seems like during periods where the room is unoccupied, the sensor will detect ‘Clear’ for 10 minutes, then go unavailable for 45 minutes, then repeat.

Since my automation is looking for the sensor to report ‘Clear’ for 30 minutes, it never runs. Since I don’t know of a way to fix the sensor, I’m trying to figure out how to fix my automation. I guess I’m trying to come up with something like “No motion detected (sensor reports ‘on’) for 30 minutes” vs “Sensor reporting ‘Clear’/‘off’ for 30 minutes.”

Would appreciate any suggestions. Thanks!

alias: Motion - Guest Room lights off
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.guest_room_motion_detector_occupancy
    to: "off"
    for:
      minutes: 30
      seconds: 0
condition:
  - condition: not
    conditions:
      - condition: time
        after: "07:00:00"
        before: "17:30:00"
        weekday:
          - mon
          - fri
action:
  - service: light.turn_off
    target:
      entity_id:
        - light.guest_room_built_in_cans
        - light.guest_room_ceiling_fan
        - light.wled
    data: {}
mode: single

How about

from: "on"

instead?

Works… thank you!!

1 Like