💡 Sensor Light - Motion Sensor - Door Sensor - Sun Elevation - LUX Value - Scenes - Time - Light Control - Device Tracker - Night Lights

@broder

Hi and thanks for asking the question. :smiley:

Let just check a few things.

  • binary_sensor.sensor_klotur_window_door_is_open = This is your door sensor? Strange name though with window and door. Hope this is just a door.
  • binary_sensor.hue_motion_sensor_1_motion_6 = This is your motion sensor.

When your door is closed is the state “OFF”? If the state is “ON” then you will need to reverse the 2 states in the code for your door.

Looks like your splitting your configuration files for your sensors (this is not how I would do it). This is a different topic for a different day and is most likely your problem :wink:. I will look to expand this further in a FAQ. For now can you move your trigger sensor as shown above to your configuration.yaml file.

Test it and let us know if it works.

Edit: Just checking you have

template:

at the top of your sensors

template:
  - trigger:
      - platform: state
        entity_id: binary_sensor.sensor_klotur_window_door_is_open
        to: "on"
      - platform: state
        entity_id: binary_sensor.sensor_klotur_window_door_is_open
        to: "off"
        for:
          seconds: 50
      - platform: state
        entity_id: binary_sensor.hue_motion_sensor_1_motion_6
        to: "on"
    binary_sensor:
      - name: "Jemand im Klo"
        device_class: occupancy
        icon: mdi:account-box-outline
        state: >
          {{ is_state('binary_sensor.sensor_klotur_window_door_is_open', 'off') and is_state('binary_sensor.hue_motion_sensor_1_motion_6', 'on') }}

Blacky :smiley:

FAQ - New Template Helper Sensors

:construction_worker_man: :construction: Stay tuned :construction: :construction_worker_woman:

Blacky :smiley:

1 Like

Is there a way when using the bypass (or when a light is manually switched on) to trigger the light off after the binary sensor motion is cleared (+ the timer set) regardless on any conditions set (lux, time, sun etc)

Hello, I’ve been doing this for several days but I can’t get it to work.
I use a binary helper as Bypass (On/OFF change when pressing the momentary switch).
Send scene that activates or deactivates it.
I get the automation to stop but still having the bypass operation configured to turn on. The problem is that pressing by default always changes the state (due to its direct function on the output).

What I need to do is make it go on automatic, but if someone presses (Light On changes to Off, Light Off changes to On) and in both cases the automation pauses until Light Off and bypass Off.

Sorry I am a little confuse on what your trying to do.

I am not realy following. But if the by-pass is ON then the automation will be paused. If the by-pass is OFF then the automation can run. When you turn off the by-pass the automation will look and see if the trigger is ON and preform the correct action.

First of all, this is a great blueprint, exactly what I needed!

I struggled a bit in the beginning as I was using two motion sensors which didn’t work well together.
But this has been sorted out by putting the two motion sensors in a group.

However I’m still facing an issue which I didn’t find a solution to yet.

When the motion is cleared an the lights dim to off state (2 second transition time) if at the exact time motion is detected it will fail and I have to restart the automation to get it working again.
If I don’t restart the automation the result is a quick (one time) flash of the lights when motion is detected.
It already happened two times in two days now.

It looks like it goes wrong when trigger is send to turn off the lights (but they are not off yet due to the transition time) and at the exact time motion is detected which turn the lights on (but they are already on because of the transition time to off state).

Hopefully someone has a solution for this.
For the upcoming days I will test if this still occurs with the transition option not selected.

@Mnmarcel

Hi Marcel, firstly welcome to the community :partying_face:

Nice work, thanks for taking the time to read the FAQ.

I have it where the lights start to transition (dim) and the motion gets detected again when dimming just about every day. When this happens the lights just come back ON with not issues.

When we send a command trough the automation to turn the lights OFF with some data for transition time, Home Assistant see the light as OFF first then the transition happens. You can check this by looking at HA and the light in question on a dashboard. Trigger the light ON and then you will see the light go OFF in HA followed by the light transition to OFF.

It could be what you are using though. I use a Shelly dimmers for this. If you can confirm that HA see the light OFF first and then dims? Can you also let us know what light / control you are using?

Blacky :smiley:

Hi Blacky,

I have tested the state during dimming by setting the transition time to 10 seconds and indeed in HA the state is off while the lights are dimming.
The device I’m using is a Miboxer (Milight) fut036z Zigbee led controller. This powers led strips on my stairs.

