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

The use of helper entities is a design choice I made for this blueprint. However, you do not have to display them on lovelace in order to set them. You can set entity values from the developer tools page in Home Assistant.

In mi case it is because most of my motion sensors are baterry powered, and have a big cooldown time

Maybe I misread something, But I cannot figure out what I’m doing wrong:
I have the most simple automation with a door sensor.
If the door opens, a light should turn on inside the house.
When the door closes the light should stay on for a minute.
My Settings:
Motion sensor: door sensor
Target entity: light inside the house:
(OPTIONAL) Turn off wait time (minutes): 1
everything else is not filled in.

When the door opens my light turns on. But when I close the door the light turns of directly and doesn’t wait for 1 minute.
I can set the turn of wait time to 1, 5 or 10, the light always turns of directly when the door closes.

my automation file:
use_blueprint:
path: freakshock88/motion_illuminance_activated_entity.yaml
input:
motion_sensor: binary_sensor.deur_sensor_houthok_access_control_window_door_is_open
target_entity: switch.sfeerlamp_hoek
no_motion_wait: ‘1’

You probably need to set no_motion as a helper entity. See Input Datetime - Home Assistant

But I am still struggling a bit too to get this blueprint working :wink:

be good to have the option for only turn the lights on when the sun is set/before sunrise. rather than/in addition to a fixed time, for those who don’t have illuminance sensors.

Tried it, didnt’t work. I know use the blueprint from the link below. Also set a no_motion delay and that works. So I think there is something wrong with this blueprint.

@thefunkygibbon I use this one with sunset and sunrise. and there the no_motion delay works fine.
https://community.home-assistant.io/t/turn-light-on-and-off-based-on-detected-motion-with-sun-condition/266013/10

There is not something wrong with this blueprint, otherwise we would have more complaints :wink:

Like @beurdy said, you cannot use hardcoded values for the no_motion_wait variable. You need to use an input_number helper enttity, this is described in the first post.

In the end the automation would then look something like:

  - alias: Turn on hallway lights on motion detected
    initial_state: true
    use_blueprint:
      path: freakshock88/motion_illuminance_activated_entity.yaml
      input:
        motion_sensor: binary_sensor.motion_sensor_hallway_occupancy
        target_entity: switch.shelly_hal_relay_0
        no_motion_wait: input_number.hallway_no_motion_turn_off_delay

I think there are plenty of other blueprints what support the sunrise/sunset scenario.
If I would add it also to this only it would become a bloated mess I’m afraid.

Yes I am sure. I have changed the target entity to multiple things. Originally I made a scene that would do multiple things once activated but when it was activating any time motion was detected I tried simplifying it with a couple different lights and outlets (one after the other, not all at once). But no matter what time I put in the input_datetime I couldn’t get this blueprint to fire correctly. I ended up makeing a automation that triggers a script. The automation is like this (i’ll post the script below it):

alias: Weekday Wakeup
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.lr_motion
    to: 'on'
condition:
  - condition: time
    after: input_datetime.wake_time
    before: input_datetime.end_wake_time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
action:
  - service: script.wakeup
mode: single

