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

@danielo515

You can and you donā€™t need a script. You can use a scene or a script or just your light entities with no scene or script. It is totally up to you. But if you would like to use a scene or a script it is recommended to add a helper because scenes and scripts have no stateā€¦ so in order for the automation to know if the lights are ON it looks at the helper to ensure the smooth operation of the automation.

Blacky :smiley:

Hi,

Here is a video with whatā€™s happens.
Video

Hue motion badrum Motion - this is the motions sensor

Aqara Door Sensor Badrum - this is the door sensor

Badrumsensor Grupp - this is the group

Badrumsensor Template - and this is the template sensor

you can see in the video that the door is closed then when I open the door the motions sensor gets triggered and the door sensor closes. The group sensor is on until the motion clear then It changes to off and last the template sensor is always clear.

There is no delay for the door sensor as you can see inte the video.
I set upp the template sensor inte the UI because in the configuration.yaml I get errors when I add it and it dosent work.

I hope you can help me I really want this to work :slight_smile:

Edit:

Managed to make the template work by changing the code from - platform: state to - trigger: state and it seems to be working now but I still have a problem, the lights still turn off when someone is in the room and the lights wonā€™t turn off when exiting the room.

I have a problem with your template. In my kitchen i have it turn on 2 different lights, when motion is detected. However, the LED strip under my kitchen cabinets slowly turn on for about .2-.5 seconds and then turn completely off, while the ceiling light turns on as it should. Do you have any idea why that happens?

Blueprint config:

id: '1729173428057'
alias: BevƦgelsesaktiveret lys KĆøkken
description: ''
use_blueprint:
  path: Blackshome/sensor-light.yaml
  input:
    motion_trigger:
      - binary_sensor.kokken_sensor_bevaegelse_aqara_occupancy
    light_switch:
      entity_id:
        - light.kokken_controller_ledstrip_miboxer
        - light.kokken_lampe_loft_shelly
    time_delay: 1
    include_light_control:
      - use_brightness
      - use_transition
      - use_colour_temperature
    light_transition_on: 3
    light_transition_off: 10
    light_colour_temperature: 3500
    night_lights:
      entity_id: light.kokken_controller_ledstrip_miboxer
    include_night_light_control:
      - use_brightness
      - use_transition
    night_light_transition_on: 3
    night_light_transition_off: 3
    night_lights_after_time: '23:00:00'
    night_lights_before_time: '05:00:00'

Sunds very promising with the Bee in the hive automation! Iā€™ve read about it and tried implementing it, but i canā€™t seem to figure out where to input the code?
Is it a helper? An automation? Should i put it into configuration.yaml, under sensors?

  - 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.your_door_sensor_here', 'off') and is_state('binary_sensor.your_motion_sensor_here', 'on') }}

I have a radar motion sensor which reports how far movement is awayā€¦
It is reported in ā€œlargeā€, ā€œmediumā€ and ā€œsmallā€
Is it possible to just use for example the state ā€œsmallā€ as a trigger, so the lamp only goes on when i am in a small radius?
How could i achieve this?
Thanks!

Iā€™ve been porting over all of my custom AppDaemon automations to this blueprint, and so far Iā€™ve been able to make everything work well. Thank you!

Apologies if this has already been discussed. It appears this topic has so many replies that the site search is kind of broken for it!

I had this set up with my AppDaemon automation for my front motion lights. The requirement was that if the lights were manually turned on at the switch, they stay on bypassing the motion light automation. I was able to do this by:

  1. Creating a toggle helper called ā€œFront Lights Motion is Activeā€.
  2. Creating a script that is called as the light turn on action. The script first checks to see if the lights are off, or if the Active helper is set. If it passes, it sets that flag:
alias: Turn On Front Light Motion
sequence:
  - if:
      - condition: or
        conditions:
          - condition: state
            entity_id: light.front_lights
            state: "off"
          - condition: state
            entity_id: input_boolean.front_lights_motion_is_active
            state: "on"
    then:
      - action: light.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: light.front_lights
      - action: input_boolean.turn_on
        target:
          entity_id: input_boolean.front_lights_motion_is_active
        data: {}
    else:
      - stop: Lights are manually controlled
description: Used by motion light automation
  1. Adding a corresponding script to handle turning things off and resetting the flag:
alias: Turn Off Front Light Motion
sequence:
  - if:
      - condition: state
        entity_id: input_boolean.front_lights_motion_is_active
        state: "on"
    then:
      - action: light.turn_off
        target:
          entity_id:
            - light.front_lights
        data: {}
      - action: input_boolean.turn_off
        target:
          entity_id:
            - input_boolean.front_lights_motion_is_active
        data: {}
description: Used by motion light automation

The only downside is that if the light was turned on by motion, and you want to keep it on using only the physical switch, you need to turn it off and on again. But, thatā€™s how it worked in the AppDaemon automation and so far thereā€™s been no complaints.

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