Turn light on and off based on detected motion with sun condition

Good Automation!

Can you add some brightness to turning on the light? Or can you tell me how to do it myself?

Thanks in advance and keep up the good work

Do not understand, if the light is on why to turn on?

1 Like

change

- service: light.turn_on
    target: !input light_target

to:

service: light.turn_on
target: !input light_target
data:
  brightness: 50

No. When light is on manual automation not run, but when light is off (no turn manual) automation based on motion and elevation sun run…
But for this we must add condition…

1 Like

The Blueprint worked like a charm, thanks for sharing!

hey thanks for this , how can i see my devices that are switches ? i only see lights, but all my lights are via fibaro swithes, thanks.

I don’t know if it’s possible to allow 2 types of devices in blueprints. you can customize the switches as lights.
customizing-devices

and the other way around ?
i changed the domain to switch in the script and see the switches now, but what else to change ? domain: switch

I didn’t find a way to keep 2 domains, you can use my blueprint as a base for a switch or keep your lights as lights and switches, see here: https://www.home-assistant.io/integrations/light.switch/

via the integrations light.switch i can see the devices as entities and selectable , so i will work like that. many thanks for the info. edit: not working for me , i use fibaro double switch, when added this one , all of them go unavailable …with single swicthes it works. Changed the domain, all the lights that i need are on a switch , so that is a better solution for me.

Does this have a manual override of the motion detector? I want this in the bedroom but I do not want the light turning on when I move during my sleep.

Thank you for the blueprint. I’m new to HA from smartthings I’ve been wanting sun setting forever with smartthings. I do however have a question. Is there a way to add a time based stop? EX I like the motion in the evenings but after 10pm when everyone is asleep I don’t need the animals running through the motion rooms turning on and off lights all night? thanks for the help

Hi, thanks for this, however I can’t get it to trigger correctly. I’m trying to do a basic ‘Turn off lights after 5 seconds, when there is no motion detected’. I have set the ‘Wait time’ to ‘5 seconds’, but the light still stays on.

Blueprint:

alias: Turn of WC Light when no motion
description: ''
use_blueprint:
  path: >-
    Marcos_Felipe/turn-light-on-and-off-based-on-detected-motion-with-sun-condition.yaml
  input:
    motion_entity: binary_sensor.wc_motion_sensor
    light_target:
      entity_id: light.wc_light
    sunrise_offset: 5
    sunset_offset: 2
    no_motion_wait: 5

Help would be appreciated, thanks.

the parameter to turn off after movement depends on the time your sensor changes the sensor status to off, mine for example takes 2 minutes.

Is there any reason the offsets are not allowed to be less than 0? I want my automation to be able to trigger 30 minutes before sunset, but the min_value for sunset_offset is 0.

Hi,

I use this variant:

blueprint:
  name: Motion-activated Light On at Sunset
  description: Turn on a light when motion is detected On At Sunset.
  domain: automation
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion

   elevation_shift:
      name: Elevation Shift
      description: Using an elevation offset (height of sun relative to the horizon) to shift the sunset trigger, either earlier or later. Positive values bring the automation start time forward, whilst negative values delay the start time.
      default: 0.0
      # Use a selector, to set the time shift or offset
      selector:
        number:
          min: -10.0
          max: 10.0
          mode: slider
          step: 1.0

    target_light:
      name: Lights
      description: This is the light (or lights) that will be activated at sunset
      selector:
        target:
          entity:
            domain: light

    target_brightness:
      name: Brightness
      description: Brightness of the light(s) when they're activated
      default: 50
      selector:
        number:
          min: 5.0
          max: 100.0
          mode: slider
          step: 5.0
          unit_of_measurement: '%'

    target_color_temp:
      name: Temperature
      description: Termperature of the light(s) when they're activated
      default: 280
      selector:
        number:
          min: 153
          max: 454
          mode: slider
          step: 1

    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

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

variables:
  target_brightness: !input 'target_brightness'
  target_color_temp: !input 'target_color_temp'

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

condition:
  - condition: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: !input elevation_shift

action:
  - service: light.turn_on
    target: !input target_light
    data_template:
      brightness_pct: '{{ target_brightness | int }}'
      color_temp: '{{ target_color_temp | int }}'
  - wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - delay: !input no_motion_wait
  - service: light.turn_off
    target: !input target_light
2 Likes

Hi,

thank you for the blueprint.

But the specification in minutes for the values sunrise_offset and sunset_offset didn´t work for me.
I had to specify both in the following format:

sunrise_offset: '02:00:00'
sunset_offset: '01:00:00'

hi, if it possible to add multiple motion sensor, or even a door sensor to the blue print?

1 Like

I’d find this very useful too.

2 Likes

have you figured it out??