Turn on light, switch, scene, script or group based on motion, illuminance, sun (+ more conditions)

Answered my own question. Added a second motion detector IN the kitchen, so after motion clears that one, the automation starts the timer. :slight_smile:

How to open multiple light entities ?Motion sensing triggers multiple entities

I had the same problem as someone above… for whatever reason, automations won’t span past midnite. I ended up making on for before 23:59 and then another starting after 00:01. I read somewhere else that HA won’t run through the midnight hour, on time alone.
I don’t know if you’d be interested in expanding the blueprint, but what about adding in an option for starting before sunrise and after sunset?
Thanks!

I’m a bit confused. Can someone tell me how I can set the lights to auto turn off after 10 seconds? Motion sensor will trigger it on again, but the automation should always try to turn off light when no motion is detected.

Thanks

Same issue here, cant get past midnight with this blueprint. ie on from 07:00 till 01:00 (the next day),
I think it has nothing to do with HA, the below automation part works flawlessly:

  - condition: and
    conditions:
    - condition: time
      after: 07:30:00
      before: 02:30:00
  action:
  - type: turn_on

must be some compare issues in the blueprint.

Regards Frank.

Ok, for the middle night time, after sunset and before sunrise, I did the timer thing. I think it was bearded tinkerer, but here’s something that works for me. The motion sensor, being activated while the timer is running, resets the timer, and the timer will continue as long as there is no more motion, and finish off (turn light off) after the required time. Only thing here that doesn’t play nice, if 2 timers are running, both fire off the automations, even if the longer scheduled timer hasn’t finished. Haven’t looked into that yet. But here’s one :slight_smile:

After light is triggered on -

alias: Front Door Lamps timer starts after turning on
  description: Front Door Lamps timer starts after turning on
  trigger:
  - platform: state
    entity_id: switch.fluorescent_light_appliance_module
    to: 'on'
  condition: []
  action:
  - service: timer.start
    data:
      duration: '0'
    target:
      entity_id: timer.front_door_open
  mode: single

And then, to turn off after timer is done -

alias: New Door lamps off after 4 minute timer
  description: New Door lamps off after 4 minute timer
  trigger:
  - platform: event
    event_type: timer.finished
    id: timer.front_door_open
  condition: []
  action:
  - type: turn_off
    device_id: 394d5d8b79e6712205801db1626790c5
    entity_id: switch.fluorescent_light_appliance_module
    domain: switch
  mode: single

and in configuration.yaml, must set a timer duration -

timer:
  front_door_open:
    duration: 00:04:00
    name: Front Door Timer 4mins
    icon: mdi:door-open

This works for me, at least to turn off the light after the light is triggered on.
I just realized that this is not what we were originally talking about, so here’s the motion timer code -
This turns the lights on, at the window of time, it works prior to and then after midnight -

Timers for kitchen light-

alias: Kitchen Light timer starts
  description: Kitchen Light timer starts
  trigger:
  - platform: state
    entity_id: binary_sensor.front_room_motion_sensor
    to: 'on'
  - platform: state
    entity_id: binary_sensor.kitchen_motion_zone
    to: 'on'
  condition:
  - condition: or
    conditions:
    - condition: time
      after: '21:00'
    - condition: sun
      before: sunrise
  action:
  - service: timer.start
    data: {}
    target:
      entity_id: timer.kitchen_light_timer
  - type: turn_on
    device_id: 4856f51b9d4f30ebc0d25c555496a473
    entity_id: switch.kitchen_light
    domain: switch
  mode: single
  max: 10

################################################

  alias: Kitchen timer ends-light off 7 mins
  description: Kitchen timer ends-light off 7 mins
  trigger:
  - platform: event
    event_type: timer.finished
    id: timer.kitchen_light_timer
    event_data: {}
  condition: []
  action:
  - type: turn_off
    device_id: 4856f51b9d4f30ebc0d25c555496a473
    entity_id: switch.kitchen_light
    domain: switch
  mode: single

I am using this blueprint for an automation to turn a (Lutron Caseta) switch on whenever motion is detected (via a Philips Hue Motion Sensor) and while turning on works, the “(OPTIONAL) Turn off wait time (minutes)” appears to have no effect at all.

Basically I set its value for my automation to 5 and yet, after a few seconds the light is turned off again by the automation. There is no concurrent automation using the motion sensor and I am a bit confused what I might be doing wrong here?

The settings look like this & any hints / suggestions are highly appreciated!

You need to create an input_number entity with the value of your timeout for it to work.

nice blueprint

Since a few people have complained about issues with the blueprint not triggering when time window spans midnight, I tried to rewrite the time condition to see if this helps.

I myself could never reproduce this however with the old version of the blueprint, so I’m not sure if this new version makes any difference.

Please test it out if you like.

Thank you, will do,

Maybe it has to do with 12 or 24 hour settings?
I my self use the 24h mode.

Regards Frank

Thanks for this, it’s been running quite nicely except the same time issues people had.
I anyhow decided to run my hours by modes Day/Evening/Night toggled by a set time or manually (typically by the gf), instead of Time Start and End.
So I modified a copy of your code with an extra optional “Day / Evening / Night” mode requring it’s state to be on to run.
#happyuser

Hai freakshock,

I can confirm that the midnight spanning is now working.
Great Job, Thank you…!!

Regards
Frank

1 Like

Hi, Frank,
Could you please add a brightness slider for those who have dimmer switches?
Thank you!
I added this line manually to the bluebrint, but thats the best I could do

action:
- service: homeassistant.turn_on
  data:
    brightness_pct: 10
  entity_id: !input 'target_entity'
- condition: template

See this post for a solution.

Hey all sorry I tried searching the thread, I would like to have one motion sensor turn on multiple lights and then turn them off, sometimes one light may be on out of the group and I’d like the rest to turn on so I’m not sure if a group would work in this case. Help is appreciated!

I’m not sure I understand your requirements.
A light group forwards all commands to all lights, so if you turn the group on, all lights in that group will turn on. Is that not what you want?

Yes my apologies, I overcomplicated this in my mind, group on, group off!

still can’t get the ‘(OPTIONAL) Turn off wait time (minutes)’ to work. if i enter a time in there manually it ignores it, but it won’t let me choose a ‘time entity’ like it expects there to be (despite there being some time entities on the system)
any ideas?

Hi thefunkygibbon…

The optional needs a helper not a fixed value.
the documentation says:

Prerequisites

Some of the (optional) input values in this blueprint use helper entities you have to create yourself, to be able to dynamically set limits. It is not possible to set hard-coded limits for these inputs.

So go to settings->helpers create a time based helper with a minimum and maximum value, give it a useful name and use this name in the optional field(s). Do so with the number value for cut of illumination.

Regards Frank