I don’t see any weird stuff in the logs.
The only thing that pops up is that it stops working when the turn off signal (motion cleared) is send at the exact same time (second) as the turn on signal (motion detected).

Could this be the Led controller?
PS: I’m already a bit disappointed with the led controller as I can not change the state after power outage. Standard state is “on”

It’s a bit difficult to reproduce as the timing has to be on the second.
So for the next couple of days I’m gonna test it without transition time, see if that helps.

I will keep you updated.

@Mnmarcel

Hi Marcel, thanks for the update.

That good news, so it will not be the blueprint or HA and probably your LED controller…

There are a lot of controllers out there. I personally use QuinLED with WLED. I have not had any problems so far to date.

Thanks it is always nice to know what is going on and how you went.

Blacky :smiley:

Hi Blacky,

With the changes of reproducing the issue being very slim, I tried something else just now.

I have put the transition time to 10 seconds.
During the dimming HA led state is “Off”, which is a good thing.
During the dimming I triggered the motion sensor to see if this messes things up.
And it did…
Lights went off (HA thinks it’s on) and couldn’t get them on again using the motion sensor. All I got is a quick flash once motion is detected.
If I look at the logbook it looks the same as it’s functioning properly.
Had to disable and enable the automation to get it working again.

So I guess this is related to the led controller, but disabling the transition time might eliminate this.

So for now I will disable the transition time and if that eliminates the issue then I’m fine with it.

Thanks so far Blacky, and have a nice weekend!

Hi, I love the blueprint and have used it for the last few months.

I’ve decided that I wanted to change it slightly but I can’t seem to get it to work.

I want the lights to be on a dimmed setting between sunset / dusk and 2300 daily, but when the PIR sensor activates I want the light to go to a bright setting for a few minutes and then return to the dimmed setting.

Is this possible?

Thanks in Advance

1 Like

Hey,

sorry for the late reply ! Tried what you suggested but still no luck. The lights still go off after 2 Minutes ( as set in the Blueprint).
I will continue fiddling around with it.

@leejbarker82

Thanks for your kind words.

Yes, there is a but though.

Before I explain the “but”, I agree this is something that needs to be resolved and will require some thought and some consideration. I will put it on the list.

Now the “but” or the how to.

  1. First create an automation using this blueprint.
  2. Set up your lights as required.
  3. Create a scene for your dimmed lights. Enter that scene into “Scenes To Turn OFF”.
  4. Enable the sun condition and adjust your settings to your liking.
  5. Enable the time options. Set the start time to a time the sun will be above your sun elevation setting. Like 4pm. Then set the end time to 2300.

This will now do the motion part and reset to dim.

Next step

  1. Download my other blueprint. :gear: Turn Light, Switch or Scene On & Off with Trigger Conditions
  2. Create an automation using this blueprint.
  3. In "Lights - Switches - Entities - Scenes " enter the dimmed scene used in the first sensor light automation.
  4. Create another scene with all the light OFF and enter it into “Scenes To Turn OFF”.
  5. Enable the sun option with the same settings as in the first sensor light automation.
  6. Enable the time option and set your start time to 23:00:01 (and 1 second).
  7. Set the end time to 23:00:02 (and 2 second).

This will turn the light ON to the dimmed setting sunset / dusk and turn the lights OFF at 23:00:02.

Your done

Hope this helps

Blacky :smiley:

@broder

:warning: NOTE: HA is releasing a new helper for templates. Maybe just wait for the next release before you do all this work. It will be out this Wednesday for HA release 2023.9.

There are many ways to split up the configuration. There is no wrong or right way to do it, it just realy depends on the way you would like it + it must work. Before splitting up your configuration I would strongly recommend that you do some research before committing to one way, as it takes some time to set everything up. Below are two links to the official Home Assistant website on this topic (there could be more but this is what I know). Both ways work. There are also a lot of different posts on this forum + some YouTube videos also on this topic so maybe check them out.

  1. Splitting up the configuration
  2. Packages

The way I like is; Splitting up the configuration - Advanced Usage " !include_dir_merge_list". For me it is very similar to you normal PC file structure. I simple and easy and I like that. Below I will show how I set up my template sensors as I did create a FAQ on template sensors in this topic. This “Sensor Light” post is not a “How To Use Home Assistant” and would prefer to stay on topic of this blueprint so I will stick to just template sensors. If you would like more information on split up the configuration please search this forum or create a new topic. There are a lot of active community members that will be able to assist you.

How I split up the configuration

