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

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

Welcome to HA!

Iluminance cutoff is indeed the problem, you also need a helper entity for that.
Check the first post again:

Hang on, RTFMing again…

Wow just what I was looking for in order to limit when the automation runs.
Thx again for your effort here

Anyone using this blueprint and also have Adaptive Lighting component for Home Assistant?

It works when it detect the first motion, the adaptive light component takes over and adjusts the lights brightness and color. However, on the second motion detection its calls Light.turn_on and all lights go to full brightness and the adaptive component takes over again.

Anyone come across this issue? What was your solution?

how do i use it with humidity instead of luminance? want to use it for a bathroom fan. also can someone tell me why did my sonoff zbmini thinks of itself that it is a light? when it is a fan.

I am getting the following error on a very simple setup I removed all variables except for motion sensor, target entity and turn off wait time.

Template warning: ‘int’ got invalid input ‘None’ when rendering template ‘{{ states[no_motion_wait].state | int }}’ but no default was specified. Currently ‘int’ will return ‘0’, however this template will fail to render in Home Assistant core 2022.1

I think changing "{{ states[no_motion_wait].state | int }}" to "{{ states[no_motion_wait].state | int(0) }}" should solve the issue (default will be 0 if state is None).

1 Like

Thanks for reporting this, I fixed this issue like @ZzetT has suggested.

Hi @freakshock Nice automation and exactly for my use case.
I have one problem, maybe you have an idea. For Blocking entity, I use an automation for toggling a hue lamp with a hue wall switch module. So, motion detected → hue lamp switches on → hue wall switch toggles lamp off. When pressing the wall switch, lamp should shine further on, but with 100% brightness (I plan to add time slots with for example only 20% brightness at night) and your automation should break until the wall switch is pressed the second time.
I used ioBroker for some years and quite new to Home Assistant.
Thanks in advance for any input.

Hi!
I think what you want is possible. If I understand you correctly, I think you can create a new helper entity yourself (input_boolean or binary sensor for instance). You would set this helper entity to ‘on’ whenever you dont want my automation to trigger, and to ‘off’ whenever you do want it, by using a separate automation. This helper entity can then be set as the blocker entity for my automation.

Hi everyone.

I want to use a script to turn off my light.
I tried to update this code block in the blueprint, but it was unsuccessful.

The block I modified:

action:
  - service: homeassistant.turn_on
    entity_id: !input target_entity
  - condition: template
    value_template: "{{ no_motion_wait != none }}"
  - wait_for_trigger:
      platform: state
      entity_id: !input motion_sensor
      from: "on"
      to: "off"
  - delay:
      minutes: "{{ states[no_motion_wait].state | int(0) }}"
  - condition: template
    value_template: "{{ (turn_off_blocker_entity == none) or (states[turn_off_blocker_entity].state == 'off') }}"
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ (target_off_domain = script) }}"
        sequence:
          - service: !input target_off_entity
    default:
      - service: homeassistant.turn_off
        entity_id: !input target_entity

And more specifically the lines I didn’t modify each other:

          - condition: template
            value_template: "{{ (target_off_domain = script) }}"
        sequence:
          - service: !input target_off_entity

Any ideas on where I am wrong?
Thanks in advance for your help.

Hi @freakshock
Thanks for your quick response. So I created an input_boolean helper and set as blocker entity in your automation. Then I created a seperate automation like below, but nothing happens. Could you give me a hint, which part is wrong? Thank you again.

Stupid question maybe, but with this blueprint, is it also possible to add the color and brightness to the light i want to turn on?

1 Like

I would check your trigger.
See for instance these docs: Automation Trigger - Home Assistant

Yes that’s possible, by defining a scene for the color and brightness you want, and have the scene be the turn-on entity in the blueprint.

Sorry to bring this up, but is there any way to execute a script using the “turn off entity” property?
Thank you :slight_smile:

Thanks for the hint with the trigger check. Now it behaves as expected and I like your blueprint better and better :slight_smile:
Now I have a question about a scene as turn on entity:
I set a scene (just one light with color in blue and brightness 20%) as target turn on entity, but then tthe light won’t turn off after last motion and turn off wait time. When I switch target turn on entity back to light entity, light goes off as expected.

Mea culpa. You have to put in a turn-off entity, if a scene or script was used as target entity. It works now as expected.