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

hey guys, i use a motionsensor in my bedroom, that triggers a light to turn on in my hallway using this blueprint. in some situations the hallway light is manualy turned on by me. if i get motion in my bedroom the light in the hallway turns off after 30 secons cause of the blueprint settings.

is there a way to let the blueprint check if the light is already turned on and if so to not run the automation to turn it off?

@Bogdis

In your group you should only have your motion sensor and your bee in the hive sensor. Donā€™t add the door sensor. Then the group should be the only entity in the trigger input in the blueprint.

Blacky :smiley:

@Strux

This is strange as your ceiling light stays ON. Maybe it is the LED controller with the blueprints light control. Try and disable Use Brightness and Use Transition and see if that works. If so then add one back in at a time to see what one causes the problem.

The below code goes into your configuration.yaml. The heading ā€œtemplate:ā€ is where you put all your template sensors under. Normally when you have a occupancy sensor they can detect you well as long as they can see you in line of sight.

template:
  - trigger:
        - platform: state
          entity_id: binary_sensor.badevaerelse_sensor_dor_aqara_contact
          to: "on"
        - platform: state
          entity_id: binary_sensor.badevaerelse_sensor_dor_aqara_contact
          to: "off"
          for:
            seconds: 10
        - platform: state
          entity_id: binary_sensor.badevaerelse_sensor_bevaegelse_aqara_occupancy
          to: "on"
      binary_sensor:
        - name: "BadevƦrelse Optaget Sensor"
          device_class: occupancy
          icon: mdi:account-box-outline
          state: >
            {{ is_state('binary_sensor.badevaerelse_sensor_dor_aqara_contact', 'off') and is_state('binary_sensor.badevaerelse_sensor_bevaegelse_aqara_occupancy', 'on') }}

Blacky :smiley:

@Flo_93

You would create a template binary sensor and use the state ā€œsmallā€ then use that template binary sensor only as the trigger.

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 (motion?) 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 your_radar_motion_sensor_entity_id_here with your entity ID.

{{ is_state('your_radar_motion_sensor_entity_id_here', 'small') }}

Blacky :smiley:

1 Like

@deviantintegral

Hi Andrew, you can also do it by creating a template binary sensor and add it into the bypass but you will have the same problem, that isā€¦ if the light is ON you will have to turn it OFF and back ON again for it to turn ON the binary sensor.

template:
  - trigger:
      - trigger: state
        entity_id: light.your_light_switch_here
        to: "on"
        id: "t1"
      - trigger: state
        entity_id: light.your_light_switch_here
        to: "off"

    binary_sensor:
      - name: "Manual Light Switch"
        icon: mdi:cog-pause
        state: >
          {% if trigger.id == 't1' and trigger.to_state.context.parent_id is none %}
            on
          {% else %}
            off
          {% endif %}

Blacky :smiley:

1 Like

@mase

You can but it is not perfect, that isā€¦ if the light is ON you will have to turn it OFF and back ON again for it to turn ON the binary sensor. Once you create the binary sensor you then add it to bypass option 1 as that will turn the light ON.

template:
  - trigger:
      - trigger: state
        entity_id: light.your_light_switch_here
        to: "on"
        id: "t1"
      - trigger: state
        entity_id: light.your_light_switch_here
        to: "off"

    binary_sensor:
      - name: "Manual Light Switch"
        icon: mdi:cog-pause
        state: >
          {% if trigger.id == 't1' and trigger.to_state.context.parent_id is none %}
            on
          {% else %}
            off
          {% endif %}

Blacky :smiley:

1 Like

But in your description of Bee in the hive sensorn is to add the door sensor and motion to the group or have I and ChatGPT miss read that?

In the bee in the hive example I have the below statement. It says once you create this sensor (bee in the hive) then group with you motion sensor and add the group to the trigger.

Iā€™ll keep refining the post to make it as clear as possibleā€¦ thank you so much for your feedback, it really helps! Sorry if my earlier explanations werenā€™t quite clear, but I think weā€™re on the same page now, and hopefully, youā€™ve got it working."

Edit: I have updated all the bee in the hive post now. Thanks again.

Blacky

Hello, I like your blueprint, i am having a hard time getting this to work without issue. The different items not working, and i have to manually run it after ha reboot or if i run a scene or manually change the lights.

alias: Sensor Light - Bedroom
description: ""
use_blueprint:
  path: Blackshome/sensor-light.yaml
  input:
    motion_trigger:
      - binary_sensor.bedroom_mmwave_radar_target
    light_switch:
      entity_id:
        - light.bedroom_back_left
        - light.bedroom_back_right
        - light.bedroom_left
        - light.bedroom_right
    time_delay: 3
    light_colour_temperature: 8000
    include_ambient: ambient_enabled
    ambient_light_sensor: sensor.bedroom_mmwave_ltr390_light
    include_device_tracker: zone_people_enabled
    zone: zone.home
    people:
      - person.*****
      - person.*****
      - person.*****
    night_lights:
      entity_id:
        - light.bedroom_left
        - light.bedroom_right
    night_time_delay: 3
    include_night_light_control:
      - use_brightness
      - manage_scripts_crossing_over
      - use_transition
      - if_lights_are_on_adjust_when_crossing_over
    include_night_light_colour_control: use_rgb_colour
    night_light_rgb_colour:
      - 255
      - 0
      - 0
    include_night_lights: night_lights_enabled
    night_lights_conditions:
      - entity_state_enabled
    night_lights_entity_state:
      - input_boolean.bedroom_sonos_helper
    night_lights_after_time: "21:01:00"
    night_lights_before_time: "21:02:00"
    include_light_control:
      - use_brightness
      - use_transition
    include_light_colour_control: use_colour_temperature
    end_scenes:
      - script.bedroom_turn_off_all_lights
    light_transition_on: 2
    light_transition_off: 2
    night_light_transition_off: 1
    include_dynamic_lighting: enable_lux_controled_brightness
    dynamic_lighting_lux_sensor: sensor.bedroom_mmwave_ltr390_light
    dynamic_lighting_max_lux: 900
    dynamic_lighting_min_lux: 50
    dynamic_lighting_max_colour_temp: 8000
    dynamic_lighting_min_colour_temp: 2000
    dynamic_lighting_heartbeat: 10
    night_light_brightness: 1

@wagnerks1990

Welcome to the community.

Thanks for your YAML.

I have changed a few things. Note; because you are using dynamic lighting option 1 if you change the brightness and normal lights are active then dynamic lighting will change the brightness to suit.

  1. Removed script in Scenes - Scripts To Turn OFF. Because you are using light entities you donā€™t need a end scrip to turn OFF you lights.
  2. In Ambient condition set your LUX levels to reflect dynamic lighting levels you have set.
  3. Could you create a toggle helper and add it into dynamic lighting Dynamic Lighting - Toggle Helper (Optional). You have set a Dynamic Lighting - Min Brightness Value to 0% so you will need to add this toggle helper in.
  4. In Night Light Control I have un-ticked Yes - Manage OFF script when crossing over as I removed the script you had above in 1.
  5. Because you are using dynamic lighting in Light Control I have un-ticked Use Brightness. It wont matter if it is ticked but because you are using dynamic lighting option 1 it will not be used.

Below is you new code, Just remember to update your people in zone.

alias: Sensor Light - Bedroom
description: ""
use_blueprint:
  path: Blackshome/sensor-light.yaml
  input:
    motion_trigger:
      - binary_sensor.bedroom_mmwave_radar_target
    light_switch:
      entity_id:
        - light.bedroom_back_left
        - light.bedroom_back_right
        - light.bedroom_left
        - light.bedroom_right
    time_delay: 3
    light_colour_temperature: 8000
    include_ambient: ambient_enabled
    ambient_light_sensor: sensor.bedroom_mmwave_ltr390_light
    include_device_tracker: zone_people_enabled
    zone: zone.home
    people:
      - person.*****
      - person.*****
      - person.*****
    night_lights:
      entity_id:
        - light.bedroom_left
        - light.bedroom_right
    night_time_delay: 3
    include_night_light_control:
      - use_brightness
      - use_transition
      - if_lights_are_on_adjust_when_crossing_over
    include_night_light_colour_control: use_rgb_colour
    night_light_rgb_colour:
      - 255
      - 0
      - 0
    include_night_lights: night_lights_enabled
    night_lights_conditions:
      - entity_state_enabled
    night_lights_entity_state:
      - input_boolean.bedroom_sonos_helper
    night_lights_after_time: "21:01:00"
    night_lights_before_time: "21:02:00"
    include_light_control:
      - use_transition
    include_light_colour_control: use_colour_temperature
    light_transition_on: 2
    light_transition_off: 2
    night_light_transition_off: 1
    include_dynamic_lighting: enable_lux_controled_brightness
    dynamic_lighting_lux_sensor: sensor.bedroom_mmwave_ltr390_light
    dynamic_lighting_max_lux: 900
    dynamic_lighting_min_lux: 50
    dynamic_lighting_max_colour_temp: 8000
    dynamic_lighting_min_colour_temp: 2000
    dynamic_lighting_heartbeat: 10
    night_light_brightness: 1
    ambient_light_value: 900
    ambient_light_high_value: 1000

Blacky :smiley:

Iā€™m sorry if i seem stupid, itā€™s just all very new to meā€¦
I have a split configuration, as you can seeā€¦
billede
And i guess, since you call this a template sensor, it should be in the sensor.yaml file, right?
But when i do that, it throws a bunch of errors:


Why is that?

@Strux

I can see you getting a bit advanced in your set up.

No because you donā€™t have

template: !include template.yaml

I personally do it this way and create folders but it is getting a bit off topic of this post/blueprint. HA is starting to do it all through helpers now but they are yet to have template trigger so I only have my template trigger sensors and some advance sensors there now and I use the helpers as it is a lot cleaner and easier to manage. If you need more help splitting your templates then maybe create a new topic or research the forum as there will be a lot of information on this. Even YouTube has people showing you how to.

template: !include_dir_merge_list template
sensor: !include_dir_merge_list sensor

Below is you code all fixed up.

template:
  - trigger:
      - trigger: state
        entity_id: binary_sensor.badevaerelse_sensor_dor_aqara_contact
        to: "on"
      - trigger: state
        entity_id: binary_sensor.badevaerelse_sensor_dor_aqara_contact
        to: "off"
        for:
          seconds: 10
      - trigger: state
        entity_id: binary_sensor.badevaerelse_sensor_bevaegelse_aqara_occupancy
        to: "on"
    binary_sensor:
      - name: "BadevƦrelse Optaget Sensor"
        device_class: occupancy
        icon: mdi:account-box-outline
        state: >
          {{ is_state('binary_sensor.badevaerelse_sensor_dor_aqara_contact', 'off') and is_state('binary_sensor.badevaerelse_sensor_bevaegelse_aqara_occupancy', 'on') }}

If you go my way and add the code below to your config file

template: !include_dir_merge_list template

You then create a folder under CONFIG (if using studio code server) or homeassistant/ (if you are using file editor) called template.

Once you done that in template folder you can create sub folders or just yaml files. I have a sub folder called binary. In binary you the create a file for your sensor say badevƦrelse_optaget_sensor.yaml. In the file add this code

# You can add a note here for future if you like

  - trigger:
      - trigger: state
        entity_id: binary_sensor.badevaerelse_sensor_dor_aqara_contact
        to: "on"
      - trigger: state
        entity_id: binary_sensor.badevaerelse_sensor_dor_aqara_contact
        to: "off"
        for:
          seconds: 10
      - trigger: state
        entity_id: binary_sensor.badevaerelse_sensor_bevaegelse_aqara_occupancy
        to: "on"
    binary_sensor:
      - name: "BadevƦrelse Optaget Sensor"
        device_class: occupancy
        icon: mdi:account-box-outline
        state: >
          {{ is_state('binary_sensor.badevaerelse_sensor_dor_aqara_contact', 'off') and is_state('binary_sensor.badevaerelse_sensor_bevaegelse_aqara_occupancy', 'on') }}

And your done.

Blacky :smiley:

Youā€™re right that I donā€™t need a script, nor a toggle.
I didnā€™t saw that I can select a scene in the ā€œentityā€ picker.
I think your example is probably too complex for a ā€œfirst introductionā€ to the solution. If you have never faced the situation you will not see the value, and it makes you think that the only way to take advantage of the feature is with all that added complexity.
I may be the weirdo here, but I think that a ā€œsimpleā€ and a ā€œcomplexā€ example will make things easier. Or maybe a disclaimer? ā€œthis is only needed if you want to transition from normal lights to night lights that stay onā€ or something like that.
Cheers

@danielo515

Yeah it is a big blueprint and has so many featuresā€¦ this can be overwhelmingā€¦ It can do so many things.

Hope you got it working, to start just add a trigger (motion sensor) enter in your light/s entities and click save. That starts your lights coming ON and OFF. Then tackle night lights in a similar way.

Blacky :smiley:

1 Like

Thanks!
I will definently look into splitting it up into folders and additional files, that would give a much better overview!

It seems like the Bee In The Hive sensor is working! Thank you!

I use your blueprint for all my motion-activated lights. Some of the lights also have a switch attached to them, so you can also manually turn on (and off) the lights. How does that affect the automation? If i manually turn on the lights and the motion sensor detects motion in the room (because i move around in the room) would the automation still turn off the lights? I ask because i have the impression that sometimes when the lights are turned on manually (usually because they have been turned off accidentally for some time) they stay on. Do you know why?

No problem,

Glad you got it working.

Have a look at this post click here

Blacky :smiley:

Thereā€™s still a problem with the sensor, but iā€™m not sure what. Maybe itā€™s the position of my motion sensor; i have it pointing not directly towards but along the wall where the door is. This means motion is detected before the door is closed. Could that be the problem? (After just reading your docs, it seems no, it should be using scenario 2.

There are 2 times that affect this automation, the motion sensor reset time in the ā€œBee In The hiveā€ template sensor, and the ā€œTime Delayā€ value in the blueprint.

The ā€œBee in the hiveā€ sensor should reflect the time it takes for the motion sensor to reset to ā€œno motion detectedā€ from ā€œmotion detectedā€. For my Aqara Motion sensor P1, i have 2 time vaules: ā€œDetection interval: Time interval between action detectionā€ and ā€œOccupancy timeout: Time in seconds after which occupancy is cleared after detecting it.ā€ i guess it is the latter, which by default is set to the value of ā€œdetection intervalā€+2s. Detection interval is 10s, which means the other sensor must be 12s. So i set the delay value in the ā€œBee in the hiveā€ sensor to 20s.

The ā€œTime delayā€ value in the blueprint is set to 2 minutes.

I open the door, go in, close the door, do motion for 20s, then stand totally still. The lights turn off after 2 minutes. Why?

template sensor:

- trigger:
    - trigger: state
      entity_id: binary_sensor.badevaerelse_sensor_dor_aqara_contact
      to: "on"
    - trigger: state
      entity_id: binary_sensor.badevaerelse_sensor_dor_aqara_contact
      to: "off"
      for:
        seconds: 20
    - trigger: state
      entity_id: binary_sensor.badevaerelse_sensor_bevaegelse_aqara_occupancy
      to: "on"
  binary_sensor:
    - name: "BadevƦrelse Optaget Sensor"
      device_class: occupancy
      icon: mdi:account-box-outline
      state: >
        {{ is_state('binary_sensor.badevaerelse_sensor_dor_aqara_contact', 'off') and is_state('binary_sensor.badevaerelse_sensor_bevaegelse_aqara_occupancy', 'on') }}

start section of blueprint: (iā€™m not going to insert 6000+ lines of code)

sensor group:

logbook:

@Strux

Sorry your having trouble :pensive:. I have just made a test sensor for this and it works perfectly.

NOTE: Every time you change/edit your template sensor YAML you have to reload it for it to take effect. Easiest way is to go into developer tools > YAML tab > scroll down to Template Entities and click itā€¦ you should see a green tick.

Let try a few things to make it clear. In a dashboard add an entities card. In the card enter your door contact sensor, your sensor group, your motion sensor and your bee In The Hive sensor like shown below.

145

Now you can see at what is happening. Test a few things.

  1. Trigger your motion sensor and time how long it takes to go from detected to clear. Then add a few seconds (+5) to your time (seconds). Use this time as a starting point replacing your 20 seconds. Make sure you reload your template senors every time you change it as described above.
  2. Close the door, stand still not to trigger your motion sensor and wait until it is clear. Everything must be clear, then make your motion sensor go detected. You should see the group and bee in the hive go to detected. It should stay that way until you open the door.
  3. Close the door, keep your motion sensor detected past your seconds. You should see the group and bee in the hive go to detected. It should stay that way until you open the door.

If you would like to show me your settings please dont copy 6000+ lines of code. What you do is go into your automation, top right 3 dots, Edit in YAML, copy all the code (will be a small amount of YAML just your settings), come back to the forum and in your reply at the top tool bar click on ā€œ</>ā€ and paste code in there.

Blacky :smiley:

Now it work thank you. :grinning:

And great job on the guide update, now itā€™s very clear.

1 Like

Your welcome, glad you got it working.

Enjoy

Blacky :smiley: