šŸ’” Sensor Light - Motion Sensor - Door Sensor - Sun Elevation - LUX Value - Scenes - Time - Light Control - Device Tracker - Night Lights

@markist

Assume the way you switch your automations is by time.

The bypass overrides everything. It looks like youā€™re using Option 3, which maintains the current state of the light in both automations. In this case, you only need the auto-OFF functionality in one automation.

When the bypass is turned OFF, it checks your site conditions and may turn the light ON if the trigger is active. If the automation is disabled (e.g., due to time constraints), it wonā€™t run, ensuring that only the active automation responds to the site conditions when the bypass is turned OFF.

Blacky :smiley:

Thank you for coming back :slight_smile: Much appreciated.

Thing is that the script is actually being triggered on motion, but my issue is that the script needs a variable to be passed in (the light entity the script has responsibility to turn on), but I canā€™t figure out how I should do that - or if itā€™s even possible :slight_smile:

@Blacky : Due to maintenance works on an entrance door, a Nuki lock that is usually attached has been unattached for some days, and the device in Home Assistant has been disabled. Since the Nuki lock is supposed to be reattached in a couple of days, I ignored Spookā€™s warnings. As a consequence, the Sensor Light automations which include the binary sensor of the disabled device do not work anymore.

Is there a possibility to bypass this problem?

Is there a way to turn on a light when motion is detected, but ONLY if a door is open?

Hello @Blacky I have this yaml created from your blueprint ā€œSensor lightā€:
alias: outdoor lights
description: ā€œā€
use_blueprint:
path: Blackshome/sensor-light.yaml
input:
motion_trigger:

  • binary_sensor.hue_outdoor_motion_sensor_1_movement
    light_switch:
    entity_id: switch.sonoff_100090db83
    time_delay: 1
    include_ambient: ambient_enabled
    ambient_light_sensor: sensor.hue_outdoor_motion_sensor_1_light
    ambient_light_options: ambient_light_option_enabled
    ambient_light_value: 10

Problem is that sometimes when the light is turned ON it will never go OFF. I think it is because of the motion sensor is not far from the light which is turned on and specified light value goes over 10 lux. Could this be the problem? If yes how to solve it? Thank you.

@croon8483

Iā€™m not sure I fully understand your request, but if youā€™re looking for a script to turn on a light with three different settings depending on the time of day, Iā€™ve created a quick example for you. Hereā€™s how you can use it:

  1. Create a new script and switch to YAML editing mode.
  2. Copy and paste the code below into the script.
  3. Switch back to the visual editor, and youā€™ll see three options to configure.

Youā€™ll need to customize the light entities and times to suit your needs. See the code below:

alias: New Script
sequence:
  - choose:
      - conditions:
          - condition: time
            after: "06:00:00"
            before: "12:00:00"
        sequence:
          - action: light.turn_on
            metadata: {}
            data: {}
      - conditions:
          - condition: time
            after: "12:00:00"
            before: "20:00:00"
        sequence:
          - action: light.turn_on
            metadata: {}
            data: {}
      - conditions:
          - condition: time
            after: "20:00:00"
            before: "06:00:00"
        sequence:
          - action: light.turn_on
            metadata: {}
            data: {}

Blacky :smiley:

@ajd_ht

Not sure what your askingā€¦ is it that your lock in disabled for a few days and was used as the trigger? if so you will need to find another trigger that suits your needs.

Blacky :smiley:

@dreadino

Yes but you will need to create a template binary sensor that looks for your conditions and if met then the template sensor will be ON.

To create a Template binary sensor, follow these steps:

  1. Navigate to Settings > Device & Services > Helpers tab at the top.
  2. Click the Create helper button.
  3. Select Template and then choose Template a binary sensor.

Next, provide a Name and Device class of your choice. If applicable, you can link this template to an existing device so it appears under that deviceā€™s details.

In the State template field, add the code below, replacing binary_sensor.motion_sensor and ā€˜binary_sensor.door_sensorā€™ with your entity ID.

Once created add this template sensor as the trigger.

{{ is_state('binary_sensor.motion_sensor', 'on') and is_state('binary_sensor.door_sensor', 'on') }}

Blacky :smiley:

1 Like

Hi all,

So. Iā€™m slowly moving everything to HA (from homey) and blueprints are a life safer. So is this one.
I have 2 questions though.