1 - First most important, do a full backup of your Home Assistant, and store it in a location where you can get to it if you brick your Home Assistant (on a separate computer not running Home Assistant).

2 - You must have a file editor. There are few to choose from. If you don’t have one already installed then this is how to add the official “File Editor” into your Home Assistant. Go to Settings / Add-ons and then click on “add-on store”. In the " Official add-ons" heading you will see “File Editor”, click on it and install it.

3 - Once you have a file editor you will need to create a new folder called “template” in the main directory “/config/” (same location you can see your “configuration.yaml” file). Once done you will have “/config/template” folder location. This is where we are going to put all our template sensors. In this folder I have also created another folder called “sensors”. This is where I put all my sensor in. I don’t care if they are a “sensor”, “template binary_sensor”, “template trigger_sensor”, etc they are all in the one folder. Some people like to split there sensors into the domain of the sensor, it up to you. So now I have a “/config/template/sensors” folder location.

4 - In your “configuration.yaml” file we will need to point HA to it. To do this you would enter this code.

template: !include_dir_merge_list template

Now all your templates must go into this folder.

5 - In the “/sensors” folder, I create a new file for each sensor. We will use the template sensor I call “Bee In The Hive” for this example. So I create a file called “bee-in-the-hive.yaml”. Note: You must have the “.yaml” for each file you create. In that file I put this code as described in my FAQ Template Sensors.

# Bee In The Hive

  - trigger:
      - platform: state
        entity_id: binary_sensor.your_door_sensor_here
        to: "on"
      - platform: state
        entity_id: binary_sensor.your_door_sensor_here
        to: "off"
        for:
          seconds: 10
      - platform: state
        entity_id: binary_sensor.your_motion_sensor_here
        to: "on"
    binary_sensor:
      - name: "Bee In The Hive"
        device_class: occupancy
        icon: mdi:account-box-outline
        state: >
          {{ is_state('binary_sensor.your_door_sensor_here', 'off') and is_state('input_boolean.testing_motion_sensor', 'on') }}

Note: We did not need to put

template:

at the top if each sensor file as this is back in the “configuration.yaml” file.

Then check your configuration by going to “Developer Tools” and “Check Configuration” link. Once it passes " restart HA with one sensor first to make sure you have everything correct. Test it make sure it is working. Then when you feel confident add the rest of your sensors checking your configuration every time you add a file as it is easer to find what you have done wrong.

Then you would just do the same for all your template sensors in there own file.

Hope this helps you.

Blacky :smiley:

1 Like

New update 4.7

:warning: Some work is required in this upgrade. Please see below on the steps required when upgrading. It is easy and not a breaking change.

New Features :new:

:white_check_mark: MULTIPLE BY-PASS UPGRADE

In our update to version 4.5 we added the ability to have multiple by-pass switches. Example, by-pass for;

  • All light Automations
  • Party Mode
  • Guest Mode
  • Night Time
  • Sleep Mode
  • Movie Mode
  • Upstairs Lights
  • Downstairs Lights
  • Bedroom Lights
  • Smoke Alarm
  • Alarm System
  • Kitchen Lights
  • Outside Lights
  • Etc

It allowed multiple by-passes but you could only select one enable option and each by-pass could require to preform a different action.

In this update you can now add multiple by-pass switches for each of the 3 different by-pass enable options :partying_face:

  1. Enable the By-pass - Turn lights ON
  2. Enable the By-pass - Turn lights OFF
  3. Enable the By-pass - Keep the lights current state

Now you can created multiple by-passes with different actions. Example, by-pass for;

  • All light Automations = ON & OFF
  • Party Mode = ON
  • Guest Mode = Pause
  • Night Time = OFF
  • Sleep Mode = OFF
  • Movie Mode = OFF
  • Upstairs Lights = ON & OFF
  • Downstairs Lights = ON & OFF
  • Bedroom Lights = OFF
  • Smoke Alarm = ON
  • Alarm System = ON
  • Kitchen Lights = ON & OFF
  • Outside Lights = ON & OFF
  • Etc

Hopefully it will help assist you on how you control your lights.

Example Use Case: Say it is a windy night and your outside lights keep going ON. You can now have a by-pass that is for “All Outside - Lights OFF” and add this bypass into every outside light automation. Then you can turn ON one by-pass switch and all your outside light will go OFF and stay OFF (disabling every automation). What happens if you hear something outside you could have a by-pass “All Outside - Lights ON” and add this bypass into every outside light automation. I think you get the idea behind it. There are so many scenarios that you can do.
.
We are also getting ready for more to come in the road map ahead :wink:

