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

@herbert1910

No, create a toggle helper and use it as the trigger. While you can’t select the toggle helper directly, you can copy and paste its entity ID into the trigger input field. Once the helper is configured, turning it ON will activate the automation. The ambient settings will then manage the automation, automatically switching the lights ON and OFF as needed.

Hope this make scene.

Blacky :smiley:

Hi Blacky! Thanks for the amazing blueprint and the support you provide here.

I recently enabled my first automation from this blueprint. I now noticed that it seems to consume a lot of RAM causing HA to become unresponsive. It seems there is a related infinite recursion / stackover flow. In more detail, I observed the following:

First, I had configured the automation without toggle helper (1 motion sensor, one light entity, dynamic lighting mode 13). When the motion sensor was triggered frequently, RAM usage went from 25% up to around 80-90%.

In the screenshot above, I restarted HA at 19:15, but RAM usage went up again afterwards.

In the log, I discovered critical log messages such as this:

Logger: homeassistant.helpers.script
Source: helpers/script.py:1015
First ocurrence: 20:02:12 (1 ocurrences)
Last logged: 20:02:12

Until condition [{'value_template': Template<template=({{ ((dynamic_lighting_boolean == []) and (expand(light_entities) | selectattr('state', '==', 'off') | list | count > 0)) or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean, 'off'))) }}) renders=42132>, 'condition': 'template'}] in script `Flur Sensor Light: Choose at step 1: default: Parallel actions for dynamic lighting and normal lights: parallel 1: Choose at step 15: 13 - Dynamic Lighting - Time Controlled - Brightness` terminated because it looped 10000 times

This is the infinite recursion / stackoverflow I mentioned above. More observations on that later.

Then, I disabled the automation. The RAM did not go up. When I enabled it again and triggered the motion sensor, RAM usage raised again, and the errors occurred again.

Due to a recommendation from a friend, I then added a toggle helper. (Previously, I figured I do not need a toggle helper because I did not trigger my own scenes or scripts.) This changed the behavior to the following:

One “cluster” of triggering the motion sensor still causes RAM usage to raise, but only up to around 45%. Interestingly, at exactly the point where the rise stops, I see the stackoverflow message.
Later, I triggered the motion sensor again, which added another 25% until it encountered the error again.

So, from my outside perspective I suppose the following happens:

  • There is an underlying infinite recursion (apparently related to dynamic lighting guessing from the error message), which quickly takes up a lot of RAM while the recursions pile up.
  • Without toggle helper, multiple instances of the automation overlap, so the RAM usage quickly gets pretty high.
  • With toggle helper, only one instance of the automation runs at a time. When the instance is killed due to the high number of recursions, the RAM usage rise stops. However, it seems that the resources are not properly freed (might be a Python thing?). So the next instance of the automation adds another step until it crashes again.

On a side note, it seems that the RAM that was covered one is not freed quickly. Restarting HA brought the RAM back down to ~25%. But it seemed the system only forcefully freed RAM when the usage was very high (~90%). However, but I did not observe that for more than half an hour, so it might be different after more time.

tl;dr: It seems that in my setup, the automation enters an infinite recursion, which consumes a lot of RAM until it hits a stack overflow.

Dear Blacky, do you have any ideas on that topic? Sorry for the long post, but I hope it was possible to follow along.

For completeness, I am using version 7.6 of the blueprint. Here is the YAML of my automation:

Click to expand
alias: Flur Sensor Light
description: ""
use_blueprint:
  path: Blackshome/sensor-light.yaml
  input:
    motion_trigger:
      - binary_sensor.flur_bewegungsmelder_bewegung
    light_switch:
      entity_id:
        - light.flur_licht_leuchte
    time_delay: 1
    include_light_control:
      - use_transition
      - use_colour_temperature
      - use_brightness
    light_transition_off: 5
    light_transition_on: 0.5
    light_colour_temperature: 3400
    include_night_lights: night_lights_enabled
    night_lights:
      entity_id:
        - light.flur_licht_leuchte
    night_time_delay: 0
    include_night_light_control:
      - use_brightness
      - use_colour_temperature
      - use_transition
    night_light_colour_temperature: 1900
    night_light_brightness: 1
    night_light_transition_off: 10
    night_lights_conditions:
      - time_enabled
    night_lights_before_time: "05:30:00"
    include_light_colour_control: use_colour_temperature
    include_night_light_colour_control: use_colour_temperature
    include_dynamic_lighting: enable_time_controled_colour_brightness
    dynamic_lighting_max_colour_temp: 3400
    dynamic_lighting_min_colour_temp: 2500
    dynamic_lighting_time_start_morning: "05:30:00"
    dynamic_lighting_time_end_morning: "06:30:00"
    dynamic_lighting_time_end_evening: "00:00:00"
    dynamic_lighting_heartbeat: 5
    dynamic_lighting_time_start_evening: "19:00:00"
    night_lights_after_time: "23:00:00"
    dynamic_lighting_min_brightness: 99
    boolean_scenes_scripts: input_boolean.flur_sensor_light_toggle_helper

I appreciate any help! I would really love to get the blueprint to work stably in my setup, since so many work and love already went into it! Let me know if I can provide more info or test anything specific.

Best, Rhidus

2 Likes

@Rhidus

Thank you for your detailed post and thorough testing… it was incredibly helpful in identifying the issue quickly. I truly appreciate your effort!

The problem stemmed from a bug in the condition logic that caused an unintended loop. :pensive:

This has now been fixed, and the updated blueprint should resolve the issue. :raised_hands: Please update the blueprint, test it, and let us know if the problem is resolved.

Once again, thank you for reporting this bug and helping improve the blueprint! :blush:

I have also updated your YAML but I am not sure if this is what you are after as some of your setting may be from testing.

  1. Because in dynamic lighting your brightness is from 100% to 99% and you are using option 13 I changed it to option 10 and your 100 % brightness will be handled in light control.
  2. Removed your toggle helper as it is not needed.
  3. In dynamic lighting changed the Dynamic Lighting - Time Evening - End Point to be 11pm so you will finally reach your Dynamic Lighting - Min Colour Temperature.
  4. In Night Light Control I selected If lights are ON, adjust the lights when crossing over. This way they will change when the time crosses over from normal light to night lights and vice versa.
Click to expand
alias: A Sensor Light - Forum
description: ""
use_blueprint:
  path: craig/new-option-sensor-light.yaml
  input:
    motion_trigger:
      - binary_sensor.flur_bewegungsmelder_bewegung
    light_switch:
      entity_id:
        - light.flur_licht_leuchte
    time_delay: 1
    include_light_control:
      - use_transition
      - use_colour_temperature
      - use_brightness
    light_transition_off: 5
    light_transition_on: 0.5
    light_colour_temperature: 3400
    include_night_lights: night_lights_enabled
    night_lights:
      entity_id:
        - light.flur_licht_leuchte
    night_time_delay: 0
    include_night_light_control:
      - use_brightness
      - use_colour_temperature
      - use_transition
      - if_lights_are_on_adjust_when_crossing_over
    night_light_colour_temperature: 1900
    night_light_brightness: 1
    night_light_transition_off: 10
    night_lights_conditions:
      - time_enabled
    night_lights_before_time: "05:30:00"
    include_light_colour_control: use_colour_temperature
    include_night_light_colour_control: use_colour_temperature
    include_dynamic_lighting: enable_time_controled_colour
    dynamic_lighting_max_colour_temp: 3400
    dynamic_lighting_min_colour_temp: 2500
    dynamic_lighting_time_start_morning: "05:30:00"
    dynamic_lighting_time_end_morning: "06:30:00"
    dynamic_lighting_time_end_evening: "23:00:00"
    dynamic_lighting_heartbeat: 5
    dynamic_lighting_time_start_evening: "19:00:00"
    night_lights_after_time: "23:00:00"
    dynamic_lighting_min_brightness: 99

Blacky :smiley:

1 Like

But then the entire automation is deactivated.
I actually meant that the light should come on when the LUX value of a sensor goes below a certain value. so use the LUX sensor as a TRIGGER.

@herbert1910

When you turn ON the toggle helper the automation will be active. It will then trigger on the lux sensor but it has to cross over.

If you are having problems could you please provide us your YAML of the automation? This YAML code are the settings you have selected in the automation so I can help. To do this go into your automation, top right 3 dots, Edit in YAML, copy all the code, come back to the forum and in your reply at the top tool bar click on “</>” and paste code in there.

Make sure you add your helper in so I can edit your YAML.

Blacky :smiley:

Blacky

New update 7.7

Your lighting experience, your way – take control and customize it to perfection! :bulb::sparkles:

:bug: Bug Fixes

  • Dynamic Lighting - A bug affecting dynamic lighting options 10, 11, 12, and 13 has been fixed. Previously, re-triggering the automation caused a loop that consumed excessive RAM and issued a critical log. This issue was caused by a single condition leading to an unintended loop. :pensive:

    The updated blueprint resolves this problem. :raised_hands: Please update your blueprint promptly to apply the fix.

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:

1 Like

@Blacky : 1.000 Thanks.

@ajd_ht

Point 1. This is up to HA and what they would like to do. Maybe they will allow this to happen.

Point 2. This Blueprint is very complex in the logic. You could have another automation to do something when the light turn ON or OFF. Adding it may just make it more confusing.

Your welcome

Blacky :smiley:

Just the option to have a follow up action would be great.

Hi @Blacky! First and foremost, a huge thank you for all the incredible effort you’ve put into creating this amazing blueprint!

I’m trying to customize the Dynamic Lighting: Time Controlled Feature for my needs. I’m using the 11 - Time Controlled - Brightness option.

I’d like the light to gradually dim from 100% to 3% over three hours, specifically between 10:00 PM and 1:00 AM.
Additionally, I want the night_time_delay to be set to 3 minutes during the night.

Here’s my YAML configuration:

