Turn a light off after 5 minutes of no motion

For the most part, I’m using Node-RED for automations but I’m just playing with the automations within HA and trying to replicate the same functionality just using the interface rather than having to resort to YAML.

One thing I can’t work out is whether you can have ONE automation that turns a light on with motion and then off again if there is no motion for 5 minutes. At the moment, I have one automation to turn the light on, and then another to turn the light off.

Is that how it goes, or is there another way of doing it?

Like I say, this is just to kick the tyres on the automations inside HA, not to find a way of achieving the goal per se.

Cheers
Andy

Hi Andy, I tend to do it all within one automation and also dim the light for 15 secs before it turns off just to let people know. See the example below:

- id: '1588702585432'
  alias: Bathroom Light On-Off
  description: Controls bathroom light based on motion sensor
  trigger:
  - device_id: 235db833caa54d49bddcb05b0f04ba12
    domain: binary_sensor
    entity_id: binary_sensor.neo4
    platform: device
    type: motion
  condition: []
  action:
  - brightness_pct: 90
    device_id: db52735c5e564774a9d7d19dd6d44e82
    domain: light
    entity_id: light.bathroom_light
    type: turn_on
  - delay: 00:03:30
  - timeout: 00:00:00
    wait_template: '{{  is_state(''binary_sensor.neo4'', ''off'')  }}'
  - brightness_pct: 50
    device_id: db52735c5e564774a9d7d19dd6d44e82
    domain: light
    entity_id: light.bathroom_light
    type: turn_on
  - delay: 00:00:15
  - device_id: db52735c5e564774a9d7d19dd6d44e82
    domain: light
    entity_id: light.bathroom_light
    type: turn_off
  mode: restart

The key thing that makes this work well is the new “restart” mode meaning the automation starts again if the motion sensor gets re-activated.

I know I don’t technically need the wait_template there but I included it anyway.

Cheers!

2 Likes

I have it working through yaml mode exactly with the automation restart mode. It can be triggered by both motion sensors, or simply by me triggering the vibration sensor of my office chair. The automation couldn’t be done like this before one of the recent HA versions.

See my snippet below:

automation:
  - alias: '[study|lights] Turn on lights when motion is detected'
    mode: restart
    trigger:
      - platform: state
        entity_id: binary_sensor.study_motion_combined
        to: 'on'
      - platform: state
        entity_id: sensor.vibration_sensor_attributes
      - platform: state
        entity_id: binary_sensor.vibration_sensor
        to: 'on'
    condition:
      - condition: numeric_state
        entity_id: sensor.average_illumination_study
        below: 40
    action:
      - service: light.turn_on
        data:
          entity_id: light.study_lights
          brightness: 255
      - service: switch.flux_study_update
      - delay:
          minutes: 15
      - service: light.turn_off
        entity_id: light.study_lights
1 Like