:warning: BLUEPRINT CODE UPDATE :exclamation:

Just a heads up if your still on a old HA version before you update.

From time to time Home Assistant update their code structure and the old code will become “DEPRECATED” stopping / breaking automations from working. It effected this blueprint about 4 to 6 months ago. I wanted to wait some time so everyone had a chance to update their HA version before updating the code as older HA versions can not run the new code. This blueprint has now been updated so it will still operate once HA remove the “DEPRECATED” code from their system. :wink: :+1:

Bugs Fixes :bug:

  • Fixed bugs in HA restart.

:warning: :stethoscope: STEPS REQUIRED WHEN UPGRADING :white_check_mark:

If you have never selected to use a by-pass then most likely you won’t need to do anything but you may want to check just encase you have selected by-pass in the past.

1 - Upgrade your blueprint.
2 - Go into your automation (the ones using this blueprint). Click the 3 dots top right and “Edit in YAML”. We are looking for orange text “include_bypass”, “motion_bypass” & “include_bypass_auto_off”. If you don’t see this then your all good to go and have never selected the by-pass. If you see this then read on.

3 - Take note of the code so you can remember what by-passes were used in the automation. We then are going to completely remove the orange text including the black input text for “include_bypass”, “motion_bypass” & “include_bypass_auto_off” as shown below.

4 - Then click 3 dots and select “Edit in visual editor”

9

5 - You will then have a clean input selection for your by-passes. Update / add the by-passes into the correct corresponding inputs.

6 - Click save, you’re done. Now just do the same in your other automations using this blueprint.

TIP
If you would like to easily find all the automation that are using this blueprint so you can check your YAML. Go into blueprints and click on the 3 dots next to the sensor light blueprint and select “show automations using this blueprint” You then can easily edit them all. See below.

If you like this blueprint? Consider hitting the :heart: button in the top post :+1:

If you like my blueprints, and would like to show your support or just say thank you? Click Here :smiling_face_with_three_hearts:

Enjoy

Blacky :grinning:

Back to FAQ: Click Here

4 Likes

Thank you very much for the time and detailed explanation… I’ll give it a whirl and let you know how I get on :+1:

And a but with a how to, isn’t really a but :joy:

No problem at all :+1:

Yea it is always nice to know how you go.

Hello,

In first place, thank you for this amazing blueprint. It’s great.

I have a problem with it … When sun elevation is below !input sun_elevation, lights switch on without the motion trigger still being activated. I have to manually switch off the lights and then everything works as expected. I don’t know if I’m missing something or my configuration has any error.

Here it is my blueprint configuration:

alias: Home:luces hall automáticas
description: Controla luces del hall con sensor de movimiento
use_blueprint:
  path: Blackshome/sensor-light.yaml
  input:
    motion_trigger:
      - binary_sensor.sonoff_a4800671ba
    time_delay: 0.5
    include_light_control: []
    light_brightness: 75
    light_transition_on: 1
    light_transition_off: 1
    include_sun: sun_enabled
    sun_elevation: 4
    include_night_lights: night_lights_enabled
    light_switch:
      entity_id: scene.luces_hall_pinar_naranja
    end_scenes:
      - scene.luces_hall_pinar_apagadas
    night_lights:
      entity_id: scene.luces_hall_pinar_noche
    night_time_delay: 0.5
    night_lights_conditions:
      - time_enabled
    night_lights_before_time: "08:00:00"

Thank you!

@miguelpucela

Your welcome, glad you like it and thanks for your kind words.

Thanks for providing your YAML… it all looks good :wink:

I have this set up at home and it runs every day. The light should not come ON when the sun elevation crosses over and your motion sensor is “clear”. It will only turn ON when the sun elevation crosses over and your motion sensor is “Detected”. If it turned your light ON, when your motion sensor becomes “clear” it will turn OFF the light.

I suspect that you may have another automation turning it ON and that is why you need to turn it OFF as this blueprint automation never triggered thus not turning OFF your light when the motion sensor is “clear”. I have been caught out on this many times :pensive:

What I would do is monitor it one night. When the light turns ON check your automations and see what triggered it. A easy way to find it, is to look in your logbook. As you can see below in my logbook I can see that the hallway lights were turned on by the “Hallway Lights” automation with motion sensor 1.

Then you can click on the link to edit it and or delete / disable the automation.

Let us know if this fixes it.

Blacky :smiley: