Lights Automation with Field and Motion Detection

Hi All,

I have an automation that is currently working perfectly fine. The lights turn on when someone enters a field of my HikVision camera. However, the lights turn off after the time expires. Can I use the motion sensor to keep the lights on as long as motion is detected. The idea is:

1 .Turn on lights when someone enter the field sensor
2. Keep the lights on as long is motion is detected
3. Turn off lights after X minutes

The trick is to turn light on only when the field sensor is triggered and no when motion is triggered. Here is my automation:

#Front Door Camera Motion Detection Lights Trigger

  • alias: Turn on front door lights when movement is detected
    trigger:
    platform: state
    entity_id: binary_sensor.front_door_cam_sensors_field_detection
    to: ‘on’
    condition:
    condition: state
    entity_id: sun.sun
    state: ‘below_horizon’
    action:
    service: homeassistant.turn_on
    entity_id: switch.front_door_lights

  • alias: Turn off front door lights 3 minutes after last movement
    trigger:
    platform: state
    entity_id: binary_sensor.front_door_cam_sensors_field_detection
    to: ‘off’
    for:
    minutes: 3
    action:
    service: homeassistant.turn_off
    entity_id: switch.front_door_lights

Could you format your code using the </> button in the editor please? It makes it easier to see whether there are obvious syntax/indentation issues
image

For your turn off automation, from what you say you want you’d just have to use binary_sensor.front_door_cam_sensors_field_motion as your trigger…everything else looks ok.

Your description is a bit unclear. Are you saying you have another motion detector, in addition to binary_sensor.front_door_cam_sensors_field_detection? You also say it’s working perfectly fine, but it isn’t. Which is it?

It appears you’re happy with the automation that turns on the light. But what about the automation that turns off the light do you not like, or want to change?

You say you want this:

Isn’t that what’s it doing already? They way you coded it, it turns on the light when motion is first detected, and only turns it off if motion is not detected for a full three minutes. (I.e., if motion is detected again before the three minutes are up, the lights will stay on, and they won’t be turned off until motion is no longer detected, and is not detected for a full three minutes.)

He’s using a hikvision camera which supports multiple binary sensors.
Motion is just that motion, but there are other line line crossing (when you cross a predefined line that you set as a boundary), vandal alarm, etc.
As I understood he’s using field crossing as a trigger, but wants to keep the lights on as long as there’s motion, and turn the lights off x min after motion stops.
the bit that’s working is the turning the light on upon field detection, but once crossed, that sensor goes off after a while unless you cross again, hence the question about motion
@datzent83 if I’m mistaken shout out.

Ah, gotcha - binary_sensor.front_door_cam_sensors_field_motion as opposed to binary_sensor.front_door_cam_sensors_field_detection. Didn’t know that (and didn’t notice the difference in the object_id.) :slight_smile: If that’s the case, then yes, I agree, he should just change the entity_id in the trigger of the off automation accordingly and it should do what he wants.

@lolouk44 you are correct. I’ll change the second part of the automation and post bank.

Thanks!

So I had this automation working for a while, but since I upgraded to v0.94 and then v0.101 the automation stopped. I can’t figure it out. The field detection from the camera is being triggered, but the lights don’t turn on. I can’t figure out what I am missing. Capture

- alias: Turn on front door lights when movement is detected
  condition:
    condition: state
    entity_id: sun.sun
    state: below_horizon
  trigger:
    platform: state
    entity_id: binary_sensor.front_door_cam_sensors_field_detection
    to: 'on'
  action:
    service: homeassistant.turn_on
    entity_id: switch.front_door_lights
  id: 7eca2888fdb0484191cd65612fb00f32
  
- alias: Turn off front door lights 2 minutes after last movement
  trigger:
    platform: state
    entity_id: binary_sensor.front_door_cam_sensors_field_detection
    to: 'off'
    for:
      minutes: 2
  action:
    service: homeassistant.turn_off
    entity_id: switch.front_door_lights
  id: d067427c3a574a4cb5dac87cb3b389d8