1: sleep mode. I want to test the BP in my bedroom. Is there a way to tell that when I go to sleep fade the lights to far red and the turn off. Or at least disable the automation till I wake up? I looked at the nightlight setting but I donā€™t think that is the way.
2: the dynamic light option, will it work when I only selected a scene? As in. Entities arenā€™t linked then in the automation right?

Cheers
Vic

@Jiran

Quick tip: When sharing code in this forum, itā€™s best to use the </> button in the editor and paste your code there. This preserves the formatting, making it easier for others to read and use.

Here are a few things to consider:

  1. Manual Light Control:
    If you turn your light ON manually and the motion sensor is not triggered, the automation wonā€™t turn the light OFF.

  2. Lux Levels and Motion Sensor Behavior:

  • If the motion sensor is triggered and your light turns ON when the levels are below 10, but the levels later rise above 10, the light will stay ON.
  • This happens because you have selected YES - My Ambient Light Sensor is affected by the Lights, so the automation ignores the lux value once the light is ON.

Blacky :smiley:

@victoroos

You can use the bypass option 2. There are many ways to do this as the trigger for sleep mode and it will depend on what you would like to do.

  • Create a toggle helper.
  • Use your phone on do not disturb (Sleep mode)

What ever you choose when your bypass is ON the automation will be disabled and the lights will turn OFF when you turn the bypass ON.

Blacky :smiley:

1 Like

Aaah Okey I didnā€™t completely get that. Thanks!
Andā€¦ If I want a transition to off? Or is that the *transition to off?
And. Amazing fast reply. Thank you. I saw in the fawlq that scenes donā€™t work with dynamic (which makes sense) but can I add scenes and entities to the automation and the dynamic light being smart enough to only do the enitites?

@victoroos

Transition OFF

Re Dynamic lighting. This only works with light entity not a script or scene. If you have a scene and a light entity it will run the scene and also control the light entity in dynamic lighting. So it will do both.

Blacky :smiley:

1 Like

Perfect. Time to just test run this and letā€™s soo what pops up.
Thanks again!!! ^^

@Blacky : Many thanks for your time.

Due to maintenance works on an entrance door, a Nuki lock that is usually attached has been unattached for some days, and the device in Home Assistant has been disabled. Since the Nuki lock is supposed to be reattached in a couple of days, I ignored Spook warnings.

I use Sensor light e.g. for switching on the light in the entrance.

Here an anonymized example

alias: Entry - Light - Automation
description: ""
use_blueprint:
  path: Blackshome/sensor-light.yaml
  input:
    motion_trigger:
      - binary_sensor.entry_frontdoor_contact
      - binary_sensor.entry_secondarydoor_contact
      - binary_sensor.garage_door_contact_closed
      - binary_sensor.entry_motion_sensor_1
      - binary_sensor.stairway_up_motion
      - binary_sensor.driveway_motion_sensor
      - >-
        binary_sensor.entry_occupancy_sensor
      - binary_sensor.entry_frontdoor_nukilock_locked
    time_delay: 4
    end_scenes: []
    light_switch:
      entity_id: light.entry_lights_main
    include_light_control:
      - use_brightness
    motion_bypass_lights_stop: []

The binary sensor

      - binary_sensor.entry_frontdoor_nukilock_locked

belongs to the unattached nuki lock / the disabled nuki integration. If I leave this binary sensor in the automation, the whole automation seems not work anymore.

Ok, maybe itā€™s easier if I provide my script :slight_smile: Thanks so far!

light_time_of_day:
  sequence:
    - alias: Turn on light with brightness determined by time of day
      choose:
        - conditions:
            - condition: time
              after: 07:00:00
              before: "20:00:00"
          sequence:
            - action: light.turn_on
              metadata: {}
              data:
                transition: 0.5
                kelvin: 2202
                brightness_pct: "{{ brightness_high }}"
              target:
                entity_id: "{{ light }}"
        - conditions:
            - condition: time
              after: "20:00:00"
              before: "23:00:00"
          sequence:
            - action: light.turn_on
              metadata: {}
              data:
                transition: 0.25
                kelvin: 2202
                brightness_pct: "{{ brightness_medium }}"
              target:
                entity_id: "{{ light }}"
        - conditions:
            - condition: time
              after: "23:00:00"
              before: 07:00:00
          sequence:
            - action: light.turn_on
              metadata: {}
              data:
                transition: 0.25
                kelvin: 2202
                brightness_pct: "{{ brightness_low }}"
              target:
                entity_id: "{{ light }}"
  fields:
    light:
      selector:
        entity:
          multiple: false
      required: true
      name: Light
      description: The light group you want to control with the script. Only one entity.
  variables:
    brightness_low: 10
    brightness_medium: 50
    brightness_high: 90

