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

I can’t get this to work correctly at all.

I am using a Philips Hue Sensor via MTQQ and this plugin

If I don’t see the Lux the light will always come on and go off on the time set within MQTT and not follow the time within the blueprint.

If I set a Lux to only turn on when dark, its doesn’t even turn on.

I know I am missing something but I don’t know what it is.

Also, how do I import the script from post 357 to test it?

Apologies, still getting to grips with HA (moved from Smartthings)

Welcome to the forums!

When using a blueprint, YAML code is created for the automation.
Can you post your generated automation code so I can review the contents?
It should look something like this and should be in the automations.yaml file:

  - alias: Turn on second floor hallway lights on motion detected during day
    id: 55d1042c98d244adb1a7bad7d9eb25dd
    initial_state: true
    use_blueprint:
      path: homeassistant/motion_illuminance_activated_entity.yaml
      input:
        motion_sensor: group.motion_detectors_hallway_light
        target_entity: scene.second_floor_hallway_day
        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_after_limit
        time_limit_before: input_datetime.second_floor_hallway_lights_turn_on_before_limit
        target_off_entity: light.second_floor_hallway_light
  • id: ‘1656278177442’
    alias: Kitchen Lights
    description: ‘’
    use_blueprint:
    path: freakshock88/motion_illuminance_activated_entity.yaml
    input:
    motion_sensor: binary_sensor.kitchen_sensor_occupancy
    target_entity: light.office_copper_light
    illuminance_sensor: sensor.kitchen_sensor_illuminance_lux
    no_motion_wait: ‘5’
    illuminance_cutoff: ‘20’

Office Copper Light is a Ikea bulb I was using to test with (as its in my office with the sensor :wink: )

I’m having the same issue as others with lights not turning off since 2022.6 update. I have updated your blueprint to the latest version (delete & reimport), as well as create new automations after updating. If I don’t define a value for Turn off wait time (minutes), then the lights will not turn off. Interestingly, even though you say hard-coded values don’t work, if I use 0, it does work.

Here is the log output when Turn off wait time (minutes) is undefined:

2022-07-07 00:48:29 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights] Garage Motion Lights: Restarting
2022-07-07 00:48:29 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights] Garage Motion Lights: Running automation actions
2022-07-07 00:48:29 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights] Garage Motion Lights: Executing step call service
2022-07-07 00:48:29 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights] Garage Motion Lights: Test condition template: False

And here is the log when Turn off wait time (minutes) = 0:

2022-07-07 00:50:17 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights_2] Garage Motion Lights 2: Restarting
2022-07-07 00:50:17 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights_2] Garage Motion Lights 2: Running automation actions
2022-07-07 00:50:17 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights_2] Garage Motion Lights 2: Executing step call service
2022-07-07 00:50:17 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights_2] Garage Motion Lights 2: Test condition template: True
2022-07-07 00:50:17 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights_2] Garage Motion Lights 2: Executing step wait for trigger
2022-07-07 00:50:17 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights_2] Garage Motion Lights 2: Initialized trigger

2022-07-07 00:51:22 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights_2] Garage Motion Lights 2: Executing step delay 0:00:00
2022-07-07 00:51:22 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights_2] Garage Motion Lights 2: Test condition template: True
2022-07-07 00:51:22 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights_2] Garage Motion Lights 2: Choose at step 6: default: Running automation actions
2022-07-07 00:51:22 INFO (MainThread) [homeassistant.components.automation.garage_motion_lights_2] Garage Motion Lights 2: Choose at step 6: default: Executing step call service

It appears there’s a bug in the template somewhere that only manifested after 2022.6, because previously it worked fine for many months.

I see what is wrong, please check this part of the FAQ which I have just added, since this goes wrong often with new users of the blueprint.

Now that you have pointed it out, its very much as case of RTFM!!!

Apologies. I think I now have it working. Just need to play around with the “Turn off wait time” - I have set it to 1 (a helper) but in MQTT the sensor is get to 5 secs before its resets its self, so the light goes off after 5 secs. I think I need to have a play!

Thanks for your report. You are correct. I have now edited the blueprint to fix the no_motion_wait undefined scenario. Please update the blueprint and try again :slight_smile:

Updated blueprint but still getting same behaviour.

  • id: ‘1656278177442’
    alias: Kitchen Lights
    description: ‘’
    use_blueprint:
    path: freakshock88/motion_illuminance_activated_entity.yaml
    input:
    motion_sensor: binary_sensor.kitchen_sensor_occupancy
    target_entity: light.office_copper_light
    illuminance_sensor: sensor.kitchen_sensor_illuminance_lux
    no_motion_wait: input_number.5
    illuminance_cutoff: input_number.20

Light will go off after 10 seconds.

I have updated the timeout to 20 and it works for 20 minutes. It doesn’t like the smaller numbers for some strange reason.

Do you actually have helper entities defined called input_number.5 and input_number.20? That does not make sense. The helper entity should have a logical name i.e. input_number.kitchen_lights_turn_off_wait_time_minutes and a VALUE of 5.

Please RTFM again :wink:

I do this time :slight_smile:

Please give your entities a more descriptive name, otherwise your setup will become a mess.
See my example from the states page, and note the value.

Yes, I was only using them for testing and was going to set them correct when done - honest :wink:

I have deleted them all and rebooted - made 2 new ones for the timeout and the lux and it looks to be working correctly now. Many thanks for your help.

1 Like

I use this for illuminating the kitchen. When the light is turned on by this blueprint (presence detected), it correctly turns off again later. But when the light is turned on any other way (e.g. someone using the wall switch) it stays on forever. I would prefer that it then also turns out when the presence sensor recognizes that noone is there any more.

Can this be achieved with this blueprint?

No, your usecase is not supported in this blueprint. It should not be too hard to create a blueprint or automation to have logic like you are describing though.

1 Like

I have tried every single numbering type of input selection through the UI. Nothing works. Can you give a step-by-step guide as part of your documentation on how to build a 5 minute timer? I see that this thread is riddled with people having the same issues as I am. They magically can get it fixed, I cannot. I have no magic.

Aqara only updates lux when movement is detected. Maybe that’s the reason?

hi,

my automation is as follows (however, the turn off does not work unless i remove the time after

alias: Master WC - Night
description: ""
use_blueprint:
  path: freakshock88/motion_illuminance_activated_entity.yaml
  input:
    motion_sensor: binary_sensor.master_wc_motion_sensor_occupancy
    target_entity: switch.master_wc_switch_center
    illuminance_sensor: sensor.master_wc_motion_sensor_illuminance_lux
    illuminance_cutoff: input_number.automation_value_wc_illumination_cutoff_master
    time_limit_after: input_datetime.automation_value_time_limit_after
    no_motion_wait: input_number.automation_value_turn_off_wait_minutes

What is the value for your entity
input_datetime.automation_value_time_limit_after?

It is 09:30PM

I was wondering about the actual value that shows in the ‘States’ section of the developer Tools in Home Assistant.
It should show a date in this format:


Also note the attribute has_date: false.
If it does not, check the examples in the first post on how to set up the input_datetime entity.