alias: light test
description: ""
use_blueprint:
  path: Blackshome/sensor-light.yaml
  input:
    motion_trigger:
      - binary_sensor.ms_room_occupancy
    light_switch:
      entity_id: light.room
    time_delay: 10
    include_dynamic_lighting: enable_time_controled_brightness
    dynamic_lighting_max_brightness: 100
    dynamic_lighting_min_brightness: 3
    dynamic_lighting_time_start_evening: "22:00:00"
    dynamic_lighting_time_end_evening: "01:00:00"
    include_night_lights: night_lights_enabled
    night_lights_conditions:
      - time_enabled
    night_lights_after_time: "23:00:00"
    night_lights_before_time: "05:00:00"
    night_lights:
      entity_id: light.room
    night_time_delay: 3

Automation Results:

  1. 9:59 PM - Brightness 100% - OK
  2. 10:00 PM - Brightness 3% (expected 100%). If I change dynamic_lighting_time_end_evening to "23:59:00", the brightness is 100%.
  3. 10:30 PM - Brightness 3% (expected 83%). If I change dynamic_lighting_time_end_evening to "23:59:00", the brightness is 83%.
  4. 11:00 PM - Brightness 100% (expected 67%). The night lights mode is enabled, and Dynamic Lighting does not seem to work.
  5. 11:30 PM - Brightness 100% (expected 50%). The night lights mode is enabled, and Dynamic Lighting does not seem to work.

Questions:

  1. Based on items 2 and 3, it seems that I cannot achieve dynamic brightness adjustment across midnight (10:00 PM to 1:00 AM). Is this by design?
  2. From points 4 and 5, should Dynamic Lighting work when the night_lights mode is active?

@Vinkoy

Thank you, and your welcome.

Answers:

  1. Currently NO. I developed it to mimic the sun not to do it over a day. That said I should be able to achieve this easily but I will need time to test it live through a whole day. Keep an eye out for a new release.
  2. Dynamic lighting only works for normal lights not night lights.

Blacky :smiley:

1 Like

@Blacky , thanks so much for your quick reply and fix! I will try it once I have a bit of time and respond whether the issue was fixed for me.

Also thanks for the suggestions on the automation settings!

@Rhidus

No problem, there is another update coming with a fix if you using it over a day and a new feature so keep an eye out for it.

Blacky :smiley:

@Blacky And here comes the update: After updating the blueprint and enabling the automation, RAM usage is stable now when motion senosr is triggered (even without the toggle helper)! Thanks for your support :heart:

1 Like

Thank you for your response!

  1. Great news! I’ll keep an eye out for updates.
  2. Got it, that’s not an issue at all. I’ve solved this on my end by creating an additional automation based on your blueprint and using mutually exclusive bypasses. This way, one automation runs until 10:00 PM, and another takes over after 10:00 PM. In the second automation, I set the time delay to 3 minutes (as I wanted during the late evening hours), ensuring Dynamic Lighting works properly during the late evening and night hours.
1 Like

Thanks for this fantastic blueprint.
I’ve been playing with it and if my lights are already on, they are not triggered/adjusted to the values configured on trigger, but they are turned off at the end of the “Time Delay”. Is there a way to prevent that?

@KeKeSeB

Welcome to the community.

This is how the blueprint is designed. This allows you to make changes to your light when they are turned ON by the automation. It also helps to reduce network traffic.

If you would like it to change then you will need to create a scene or a script and input it into Lights - Switches - Scenes - Scripts and don’t use the Scenes & Scripts - Toggle Helper, leave this input empty.

Blacky :smiley:

1 Like

New update 7.8

Your lighting experience, your way – take control and customize it to perfection! :bulb::sparkles:

:new: New Feature

  • Dynamic Lighting - State Control Option
    You now have an option to enable or disable dynamic lighting based on the state of a specified entity. When the entity is in the selected activation state, dynamic lighting will function as configured. When the entity is not in the activation state, dynamic lighting will be disabled. This allows you to toggle between normal lighting and dynamic lighting based on the entity’s state.

  • Dynamic Lighting - Next Day
    With options 10, 11, 12, and 13, you can now set the time for transitioning to a new day.

:bug: Bug Fixes

  • Dynamic Lighting
    • Resolved an issue with options 10, 11, 12, and 13 that could cause excessive RAM usage and generate a critical log, depending on your settings.
    • Fixed a bug where turning OFF the bypass might not reset your lights correctly.

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:

3 Likes

Cannot save any automation. I have HA detecting presence of Aqara FP2. HA does detect presence for binary sensor binary_sensor.kitchen_occupied on the dashboards.

When I select that sensor as a trigger for this blueprint, the automation cannot be saved.
Get error: Message malformed: extra keys not allowed @ data[‘triggers’]

I chose just one entity in the subsequent dropdown. Not an area, not a device, just one light entity: light.big_kitchen_light.

kitchen_occupied is a type group in helpers with 2 entities in the group. One entity is the In Kitchen and the other is Any Area Detect. These entities show just fine on a dashboard and are working.

I do not understand why this cannot be used as a trigger.

@jrullo8

Welcome to the community.

Sorry your having troubles… You will need to update your HA if you can as I have updated the code to follow HA road map. This way you will be able to use the blueprint how HA would like it to be. Once you done that everything will work perfectly.

Blacky :smiley: