πŸ’‘ Blueprint for motion lights with day/night mode, illuminance and dimmabel timer

I just expanded my original blueprint for motion lights to be a little bit more smart :nerd_face::bulb::walking_man::sunny:

Now you can have different timers when the lights should turn of depending on if it is day mode or night mode, set by two input helpers. 🫑

The user can also set a dimmable timer, that will dim the lights when they soon will turn off. This mimics the way Hue does it out of the box, but with more flexibility as you can set this yourself!

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

I use it in my hallway and bathrooms, to only turn on the hallway lights when it is dark enough. So the lights will only turn on when they are needed. The day and night mode is nice, because you generally want the lights to turn of pretty quickly during the night and not stay on for so long.

The dimming is also a nice addition as it signals that the light is soon to turn of, so if you want it to stay on, wave to the sensor! :wave:

Here is the gist with the code. Happy automating!

13 Likes

Hey mate, I tried all evening to get the Night time helper to work.
It does not matter what I try, I always get this error:

Error: ValueError: could not convert str to datetime: '2023-08-10 08:10:19'

I tried changing my time format of home assistant but it seems to only change how time is displayed.
Have you had that before or got any clue why this could happen?

Running HomeAssistant 2023.7.2 on docker on a synology nas.

small edit
I was wondering if it was possible to instead use sensor.sun_next_rising / sensor_sun_next_setting values for the night time start and stop datetime.

1 Like

there are an error in the yaml:

  • delay: ’ {% if today_at(states(local_night_end)) < now() or now() < today_at(states(local_night_start)) %}

not β€œnow() or now()” but β€œnow() and now()”

Came here to ask about the wait time (night) not applying between night start and night end. During the night, the day wait time is still used.

Looks like the above logic could be the cause. @Danielbook?

So ive tweaked this to my needs if its useful to anyone else. Ive added in a condition that will allow it to skip. I use it for a togglable night mode so the lights don’t come on in the bedroom when sleeping. Ive also change it to use sunrise and sunset as the night time/day time change.

blueprint:
  name: Motion-activated Light with illuminance, nightmode and dimmable
  description:
    Turn on a light when motion is detected and illuminance is below a
    set Lux level. The light will dim before it is turned off to signal that it has
    not detected motion in quite a while. There is also two timers, on for daytime
    and one for nighttime.
  domain: automation
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain:
            - binary_sensor
          device_class:
            - motion
          multiple: false
    lux_entity:
      name: Illuminance Sensor
      selector:
        entity:
          domain:
            - sensor
          device_class:
            - illuminance
          multiple: false
    lux_level:
      name: Illuminance level
      description:
        If lux is below this value and motion is detected, the light will
        turn on.
      default: 100
      selector:
        number:
          min: 0.0
          max: 1000.0
          step: 1.0
          mode: slider
    light_target:
      name: Light
      selector:
        target:
          entity:
            - domain:
                - light
    dim_time:
      name: Dim light
      description:
        The light will start dim this many seconds before it is turned
        off if no motion has been detected to signal that the light will soon turn
        off.
      default: 30
      selector:
        number:
          min: 0.0
          max: 120.0
          unit_of_measurement: seconds
          step: 1.0
          mode: slider
    no_motion_wait_day:
      name: Wait time (day)
      description:
        Time to leave the light on after last motion is detected during
        the day.
      default: 300
      selector:
        number:
          min: 0.0
          max: 600.0
          unit_of_measurement: seconds
          step: 1.0
          mode: slider
    no_motion_wait_night:
      name: Wait time (night)
      description:
        Time to leave the light on after last motion is detected during
        the night.
      default: 120
      selector:
        number:
          min: 0.0
          max: 600.0
          unit_of_measurement: seconds
          step: 1.0
          mode: slider
    skip_condition:
      name: Skip Condition
      description: Enter an entity that should be used to disable this automation.
      selector:
        entity: {}
      default: ""
  source_url: https://gist.github.com/Danielbook/ad8dacabb8dc01e7cf062cbd8c1a00ed
mode: restart
max_exceeded: silent
variables:
  local_motion_delay_day: !input no_motion_wait_day
  local_motion_delay_night: !input no_motion_wait_night
  local_motion_dim_time: !input dim_time
  local_skip_condition: !input skip_condition
  sun_entity: sun.sun
trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"
condition:
  condition: and
  conditions:
    - condition: numeric_state
      entity_id: !input lux_entity
      below: !input lux_level
    - condition: template
      value_template: >
        {{ local_skip_condition == '' or is_state(local_skip_condition, 'off') }}
action:
  - service: light.turn_on
    target: !input light_target
  - wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
  - delay: " {% if is_state('sun.sun', 'above_horizon') %}
      {{ local_motion_delay_day - local_motion_dim_time }} {% else %} {{ local_motion_delay_night
      - local_motion_dim_time }} {% endif %} "
  - service: light.turn_off
    target: !input light_target
    data:
      transition: !input dim_time

:pray:

Thank you!

Put this in place yesterday to turn on outside lights when triggered from a motion sensor.

Absolutely spot on.

:+1: