Simple camera motion garage lights

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

I needed a simple automation for my garage lights. It needed a cooldown to prevent an infinite cycle at night, where the lights turning off causes another motion event, since I am using a camera (reolink) as the sensor. I also wanted the lights to only activate during the night. So this does just that, and nothing more!

This is my first blueprint, and also my first day with homeassistant… so hopefully I didn’t screw anything up!

# A Homeassist blueprint to run my garage lights from a reolink camera.
# A cooldown is needed, as otherwise the lights turning off causes another motion event
blueprint:
  name: Garage lights from camera motion
  description: Turn on a light when motion is detected unless it just turned off.
  domain: automation
  author: Mitchell Pleune
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          filter:
            device_class: motion
            domain: binary_sensor
    light_target:
      name: Light
      selector:
        entity:
          domain: light
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds
    cooldown:
      name: Cooldown
      default: 5
      selector:
        number:
          min: 0.0
          max: 1800.0
          step: 0.5
          mode: box
          unit_of_measurement: seconds
    enable_sun_condition:
      name: Enable time condition
      description: Should sunrise and sunset be used as conditions
      default: true
      selector:
        boolean:
    sunset_time_offset:
      name: After Sunset
      description: How long after sunset the lights will trigger
      default: "-1:00:00"
      selector:
        time: {}
    sunrise_time_offset:
      name: After Sunrise
      description: How long after sunrise the lights will still trigger
      default: "1:00:00"
      selector:
        time: {}

mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"

variables:
  switchEntityVar: !input light_target
  vooldownPeriodVar: !input cooldown

action:
  - alias: "Wait for cooldown complete"
    condition: template
    value_template: >
      {{ (as_timestamp(now()) - as_timestamp(states[switchEntityVar].last_changed)) > 10 }}
  - alias: "Make sure is at least darkish out"
    condition: sun
    enabled: !input enable_sun_condition
    after: sunset
    after_offset: !input sunset_time_offset
    before: sunrise
    before_offset: !input sunrise_time_offset
  - alias: "Turn on the light"
    service: light.turn_on
    target:
      entity_id: !input light_target
  - alias: "Wait until there is no motion from device"
    wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - alias: "Wait the number of seconds that has been set"
    delay: !input no_motion_wait
  - alias: "Turn off the light"
    service: light.turn_off
    target:
      entity_id: !input light_target