Motion Sensor Automation With Timer or State

I’m trying to configure my Xiomi Aqara motion sensor to trigger my kitchen lights with the automation below but i’m having problems with keeping the lights on when i’m actually in the kitchen.

I think the problem is my automation below only switchs on light when my sensor goes from “off” to “on” and since i’m in kitchen, sensor’s detection keep staying at “on” state.

What you guys do in a similar case ? Any direction will be appreciated :slight_smile:

By the was is it possible to write an automation to check for the sensor’s motion state every 2 minutes and if it’s “off” it’ll switch off the lights and if it’s “on” it’ll restart my timer.

configuration.yaml

timer:
  timer_kitchen:
    duration: '00:02:00'

automations.yaml

- id: '1579199718836'
  alias: KitchenMotion
  trigger:
  - entity_id: binary_sensor.motion_sensor_01
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      brightness: 255
      entity_id: light.kitchen
    service: light.turn_on
  - data:
      entity_id: timer.timer_kitchen
    service: timer.cancel
  - data:
      duration: 00:02:00
      entity_id: timer.timer_kitchen
    service: timer.start
  - data:
      message: (re)started
      name: 'Timer for Kitchen: '
    service: logbook.log
  initial_state: 'on'

- id: '0000000000012'
  alias: Timer Kitchen
  trigger:
  - event_data:
      entity_id: timer.timer_kitchen
    event_type: timer.finished
    platform: event
  condition: []
  action:
  - data:
      entity_id: light.kitchen
    service: light.turn_off
  initial_state: 'on'

My suggestion would be to scrap the timer entirely and use these automations instead:

- id: '1579199718836'
  alias: KitchenMotion
  trigger:
  - platform: state
    entity_id: binary_sensor.motion_sensor_01
    from: 'off'
    to: 'on'
  action:
  - service: light.turn_on
    entity_id: light.kitchen
    data:
      brightness: 255
- alias: Turn kitchen lights off
  trigger:
  - platform: state
    entity_id: binary_sensor.motion_sensor_01
    to: 'off'
    for: '00:02:00'
  action:
  - service: light.turn_off
    entity_id: light.kitchen

The second automation will turn the lights off if the motion sensor goes to off for 2 minutes.

6 Likes

Wow thanks, this really changed my perpective. Tested and working nicely. Cheers :+1: