Q: Motion Lights automatio

Hi all,

My motion and turn_on services work in my automation. But when the motion sensor detects NO motion, the lights should turn off after 1 minute… somehow my automation won’t work…

Can someone please have a look and help me out ???

Kindly appreciated !


- id: '1641772686099'
  alias: Keuken lichten aan bij zonsondergang
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: 316e40db262e880e3f4197c5515f33c9
    entity_id: binary_sensor.hue_motion_sensor_2_motion
    domain: binary_sensor
  - type: illuminance
    platform: device
    device_id: 74bb95876114f6a3a38f492cb9d97d63
    entity_id: sensor.hue_motion_achtertuin_illuminance
    domain: sensor
    below: 10
  condition: 
    condition: state
    entity_id: light.dimmable_light_6
    state: 'off'
  action:
  - service: input_boolean.turn_on
    entity_id: input_boolean.motion_detected
  - type: turn_on
    device_id: 0fea5c2c902a92aa76287e38bda8f4f0
    entity_id: light.dimmable_light_6
    domain: light
  - type: turn_on
    device_id: d40cf8a83d19333b9190cb78bf459f4f
    entity_id: light.dimmable_light_7
    domain: light
  mode: single



- id: '1641772686100'
  alias: Keuken lichten uit na geen beweging
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: 316e40db262e880e3f4197c5515f33c9
    entity_id: binary_sensor.hue_motion_sensor_2_motion
    domain: binary_sensor
    to: 'off'
    for: '00:01:00'
  condition: 
    condition: state
    entity_id: input_boolean.motion_detected
    state: 'on'
  action:
  - service: input_boolean.turn_off
    entity_id: input_boolean.motion_detected
  - type: turn_off
    device_id: 0fea5c2c902a92aa76287e38bda8f4f0
    entity_id: light.dimmable_light_6
    domain: light
  - type: turn_off
    device_id: d40cf8a83d19333b9190cb78bf459f4f
    entity_id: light.dimmable_light_7
    domain: light
  mode: single
 

You wanted the other quotes for code markup.

Hi Tinkerer,

Thx for you quick answer, could you specify what you exactly mean ?

Thx !!!

Kr,

Bart

grafik

Use that button from the editor’s toolbar, then paste your code into the created section.

Btw: No need to re-invent the wheel, there is a “Motion-activated Light” automation blueprint, that wait’s for your configuration.

See the sticky post, point 11.

Thanks a lot ! I’ve edited the post in the right format

Kr,

Bart

You automations are ambiguous. Do you want the lights to turn on by motion AND darkness outside (sensor.hue_motion_achtertuin_illuminance) or do you want to turn on the lights on motion OR darkness outside?

Hi Christoph,

When it’s dark outside, the lights should go on when detecting motion. The lights should go on for max 2 minutes and go of if no motion is detected after those 2 minutes.

So it’s an AND statement, motion AND darkness

Kind regards,

Bart

Okay, this should work out of the box, although I recommend using the automation UI editor for safety:

alias: Keukenlichtcontrole door beweging in het donker
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.hue_motion_sensor_2_motion
    id: 'on'
    from: 'off'
    to: 'on'
  - platform: state
    entity_id: binary_sensor.hue_motion_sensor_2_motion
    id: 'off'
    from: 'on'
    to: 'off'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 'on'
          - condition: numeric_state
            entity_id: sensor.hue_motion_achtertuin_illuminance
            below: 10
        sequence:
          - type: turn_on
            device_id: 0fea5c2c902a92aa76287e38bda8f4f0
            entity_id: light.dimmable_light_6
            domain: light
          - type: turn_on
            device_id: d40cf8a83d19333b9190cb78bf459f4f
            entity_id: light.dimmable_light_7
            domain: light
    default:
          - type: turn_off
            device_id: 0fea5c2c902a92aa76287e38bda8f4f0
            entity_id: light.dimmable_light_6
            domain: light
          - type: turn_off
            device_id: d40cf8a83d19333b9190cb78bf459f4f
            entity_id: light.dimmable_light_7
            domain: light
mode: single

Hints:

  • i tend to use two triggers for state changes for off → on and on → off because it did happen in the past, that binary_sensors triggered without change (that is: sensor is off, becomes unavailable, returns back in and reports off again)
  • only if the motion sensor changed off → on (trigger-id: ‘on’) and the illuminance sensor reports a value below 10, lights are turned on. No need to check the current state of the switched lights, you can turn them on again.
  • if the motion sensor changes on → off for more than 2 minutes, the lights are turned off, despite their current state and even when it’s light outside. Since the lights should already be off, this doesn’t harm.

Thank you very much for correcting and explaining m0wlheld !!!

I’ll give it a try, but need to wait for feedback after the dark :wink: