Motion-activated Light-brightness

Turn the light on to brightness when motion is detected, depending on the selected time period, different brightness and turn-on time.

This bluprint is designed to turn on the light by the motion sensor, and takes into account that at night you need a dimmer light than during the day, so I created the opportunity to choose the period in which you want to have a different brightness of light other than daytime, as well as the time after which the light should turn off also divided into two periods

This is my first bluprint, so do not judge strictly, and perhaps there is a better option to create this

Get started

Click the badge to import this Blueprint:

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Or import this Blueprint by using the forum topic URL:

blueprint:
  name: Motion-activated Light-brightness
  description: Turn the light on to brightness when motion is detected, depending on the selected time period, different brightness and turn-on time.
  domain: automation
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    on_night_time:
      name: (Required) On Time Night
      description: The time when the night mode starts.
      selector:
        time: {}
    off_night_time:
      name: (Required) Off Time Night
      description: The time when the night mode ends.
      selector:
        time: {}
    day_brightness:
      name: Day brightness
      description: Brightness, in daytime mode
      default: 1
      selector:
        number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    night_brightness:
      name: Night brightness
      description: Brightness, in night mode mode
      default: 1
      selector:
        number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    no_motion_wait_day:
      name: Wait time day
      description: Time to leave the light on after detecting the last movement for daytime mode.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds
    no_motion_wait_night:
      name: Wait time night
      description: Time to leave the light on after detecting the last movement in night mode
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"

action:
  - choose:
      - conditions:
          - condition: time
            after: !input on_night_time
            before: !input off_night_time
        sequence:
          - alias: "Turn on the light"
            service: light.turn_on
            data:
              brightness_pct: !input night_brightness
            target: !input light_target
          - alias: "Wait until there is no motion from device"
            wait_for_trigger:
              platform: state
              entity_id: !input motion_entity
              from: "on"
              to: "off"
          - alias: "Wait the number of seconds that has been set"
            delay: !input no_motion_wait_night
          - alias: "Turn off the light"
            service: light.turn_off
            target: !input light_target
    default:
      - alias: "Turn on the light"
        service: light.turn_on
        data:
          brightness_pct: !input day_brightness
        target: !input light_target
      - alias: "Wait until there is no motion from device"
        wait_for_trigger:
          platform: state
          entity_id: !input motion_entity
          from: "on"
          to: "off"
      - alias: "Wait the number of seconds that has been set"
        delay: !input no_motion_wait_day
      - alias: "Turn off the light"
        service: light.turn_off
        target: !input light_target

At the request of people who liked my blueprint, I created a version with the ability to also choose the color temperature, unfortunately I do not have enough knowledge to do all this in one blueprint.

Get started

Click the badge to import this Blueprint:
Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Motion-activated Light-brightness and temp
  description: Turn the light on to brightness and temperature when motion is detected, depending on the selected time period, different brightness and turn-on time.
  domain: automation
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    on_night_time:
      name: (Required) On Time Night
      description: The time when the night mode starts.
      selector:
        time: {}
    off_night_time:
      name: (Required) Off Time Night
      description: The time when the night mode ends.
      selector:
        time: {}
    day_brightness:
      name: (Required) Day brightness
      description: Brightness, in daytime mode
      default: 100
      selector:
        number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    night_brightness:
      name: (Required) Night brightness
      description: Brightness, in night mode
      default: 20
      selector:
        number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    day_temp:
      name: (Required) Day temp
      description: Temp, in daytime mode
      default: 1
      selector: 
        color_temp:
    night_temp:
      name: (Required) Night temp
      description: Temp, in night mode
      default: 1
      selector: 
        color_temp:
    no_motion_wait_day:
      name: Wait time day
      description: Time to leave the light on after detecting the last movement for daytime mode.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds
    no_motion_wait_night:
      name: Wait time night
      description: Time to leave the light on after detecting the last movement in night mode
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"

action:
  - choose:
      - conditions:
          - condition: time
            after: !input on_night_time
            before: !input off_night_time
        sequence:
          - alias: "Turn on the light"
            service: light.turn_on
            data:
              brightness_pct: !input night_brightness
              color_temp: !input night_temp
            target: !input light_target
          - alias: "Wait until there is no motion from device"
            wait_for_trigger:
              platform: state
              entity_id: !input motion_entity
              from: "on"
              to: "off"
          - alias: "Wait the number of seconds that has been set"
            delay: !input no_motion_wait_night
          - alias: "Turn off the light"
            service: light.turn_off
            target: !input light_target
    default:
      - alias: "Turn on the light"
        service: light.turn_on
        data:
          brightness_pct: !input day_brightness
          color_temp: !input day_temp
        target: !input light_target
      - alias: "Wait until there is no motion from device"
        wait_for_trigger:
          platform: state
          entity_id: !input motion_entity
          from: "on"
          to: "off"
      - alias: "Wait the number of seconds that has been set"
        delay: !input no_motion_wait_day
      - alias: "Turn off the light"
        service: light.turn_off
        target: !input light_target
8 Likes

Hi, thanks for creating this blueprint. I am using it and it is working very well.

This is great and works well!! Could you add the option please to select what colour temperature on Night and on Day. As during the day, I want a daylight and at night I’d like a warm white. Would this be possible?

4 Likes

Just saw this blueprint today, very nice. I’m able to use it at a few locations in our house. I have a few locations which the light only needs to be turned on if lux is above a certain value. Could this be incorporated too? If not; no worries, tnx anyhow!

1 Like

I can do this, but most likely a separate blueprint, I will consider adding this function to this blueprint, if it does not work, then a separate one

1 Like

Thanks mate, that would be great. Please let me know the outcome either way :slight_smile:

I have already supplemented the theme with a color temperature selection option

Thank for you blueprint! Can you add separate blueprint with brightness and rgb color, instead color temperature?

Thanks for the blueprints, they work really well!
I have updated your blueprint to use lux data, like this when we specify a threshold the light will only turn on if lux level is bellow the threshold:

Click the badge to import this Blueprint:
Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Motion-activated Light (Brightness, Temperature, Lux)
  description: "Turn the light on to a given brightness and temperature when motion is detected, depending on the selected time period,\
    \ different brightness and temperature can be set.\n\
    \ Optionally you can set a lux treshold which will not turn on the light if lux sensor reports more light than the threshold."
  domain: automation
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    on_night_time:
      name: (Required) On Time Night
      description: The time when the night mode starts.
      selector:
        time: {}
    off_night_time:
      name: (Required) Off Time Night
      description: The time when the night mode ends.
      selector:
        time: {}
    day_brightness:
      name: (Required) Day brightness
      description: Brightness, in daytime mode
      default: 100
      selector:
        number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    night_brightness:
      name: (Required) Night brightness
      description: Brightness, in night mode
      default: 20
      selector:
        number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    day_temp:
      name: (Required) Day temp
      description: Temp, in daytime mode
      default: 1
      selector: 
        color_temp:
    night_temp:
      name: (Required) Night temp
      description: Temp, in night mode
      default: 1
      selector: 
        color_temp:
    illuminance_sensor:
      name: (Optional) Illuminance sensor
      description: The illuminance sensor to get lux data.
      default:
      selector:
        entity:
          domain: sensor
          device_class: illuminance
    illuminance_cutoff:
      name: (Optional) Illuminance threshold
      description: The threshold to compare to the current illumination (lux above this value will NOT turn on the light).
      default:
      selector:
        number:
          min: 0
          max: 100
          unit_of_measurement: lx
    no_motion_wait_day:
      name: Wait time day
      description: Time to leave the light on after detecting the last movement for daytime mode.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds
    no_motion_wait_night:
      name: Wait time night
      description: Time to leave the light on after detecting the last movement in night mode
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"

action:
  - choose:
      # IF light above threshold (cass dummy service to do nothing)
      - conditions: 
          - condition: numeric_state
            entity_id: !input illuminance_sensor
            above: !input illuminance_cutoff
        sequence:
          - alias: "Wait until there is no motion from device"
            wait_for_trigger:
              platform: state
              entity_id: !input motion_entity
              from: "on"
              to: "off"
          - alias: "Wait the number of seconds that has been set"
            delay: !input no_motion_wait_night
          - alias: "Turn off the light"
            service: light.turn_off
            target: !input light_target
      # ELIF light bellow threshold (turn on night light)
      - conditions:
          - condition: time
            after: !input on_night_time
            before: !input off_night_time
        sequence:
          - alias: "Turn on the light"
            service: light.turn_on
            data:
              brightness_pct: !input night_brightness
              color_temp: !input night_temp
            target: !input light_target
          - alias: "Wait until there is no motion from device"
            wait_for_trigger:
              platform: state
              entity_id: !input motion_entity
              from: "on"
              to: "off"
          - alias: "Wait the number of seconds that has been set"
            delay: !input no_motion_wait_night
          - alias: "Turn off the light"
            service: light.turn_off
            target: !input light_target
    # ELSE (Turn on day light)
    default:
      - alias: "Turn on the light"
        service: light.turn_on
        data:
          brightness_pct: !input day_brightness
          color_temp: !input day_temp
        target: !input light_target
      - alias: "Wait until there is no motion from device"
        wait_for_trigger:
          platform: state
          entity_id: !input motion_entity
          from: "on"
          to: "off"
      - alias: "Wait the number of seconds that has been set"
        delay: !input no_motion_wait_day
      - alias: "Turn off the light"
        service: light.turn_off
        target: !input light_target
3 Likes

Hmm…
what about dusk/dawn/night/day & sun set/rise

Time is nice, but it really depends on the season….

Elevation would be working as well :thinking:

Thank so much for this! It works perfectly with my Hue lights - when the stock options for Hue and HAOS didn’t deliver, this did. Well done!

Thanks for your blueprint!
I have one issue with it, my motion sensor has a cooldown period of 180 seconds. If i use the “Wait time day/night” in the blueprint, it adds this delay to the 180 seconds instead of adding it to the trigger time. How do I change this?

Good afternoon, in order not to take into account the cooldown period of the motion sensor, you need to remove these lines from the code

- alias: "Wait until there is no motion from device"
  wait_for_trigger:
    platform: state
    entity_id: !input motion_entity
    from: "on"
    to: "off"

but in this case, you will have problems that if you pass under the sensor during the cooldown period, the light will most likely not turn on

1 Like

hi there , hassio newbie here :blush:
this automation works beautifully with my tplink bulbs (no rgb, only leds), kudos…
but may I ask if it would be possible to reduce to a defined percentage and not to switch off entirely once the time runs out, would be nice to have very low lights always enabled.

Thanks in advance :slight_smile: