Enhanced motion controller to activate scenes by time and illuminance - now in addition with idle ambient scene

Hi,
you have to put e.g. !input time_scene_night into a variable before and use the varibale within the template.

variables:
  no_motion_wait_night: !input no_motion_wait_night
  no_motion_wait_morning: !input no_motion_wait_morning
  no_motion_wait_day: !input no_motion_wait_day


{% if (states.sensor.time.state > time_scene_night) and (states.sensor.time.state < time_scene_morning) %} 
       {{no_motion_wait_night}}
      {% elif (states.sensor.time.state > time_scene_morning) and (states.sensor.time.state < time_scene_evening) %}
         {{no_motion_wait_morning}}
      {% else %}
        {{no_motion_wait_day}}
      {% endif %}

But it is only an assumption

The !input tag is used by the YAML processor to perform a substitution. It is designed to assign a value to a key.

The key in the following example is entity_id

  entity_id: !input whatever

You have not used !input in that manner. You have it standing alone within a template.

You must do what dkoehler suggested because it uses the !input tag to assign a value to a key. Create a variable, assign the selector value to it, then use the variable in the template.

Ok gotcha, makes sens :slightly_smiling_face:
I’ll expiriment a little more with it

Did you get it working with groups of motion sensors yet? Would it only require broadening the filter on the selector for motion_entity?

Hi, unfortenately I switched back to node red. Much more comfortable debugging and faster results.

Insanely awesome. Great work.

Thanks for your hard work on this.

Has anybody managed to remove the need to have a light sensor?

You can try YAMA - Yet Another Motion Automation (Scenes, Ambient Light and some Conditions )

It is a fork of this blueprint

2 Likes

Thanks, I’ll take a look

First of all: thanks a lot for this blueprint!! Makes motion controlled lights automation a breeze.

I only have one question: is it possible to create a transition to a scene, to make the lights come on gradually? My yaml skills are not good enough to understand how to do that within this blueprint…

2 Likes

Hi,

When it comes to light flux meter, I simply removed all line which corresponds to this entity, but… seems it doesn’t work at all…

blueprint:
  name: Motion-activated light scene with surrounding light level check and optional
    ambient scene
  description: Turn on a light scene when motion is detected. Three different scenes
    can be defined depending on time of day. Furthermore a source for checking sourrounding
    light can be defined to enable light only if it is dark enough.
  domain: automation
  source_url: https://gist.github.com/incapable/f43f74a0c5f9554b86f31ad0c0584180
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
#    lightsensor_entity:
#      name: Illuminance Sensor
#      selector:
#        entity:
#          domain: sensor
#          device_class: illuminance
#    illuminace_level:
#      name: Max Illuminance
#      description: Maximal immuminance level in lux. If illuminance is higher, light
#        will not be enabled
#      default: 600
#      selector:
#        number:
#          min: 0.0
#          max: 5000.0
#          unit_of_measurement: lux
#          mode: slider
#          step: 1.0
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    scene_ambient:
      name: Ambient Scene (Optional)
      description: Scene for ambient state. Will be activated when no motion is detected
        and light level is under threshold. Default value = scene.none
      default: scene.none
      selector:
        entity:
          domain: scene
    time_scene_ambient_start:
      name: Ambient time frame start
      description: Time from which on ambient scene will be activated
      default: 00:00:00
      selector:
        time: {}
    time_scene_ambient_end:
      name: Ambient time frame end
      description: Time from which on ambient scene will be not activated
      default: 00:00:00
      selector:
        time: {}
    scene_morning:
      name: Scene for the morning
      default: scene.none
      selector:
        entity:
          domain: scene
    time_scene_morning:
      name: Time for the morning scene
      description: A time input which defines the time from which on the scene will
        be activated if motion is detected. Default value = scene.none
      default: 00:00:00
      selector:
        time: {}
    no_motion_wait_morning:
      name: Wait time morning
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0.0
          max: 3600.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
    scene_day:
      name: Scene for the bright day
      default: scene.none
      selector:
        entity:
          domain: scene
    time_scene_day:
      name: Time for the day scene
      description: A time input which defines the time from which on the scene will
        be activated if motion is detected. Default value = scene.none
      default: 00:00:00
      selector:
        time: {}
    no_motion_wait_day:
      name: Wait time day
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0.0
          max: 3600.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
    scene_evening:
      name: Scene for the evening
      default: scene.none
      selector:
        entity:
          domain: scene
    time_scene_evening:
      name: Time for the evening scene
      description: A time input which defines the time from which on the scene will
        be activated if motion is detected. Default value = scene.none
      default: 00:00:00
      selector:
        time: {}
    no_motion_wait_evening:
      name: Wait time evening
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0.0
          max: 3600.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
    scene_night:
      name: Scene for the dark night
      default: scene.none
      selector:
        entity:
          domain: scene
    time_scene_night:
      name: Time for the night scene
      description: A time input which defines the time from which on the scene will
        be activated if motion is detectedd. Default value = scene.none
      default: 00:00:00
      selector:
        time: {}
    no_motion_wait_night:
      name: Wait time night
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0.0
          max: 3600.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
mode: restart
max_exceeded: silent
variables:
  scene_ambient: !input 'scene_ambient'
trigger:
  platform: state
  entity_id: !input 'motion_entity'
  from: 'off'
  to: 'on'
action:
- choose:
  - conditions:
    - condition: time
      after: !input 'time_scene_morning'
      before: !input 'time_scene_day'
#    - condition: numeric_state
#      entity_id: !input 'lightsensor_entity'
#      below: !input 'illuminace_level'
    sequence:
    - scene: !input 'scene_morning'
  - conditions:
    - condition: time
      after: !input 'time_scene_day'
      before: !input 'time_scene_evening'
#    - condition: numeric_state
#      entity_id: !input 'lightsensor_entity'
#      below: !input 'illuminace_level'
    sequence:
    - scene: !input 'scene_day'
  - conditions:
    - condition: time
      after: !input 'time_scene_evening'
      before: !input 'time_scene_night'
#    - condition: numeric_state
#      entity_id: !input 'lightsensor_entity'
#      below: !input 'illuminace_level'
    sequence:
    - scene: !input 'scene_evening'
  - conditions:
    - condition: time
      after: !input 'time_scene_night'
      before: !input 'time_scene_morning'
#    - condition: numeric_state
#      entity_id: !input 'lightsensor_entity'
#      below: !input 'illuminace_level'
    sequence:
    - scene: !input 'scene_night'
- service: input_boolean.turn_off
  data: {}
  entity_id: input_boolean.user_changed_lights
- delay: 00:00:05
- service: input_boolean.turn_on
  data: {}
  entity_id: input_boolean.user_changed_lights
- wait_for_trigger:
    platform: state
    entity_id: !input 'motion_entity'
    from: 'on'
    to: 'off'
- delay: "{% if (states.sensor.time.state > time_scene_night) and (states.sensor.time.state\
    \ < time_scene_morning) %} \n  !input no_motion_wait_night\n{% elif (states.sensor.time.state\
    \ > time_scene_morning) and (states.sensor.time.state < time_scene_evening) %}\n\
    \  !input no_motion_wait_morning\n{% else %}\n  !input no_motion_wait_day\n{%\
    \ endif %}"
- choose:
  - conditions:
    - '{{ scene_ambient != ''scene.none''}}'
    - condition: time
      after: !input 'time_scene_ambient_start'
      before: !input 'time_scene_ambient_end'
#    - condition: numeric_state
#      entity_id: !input 'lightsensor_entity'
#      below: !input 'illuminace_level'
    sequence:
    - scene: !input 'scene_ambient'
  default:
  - service: light.turn_off
    target: !input 'light_target'

I have one question:
If I want to select scene based on motion and time, why do I need to select LIGHT SOURCE?
Scene should activate those lights which I want, so? Or it’s just that this will TURN OFF all those lights?
At least, this is my understanding because there is no other connection between INPUT and LIGHT TURN OFF.

Very nice automation! Is it possible to have this automation running only active when homealarm is disarmed? Second, I would like to disable the timer, so when I am at home the scene (at designated time) comes on when lux is below X, is this possible?

Greetings

Love this automation, in theory it does everything I need - but I am struggling to get it to run consistently and suspect its my config. I have a Hue outside motion senor which I use to trigger it. I want an ambient scene (e.g. outside warm lighting scene) on from when it gets dark, and then when motion is detected I want a ‘security’ scene (e.g. outside security lighting scene). After the security scene has been running for 120 seconds, I want the ambient / warm scene to return. Try as I might, I can’t get the ambient scene to come back after the security scene - I just can’t work it out. Am I even using the right automation?

Hi, all what this blueprint has I want it: time zones, lux and motion. But I don’t want scenes but only set the brightness of the light.
Im new to home assistant and yaml and I can’t get it working what is wrong with this code?

blueprint:
  name: Motion-activated light scene with surrounding light level check and optional ambient scene
  description: Turn on a light scene when motion is detected. Three different scenes can be defined depending on time of day. Furthermore a source for checking sourrounding light can be defined to enable light only if it is dark enough.
  domain: automation
  source_url: https://gist.github.com/dirkk1980/3e5c23acb05fb639bafdc5036b91aae6
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    lightsensor_entity:
      name: Illuminance Sensor
      selector:
        entity:
          domain: sensor
          device_class: illuminance
    illuminace_level:
      name: Max Illuminance
      description: Maximal immuminance level in lux. If illuminance is higher, light will not be enabled
      default: 600
      selector:
        number:
          min: 0
          max: 5000
          unit_of_measurement: lux
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    scene_ambient:
      name: Ambient Scene (Optional)
      description: Scene for ambient state. Will be activated when no motion is detected and light level is under threshold. Default value = scene.none
      default: 2
      selector:
       number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    time_scene_ambient_start:
      name: Ambient time frame start
      description: Time from which on ambient scene will be activated
      default: "00:00:00"
      selector:
        time:
    time_scene_ambient_end:
      name: Ambient time frame end
      description: Time from which on ambient scene will be not activated
      default: "00:00:00"
      selector:
        time:
    scene_morning:
      name: Scene for the morning
      default: 100
      selector:
       number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    time_scene_morning:
      name: Time for the morning scene
      description: A time input which defines the time from which on the scene will be activated if motion is detected. Default value = scene.none
      default: "00:00:00"
      selector:
        time:
    scene_day:
      name: Scene for the bright day
      default: 80
      selector:
       number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    time_scene_day:
      name: Time for the day scene
      description: A time input which defines the time from which on the scene will be activated if motion is detected. Default value = scene.none
      default: "00:00:00"
      selector:
        time:
    scene_evening:
      name: Scene for the evening
      default: 50
      selector:
       number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    time_scene_evening:
      name: Time for the evening scene
      description: A time input which defines the time from which on the scene will be activated if motion is detected. Default value = scene.none
      default: "00:00:00"
      selector:
        time:
    scene_night:
      name: Scene for the dark night
      default: 1
      selector:
       number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    time_scene_night:
      name: Time for the night scene
      description: A time input which defines the time from which on the scene will be activated if motion is detectedd. Default value = scene.none
      default: "00:00:00"
      selector:
        time:
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

mode: restart
max_exceeded: silent

variables:
  scene_ambient: !input scene_ambient
trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"
## condition for illumination has to be checked for every scece and not global. reason: action should be also triggered if no lights should be enabled to switch off ambient scene if it is to bright
action:
  - choose:
      - conditions:
          - condition: time
            after: !input time_scene_morning
            before: !input time_scene_day
          - condition: numeric_state
            entity_id: !input lightsensor_entity
            below: !input illuminace_level
        sequence:
          - type: turn_on
            device_id: !input 'light_target'
            entity_id: !input 'light_target'
            domain: light
            brightness_pct: !input scene_morning
      - conditions:
          - condition: time
            after: !input time_scene_day
            before: !input time_scene_evening
          - condition: numeric_state
            entity_id: !input lightsensor_entity
            below: !input illuminace_level
        sequence:
          - type: turn_on
            device_id: !input 'light_target'
            entity_id: !input 'light_target'
            domain: light
            brightness_pct: !input scene_day
      - conditions:
          - condition: time
            after: !input time_scene_evening
            before: !input time_scene_night
          - condition: numeric_state
            entity_id: !input lightsensor_entity
            below: !input illuminace_level
        sequence:
          - type: turn_on
            device_id: !input 'light_target'
            entity_id: !input 'light_target'
            domain: light
            brightness_pct: !input scene_evening
      - conditions:
          - condition: time
            after: !input time_scene_night
            before: !input time_scene_morning
          - condition: numeric_state
            entity_id: !input lightsensor_entity
            below: !input illuminace_level
        sequence:
          - type: turn_on
            device_id: !input 'light_target'
            entity_id: !input 'light_target'
            domain: light
            brightness_pct: !input scene_night
  - wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - delay: !input no_motion_wait
  - choose:
      - conditions:
          - "{{ scene_ambient != 'scene.none'}}"
          - condition: time
            after: !input time_scene_ambient_start
            before: !input time_scene_ambient_end
          - condition: numeric_state
            entity_id: !input lightsensor_entity
            below: !input illuminace_level
        sequence:
          - type: turn_on
            device_id: !input 'light_target'
            entity_id: !input 'light_target'
            domain: light
            brightness_pct: !input scene_ambient
    default:
      - service: light.turn_off
        target: !input light_target

would it be possible to add separate wait times for each of the 4 scenes?

Really good blue print. But I was wondering, is it possible to not have “Wait time”. I dont want the lights to be turned off at all after being triggered.

Edit.

I didnt get this one to work afterall. Automation is triggered by motion. But the light wont turn on. Do I need scenes in order for this automation to work?

alias: Lys - skru på lys i andre etasje ved bevegelse (Med LUX)
description: ''
use_blueprint:
  path: dirkk1980/motion_controlled_scenes_enhanced.yaml
  input:
    illuminace_level: 700
    motion_entity: binary_sensor.hue_motion_sensor_1_motion
    lightsensor_entity: sensor.hue_motion_sensor_1_illuminance
    light_target:
      entity_id:
        - light.hue_smart_plug_1
        - light.trapper
        - light.kontor
    no_motion_wait: 3600


This one works;

alias: Lys - skru på lys i ander etasje ved beveglese (Uten LUX)
description: ''
use_blueprint:
  path: homeassistant/motion_light.yaml
  input:
    motion_entity: binary_sensor.hue_motion_sensor_1_motion
    light_target:
      entity_id:
        - light.trapper
        - light.kontor
        - light.hue_smart_plug_1
    no_motion_wait: 3600

Hello, nice blueprint! but can we add option to trigger scene on motion only when its dark in room?

1 Like

have been using this for ages but really need the lights to dim down to a lower brightness for 5 -10 seconds to warn that they will be turning off, I changed the blueprint at the end from

default:

  • service: light.turn_off
    target: !input ‘light_target’

to
default:

  • service: light.turn_on
    target: !input ‘light_target’
    data:
    brightness: 80
  • delay: 5
  • service: light.turn_off
    target: !input ‘light_target’

which works fine but now the illuminance part of the blueprint is not working correctly.
can any please help
thanks