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

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

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.