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

Blueprint is working great. The only issue I am having is more a logic one. I am using in the main area of the house. When we come down in the morning it is dark and the lights come on. But then they never go off as the room stays “active” regardless how bright is eventually gets. Could be for any part of the day if its rainy and dark then lights still are on but there would always be motion to keep the lights active.

Hi what value do you use for the aqara motion sensor? What zigbee do you use?. I’m using zigbee 2 mqtt with the 5 sec hack and even when lux is 66 and I set 200 as the cut off. The light won’t come on. Any advice would be appreciated

Hi @MrRodz, I ended up not using this template with the Aqara motion sensor because as far as I can tell, the sensor does not put out the lux level until the sensor is activated by motion. So you can’t use the lux level to decide if you’ll turn on the light since it doesn’t know the lux level until after the sensor sees motion. Does that make sense? I just used a sunset-sunrise timer to decide when it will turn on the light. I use the Conbee 2 and have been very satisfied.

1 Like

Ahh ok thank you. Yeah that makes sense… sort of. I used to use domoticz and had a blocky set up to do a similar thing, well jut bring the light on if the lux was below 250. It worked in that instance. I’ll see if I can find out the difference. Sun position is not an option with the weather by me. Thanks for getting back to me.

Hi,
I have a problem, or a thinking error. I am trying to turn on a house light only when the outside brightness falls below a certain value. In principle, this should work. I have selected the appropriate outdoor sensor under (OPTIONAL) Illuminance sensor:. This is a PD03Z Zwave sensor. It delivers the value in the following form:

Bildschirmfoto vom 2021-02-28 12-19-49

If I now set (OPTIONAL) Illuminance cutoff value: e.g. 250, the automation should work at less than 250Lux. Is this a thinking error? Unfortunately it does not work at all. That means as soon as I enter a value under (OPTIONAL) Illuminance cutoff value (no matter which one) the error occurs? Is it maybe the comma/dot in the return value of the sensor?

Like I posted multiple times in this thread, if you want/need to specify brightness or other attributes of a light, create a scene for that and use it in this blueprint.

This is by design. Originally the blueprint checked for illumination every time motion was detected. However, this created a bug where if the light itself was responsible for illuminating to above the illuminance threshold, the automation would quickly turn off the light again. To mitigate this, I have removed the illuminance check when the light was already on. Unfortunately this does not help your usecase.

In my house I leave lights in the ‘main area’s’ always on when I’m home. For area’s where I am only present for a shorter time I use this blueprint.

You probably are not using helper entities for the cutoff value.
Read the first post again to read how to set it up.

This blueprint is helpful! One thing I did have an issue with is if you use a ‘before’ and ‘after’ times that span midnight, it does not appear to work.
For example:
I have a nightlight that comes on if we get out of bed. If I set the after to 19:00 but the before is set to 07:00, the condition doesn’t seem to evaluate properly. Not sure if this is a limitation of the input_datetime entities, but just FYI.
I’ll probably use lux instead for this application.
Thanks for sharing!

Hello and thank you for your work.
I noticed that if I insert as time: after 18:00 but before 06:00 (example) the automation does not work as there is the “change of day” and I think the code is partially wrong.

If I set the time within the limits of the day instead it works well.

That is weird.
I use an automation that also spans midnight, for turning on my hallway light next to my bedroom during thte night. It is working without issues.

My automation:

  - alias: Turn on second floor hallway lights on motion detected during night
    description: ''
    use_blueprint:
      path: homeassistant/motion_illuminance_activated_entity.yaml
      input:
        motion_sensor: group.motion_detectors_hallway_light
        target_entity: scene.second_floor_hallway_night
        illuminance_sensor: sensor.motion_sensor_2nd_floor_hallway_illuminance_lux
        illuminance_cutoff: input_number.illumination_zolder_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_before_limit
        time_limit_before: input_datetime.second_floor_hallway_lights_turn_on_after_limit
        target_off_entity: light.licht_gang_2e

The values for the input_datetimes are:

 input_datetime.second_floor_hallway_lights_turn_on_before_limit: 22:00:00
 input_datetime.second_floor_hallway_lights_turn_on_after_limit: 08:00:00

(The reason them seem backwards is because I use the same limits for the daytime automation)

Are you using the latest version of the blueprint? If you are not sure, please delete it and reimport it.

Hi,

I have been using this blueprint and on the most part it works great and is easy to setup.

What I am having problems with is i want the lights to delay turning off until the tv is off. I have tried setting the tv as a “Turn-off Blocking entity” but it seems to still turn the lights off when the tv is on.

I tried setting the “Turn-off entity” to be a script which itself turns the lights off only if the tv is off, but the script isnt called. it seems to send an off command to the “Target entity.” which is a separate script?

Im sure i am doing something wrong?

Thank you for answering.
I took your advice. Project deleted and re-imported.
Same problem.

- id: '1615487599067'
  alias: Motion Accendi Luce Cortesia
  description: ''
  use_blueprint:
    path: freakshock88/motion_illuminance_activated_entity.yaml
    input:
      motion_sensor: binary_sensor.motion_lavanderia
      target_entity: switch.power_presa_luce_notturna
      illuminance_sensor: sensor.motion_luminosita_lavanderia
      illuminance_cutoff: input_number.illuminazione_lucenotte
      time_limit_after: input_datetime.accendi_dopo_lucenotte
      time_limit_before: input_datetime.accendi_prima_lucenotte
      no_motion_wait: input_number.no_motion_lucenotte

The values for the input_datetimes are:

input_datetime.accendi_dopo_lucenotte: 19:00:00
input_datetime.accendi_prima_lucenotte: 07:00:00

If I try with these values ​​it works

input_datetime.accendi_dopo_lucenotte: 00:00:00
input_datetime.accendi_prima_lucenotte: 23:59:00

That´s a very important point, took me some time to track down the reason why my automation didn´t fire (had a hard coded value in the “(OPTIONAL) Illuminance cutoff value”).

As I never handled helper entities before:
how to permanently store values in helper entities? Are they reboot resistent once set?

Update: found it in the docs, should be safe to survive reboots according to Input Select - Home Assistant.

New issue: light does not get turned off after motion sensor detects no motion anymore.

Whats wrong?

alias: Light ON_Room
description: ''
use_blueprint:
  path: freakshock88/motion_illuminance_activated_entity.yaml
  input:
    motion_sensor: binary_sensor.motion_room
    target_entity: light.bulb_room
    illuminance_sensor: sensor.illuminance_sensor_room
    illuminance_cutoff: input_number.illuminance_minimum_room

Answered that one by myself too: There´s no auto off when there´s no helper entity for the (OPTIONAL) Turn off wait time (minutes).

So lessons learned:

  1. This blueprint exactly does what it promises in its name: turn on something. Turning off and other stuff is completely optional and not working by default. Wrong expectations on my side :slight_smile:
  2. Read the whole blueprint documentation (first post and blueprint texts in HA). Without helper entities you won´t get far beyond the initial use-case (turning things on based on motion). Using helper entities is a bit overkill where hard coded values would be enough too.
  3. Helper entity for (OPTIONAL) Turn off wait time (minutes) can have value 0 which means light will be turned off immediately when motion sensor detects no movement anymore.

Feature request @freakshock: accept seconds instead of minutes for the (OPTIONAL) Turn off wait time (minutes) entity. That would allow a better timing.

i have a problem with automation: i set a Turn off wait time of 1 minute but the automation activate the output only during the on state of trigger

The turn-off blocking entity only works when this entity’s state is ‘on’.
Probably your TV state is not ’ on’ , but ‘playing’ when it is on. That’s why it is not working.
Tou could work around that by setting a binary sensor based on your TV’s state.

Turn-off enity will turn off the defined entity. Turning off a script has no meaning here.

1 Like

Thanks freakshock. That makes sense I will give that a go. :+1:

Yup. Looks like you ran into the same issue that I did. I could not get the times to span midnight. Other than that, it’s a good blueprint.

Hey @freakshock,

first of all, thanks for this well working blueprint! I have a scenario where I’m just wondering if I should request and additional feature from you. Or maybe you can suggest another way using the existing features?

My scenario: I have a night mode (on/off). The brightness of the lights should be controlled depending on whether the night mode is on or off. In addition, it would make sense to define a value (e.g. using input_number) for the brightness in each mode.

Which way would you suggest?

Cheers, red