…and the script is below (it turns on various WLED instances, opens youtube on the TV and a few other things but most importantly it turns off the above automation, otherwise additional motion would continue triggering the automation. There is also a 3rd automation which simply turns on the above automation everyday at 4am (it doesn’t trigger it, just turns it on and makes it available for when motion is detected):

sequence:
  - service: media_player.turn_on
    target:
      entity_id:
        - media_player.main_tv
        - media_player.roku_streaming_stick
  - delay:
      hours: 0
      minutes: 0
      seconds: 4
      milliseconds: 0
  - service: media_player.select_source
    target:
      entity_id: media_player.roku_streaming_stick
    data:
      source: YouTube
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: remote.send_command
    target:
      entity_id: remote.roku_streaming_stick
    data:
      command: left
      delay_secs: 1
  - service: remote.send_command
    target:
      entity_id: remote.roku_streaming_stick
    data:
      command: select
      delay_secs: 1
  - device_id: 1367990c3a2e022f22f0c40ed01641d0
    domain: select
    entity_id: select.wled_coolclock_preset
    type: select_option
    option: twelve
  - device_id: d0d6487fde13b0088a56e7a1f09d7da0
    domain: select
    entity_id: select.wled_lamp_preset
    type: select_option
    option: Third
  - service: scene.turn_on
    target:
      entity_id: scene.brighter_morning
    data:
      transition: 295
  - service: light.turn_on
    target:
      entity_id: light.cam3_feeder_level_indicator
    data:
      brightness: 165
      transition: 300
  - service: automation.turn_off
    target:
      entity_id: automation.weekday_wakeup
mode: single
alias: wakeup

these were built with the visual editor and could probably be condensed and simplified but it was my work around at the time back in June and has worked reliably since then.

Trying to set-up this Blueprint for the first time. Want to use the illuminance sensor but when I select the picker it shows “No matching entities found”. I have 3 different sensors that all support luminance.

Can someone help. The blueprint works however the sensor I use is a door sensor. Unfortunately the automation runs when I close the sensor/door, when I actually want it to turn on when opening door. So can I get it to work the other way around? Any advice appreciated.

Under “Blocking entity (any entity with state on/off)”, can i place multiple entities?
Also, if i can… is the relationship between those entities is “Or” or “And”?

There is a filter on the entities that show for the Illuminance sensor selector.

          domain: sensor
          device_class: illuminance

Using customize.yaml you can fix this.

If you define the automation by hand it will probably still work without changing your illuminance entity itself.

You could define a binary_sensor of which the value is the opposite of the door sensor, and use this as the triggering entity of the blueprint.

Something like:

template:
  - binary_sensor:
      - name: "Reverse door state"
        state: "{{ states.door_sensor.state == 'off' }}"

No that is not supported by this template directly, however you can work around it by using a group. In this case it works as a AND condition, so all entities in the group have to be on for the blocking entity to be active.

Another alternative (if you want OR) is a binary sensor:

template:
  - binary_sensor:
      - name: "Blueprint should be blocked"
        state: "{{ states.blocking_entity_1.state == 'on' or states.blocking_entity_2.state == 'on' }}"

I want the blueprint to be triggered using multiple motion sensors (either one may detect motion). I created a group and entered that group as the motion detector in the blueprint.

Doesn’t seem to work… Is it possible to change this?

This exact scenario should work fine in this blueprint, I use it myself. Is the group state ‘on’ when one of the motion sensors detect motion?

So what did everyone here did with their template - automation?
I mean, i wanna block the motion sensor when the house is in “sleeping mode” and also when it’s “day time”.
how did you go about it?

Just use the newly created binary_sensor (as written in my previous post) as the blocker_entity.
Something like:

  - alias: Turn on attic lights on motion detected in second floor stairs during day
    initial_state: true
    use_blueprint:
      path: freakshock88/motion_illuminance_activated_entity.yaml
      input:
        motion_sensor: binary_sensor.motion_sensor
        blocker_entity: binary_sensor.blueprint_should_be_blocked
        target_entity: scene.second_floor_hallway_day
        illuminance_sensor: sensor.motion_sensor_illuminance
        illuminance_cutoff: input_number.illumination_attic_low_cutoff
        no_motion_wait: input_number.second_floor_hallway_no_motion_turn_off_delay
        time_limit_after: input_datetime.second_floor_hallway_lights_turn_on_after_limit
        time_limit_before: input_datetime.second_floor_hallway_lights_turn_on_before_limit
        target_off_entity: light.attic

I’m new to HomeAssistant but I’m very eager to learn. I’m using this excelent blueprint but I quite sure that I have made a mistake.

I created a helper for the date and time. I also created a helper for a timer. But I don’t think this helper is needed.

Here’s the yaml that is generated when I use the UI.

I would really appreciate a pointer here. I think that maybe the illuminance_cutoff is the problem?

alias: Turn on light, switch, scene, script or group based on motion and illuminance.
description: ''
use_blueprint:
  path: freakshock88/motion_illuminance_activated_entity.yaml
  input:
    no_motion_wait: '10'
    motion_sensor: binary_sensor.shed_motion_sensor
    target_entity: scene.shed_evening_lights
    illuminance_sensor: sensor.shed_motion_sensor_light_level
    illuminance_cutoff: 1.0 lx
    time_limit_after: input_datetime.wined_down
    target_off_entity: light.shed_lights