Best lighting automations with motion sensors

Hi all,

I am new to home home assistant. I have motion sensors for all my lights and I first set up different automations for on during the day, during the evening and off. So, three automations for one room. Now I discovered the “Choose” function and I can bring all three into one automation. This got me thinking, is there a better, more efficient way of doing this? Herewith a typical automation:

alias: Upstairs Office Lights
description: ''
trigger:
  - type: motion
    platform: device
    device_id: c980d9d34016384294823a1d0bd20a31
    entity_id: binary_sensor.upstairs_office_sensor_motion
    domain: binary_sensor
    id: Motion
  - type: no_motion
    platform: device
    device_id: c980d9d34016384294823a1d0bd20a31
    entity_id: binary_sensor.upstairs_office_sensor_motion
    domain: binary_sensor
    id: No Motion
    for:
      hours: 0
      minutes: 20
      seconds: 0
      milliseconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Motion
          - condition: time
            after: '07:00'
            before: '18:00'
          - type: is_illuminance
            condition: device
            device_id: c980d9d34016384294823a1d0bd20a31
            entity_id: sensor.upstairs_office_sensor_light_level
            domain: sensor
            below: 10
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.upstairs_office_lights
            data:
              color_temp: 231
              brightness_pct: 100
      - conditions:
          - condition: trigger
            id: Motion
          - condition: time
            after: '18:00'
            before: '07:00'
          - type: is_illuminance
            condition: device
            device_id: c980d9d34016384294823a1d0bd20a31
            entity_id: sensor.upstairs_office_sensor_light_level
            domain: sensor
            below: 10
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.upstairs_office_lights
            data:
              color_temp: 425
              brightness_pct: 100
      - conditions:
          - condition: trigger
            id: No Motion
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.upstairs_office_lights
    default: []
mode: single

I think what you are trying to do is essentially correct although you may run into problems with the time conditions. These are in effect an ‘AND’ so ‘after 18:00’ and ‘before 07:00’ can never be true. To get arround this I use an ‘OR’ condition as in the example below.

Personally I find it easier to manage if I have 1 automation per light (or light group) otherwise things can get quite complex (for me at least). Also, if the lights are dimable then I dim them for 30 secs to warn that they are about to go off.

- id: '1585041688580'
  alias: Kitchen LEDs Control
  description: Controls kitchen LEDs based on motion sensor and occupancy
  trigger:
  - device_id: e3373f55ca5c4f9c896896bd49619215
    domain: binary_sensor
    entity_id: binary_sensor.neo2
    platform: device
    type: motion
  - entity_id: binary_sensor.z2_occupied
    platform: state
    to: 'on'
  condition:
  - condition: or
    conditions:
    - after: sunset
      after_offset: -00:30:00
      condition: sun
    - before: sunrise
      before_offset: 00:30:00
      condition: sun
  action:
  - brightness_pct: 100
    device_id: 5320c28c7c1e45c580aa9a5ad9bc4432
    domain: light
    entity_id: light.kitchen_leds1
    type: turn_on
  - brightness_pct: 100
    device_id: 793e56970e0d467a9afca2bd780b0797
    domain: light
    entity_id: light.kitchen_leds2
    type: turn_on
  - delay: 00:05:00
  - timeout: 00:05:00
    wait_template: '{{  is_state(''binary_sensor.neo2'', ''off'') and is_state(''binary_sensor.z2_occupied'',
      ''off'') }}'
  - brightness_pct: 40
    device_id: 5320c28c7c1e45c580aa9a5ad9bc4432
    domain: light
    entity_id: light.kitchen_leds1
    type: turn_on
  - brightness_pct: 40
    device_id: 793e56970e0d467a9afca2bd780b0797
    domain: light
    entity_id: light.kitchen_leds2
    type: turn_on
  - delay: 00:00:30
  - device_id: 5320c28c7c1e45c580aa9a5ad9bc4432
    domain: light
    entity_id: light.kitchen_leds1
    type: turn_off
  - device_id: 793e56970e0d467a9afca2bd780b0797
    domain: light
    entity_id: light.kitchen_leds2
    type: turn_off
  mode: restart

The above needs simplifying to use a light group which I have already defined but have not yet got around to incorporating in the automation.

At the end of the day though it is whatever works best for you.

Thanks, using sunrise and sunset is also a good idea. I want to minimize my automations so that I can easily disable them when on holiday. So using one automation for a room light instead of three is definitely better. I used to use the Philips Hue software before is saw the “light”, but the concept of this automation is similar in where the entire automation is built around the sensor, time of day and light conditions.

Luminance is by far the better way to go for a condition if you have a suitable sensor. A sunrise/sunset is an alternative if you don’t have a luminance sensor but will not work as well e.g. on a very cloudy day.

1 Like