Soā€¦ I have a field called light. This is the light entity to be called on light.turn_on. If this is not given, the script have nothing to activate.

So in the blueprint automation, when I select this script to run (via the UI) Iā€™m not given any way to provide the light entity I want to control, causing my script to fail (as the field is required).

Perhaps it should be done via YAML, but I havenā€™t got anything to work there either - Iā€™ve tried some variants, but my last try was:

- id: '1731869443083'
  alias: entrance/motion
  description: Turn on lights on motion
  use_blueprint:
    path: Blackshome/sensor-light.yaml
    input:
      light_switch:
        entity_id: script.light_time_of_day
        data:
          light: light.entrance
      motion_trigger:
      - binary_sensor.entrance_motion_sensor_occupancy

ā€¦ but canā€™t figure out :slight_smile:

Hello dear expert. Could you help me and give me a hint what I am doing wrong?

I am trying to turn a light on/off through motion. I tried everything, but the automation script never gets triggered. I tried my Entity from my motion sensor of Philips Hueā€¦ I tried the entity from an Aqara FP2 Presence Sensor.

If I use the standard homeassistant automation for activating a light on motion it works fine. But this script, with the same entities, never gets triggered. What am I doing wrong?

(In the json trace file there is written

"trace": { "last_step": null, "run_id": "8c7576d62e128ffa411a4baf7d9e1ef2", "state": "stopped", "script_execution": null, "timestamp": { "start": "2024-11-19T19:34:53.756218+00:00", "finish": "2024-11-19T19:34:53.759120+00:00" }, "domain": "automation", "item_id": "1732044013135", "error": "UndefinedError: 'dict object' has no attribute 'entity_id'", "trigger": null, "trace": {},

and moreā€¦

Please help me. Thanks

Hi, nice work, just what I have been looking for! I love the feature with setting up an Ambient Light Sensor for activation in low-light conditions, but ā€¦ Not all rooms in my house need light at the same light level from a single sensor. Would it be possible to implement a feature where light in different rooms are triggered from same sensor but with different light levels?

@ajd_ht

It should still work if you disable the one entity. You could just remove this entity from the automation and then add it back in when it is up and running again.

With 8 entities I would make a group helper and add all the entities in there. Once you created the group I would then just add the group helper as the trigger. The how to do this is in the FAQ, click here.

Although your automation YAML should work I have notice one thing that is not normal. Below is you code cleaned up.

alias: Entry - Light - Automation
description: ""
use_blueprint:
  path: Blackshome/sensor-light.yaml
  input:
    motion_trigger:
      - binary_sensor.entry_frontdoor_contact
      - binary_sensor.entry_secondarydoor_contact
      - binary_sensor.garage_door_contact_closed
      - binary_sensor.entry_motion_sensor_1
      - binary_sensor.stairway_up_motion
      - binary_sensor.driveway_motion_sensor
      - binary_sensor.entry_occupancy_sensor
      - binary_sensor.entry_frontdoor_nukilock_locked
    time_delay: 4
    light_switch:
      entity_id: light.entry_lights_main
    include_light_control:
      - use_brightness

Blacky :smiley:

@croon8483

You cant edit the YAML code of the blueprint, it will not work as these are just inputs.

Regarding your script, why donā€™t you just put in the brightness in rather than use a variable and then just select your light group as shown below.

alias: Turn on light with brightness determined by time of day
sequence:
  - choose:
      - conditions:
          - condition: time
            after: "07:00:00"
            before: "20:00:00"
        sequence:
          - action: light.turn_on
            metadata: {}
            data:
              transition: 0.5
              kelvin: 2202
              brightness_pct: 90
            target:
              entity_id: light.ensuite_led_s
      - conditions:
          - condition: time
            after: "20:00:00"
            before: "23:00:00"
        sequence:
          - action: light.turn_on
            metadata: {}
            data:
              transition: 0.25
              kelvin: 2202
              brightness_pct: 50
            target:
              entity_id:
                - light.ensuite_led_s
      - conditions:
          - condition: time
            after: "23:00:00"
            before: "07:00:00"
        sequence:
          - action: light.turn_on
            metadata: {}
            data:
              transition: 0.25
              kelvin: 2202
              brightness_pct: 10
            target:
              entity_id:
                - light.ensuite_led_s

Blacky :smiley: