šŸ”† Smart Light - Entity - Sun Elevation - Ambient & Time Triggers

Ain’t gonna work in my situation: I also have some guests triggers and time based templates so the lights should work in some time windows when i’m not at home.

So i need to built a entire new automation to toggle a helper and include that in you’re automation.

I’m guessing that i i’m using the ā€œTake controlā€ option in HA and add a template section is the only solution in my case…

I’m talking about making the automation trigger when the Light Entity changes (not Sun/time triggers) - basically a ā€˜Manual Override’

My goal is smart automation that respects manual control while enforcing rules (sun elevation, time, ambient light, motion, etc).

Manual trigger integration would work like this:

When the target light is changed (on/off/dim) the automation does a condition check (sun elevation, time, ambient light, etc).

Manual Override Time (aka MOT)
→ If the blueprint triggered the light change (motion, sun elevation, time, etc) then an internal flag (MOT) is set based on a user defined time frame (say 3 mins) when the blueprint assumes the light change was not manual.

Logic…

If inside MOT then do nothing / exit automation (skip below 1 & 2)

If outside the MOT, then…

  1. If ANY blueprint conditions are met
    → target light level adjusts to brightness in user defined settings (thus is is night time and will adjust to 10%)
  2. If NO night conditions are met
    → target light is set to Off after user defined timeout (thus is not ā€˜night’ and the lights should be off)

@EvertJob

I wouldn’t use the take control, but it totally up to you. You now have more conditions than your last post. I would just resolve them and keep the blueprint intact.

Blacky :grinning:

@Ltek

Have you looked at :stop_button: Manual Control Status Tracker blueprint. I think this will do your MOT. There are some limitations though. Then I think you use bypass option 3.

Blacky :grinning:

thanks Blacky, you rock. Nothing exists that does Time, Lux, Motion, and Sun Elevation all together so I wrote one that does :slight_smile:

Hi Blacky. Last few days the automation runs but nothing happens. Cannot figure out why it randomly does this. Some nights the automation works fine (barring zwave being stupid for a light or two), other nights absolutely nothing happens. Last two or three nights, nothing has happened at all even though the automation has ran.

alias: Night Lights
description: ""
use_blueprint:
  path: Blackshome/smart-light.yaml
  input:
    include_sun:
      - sun_rising
      - sun_falling
    light_switch:
      entity_id:
        - scene.stair_lights
        - scene.night_lights_all_night
    sun_elevation: 3
    sun_elevation_rising: -2
    include_ambient: []
    boolean_scenes_scripts: input_boolean.night_lights_toggle
    include_light_control: []
    include_night_lights: night_lights_disabled
    night_lights_conditions: []
    night_lights_entity_state: []
    include_bypass:
      - bypass_enabled_turn_on
      - bypass_enabled_turn_off
    ambient_light_value: 400
    end_scenes:
      - scene.step_lights_off
      - scene.night_lights_all_night_off
    bypass_lights_on:
      - input_boolean.night_lights_override_on
    bypass_lights_off:
      - input_boolean.night_lights_override_off
    ambient_light_value_off: 600
    include_entity_state:
      - entity_on
    entity_input: input_boolean.it_s_dark_out
    include_ha_restart: enable_ha_restart
    include_bypass_auto_off:
      - bypass_auto_off_enabled_on
      - bypass_auto_off_enabled_off
    bypass_auto_off_delay: 1
    include_button:
      - button_on
    button_input: input_button.activate_night_lights

I do have this automation activating another automation that controls lights that turn on at the same time but the second automation turns just those lights off at 3am.

alias: Night Lights (Off at 3AM)
description: ""
use_blueprint:
  path: Blackshome/smart-light.yaml
  input:
    light_switch:
      entity_id:
        - switch.couch_small_lamp
        - switch.foyer_lamp_outlet
        - switch.great_room_lamps_outlet
        - scene.night_lights_off_at_3am
    boolean_scenes_scripts: input_boolean.night_lights_toggle_off_at_3am
    end_scenes:
      - scene.night_lights_off_at_3am_off
    include_ambient: []
    ambient_light_value: 1000
    include_sun: []
    sun_elevation: -5.5
    sun_elevation_rising: -5
    include_time:
      - time_off
    before_time: "03:00:00"
    include_entity_state:
      - entity_on
    entity_input: input_boolean.night_lights_toggle
    include_ha_restart: enable_ha_restart
    include_bypass: []
    bypass_lights_on: []
    bypass_lights_off: []
    include_bypass_auto_off: []
    bypass_auto_off_delay: 1
    include_button:
      - button_on
    button_input: input_button.activate_night_lights_off_at_3am

@networkcrasher

Just keep an eye on your input_boolean.night_lights_toggle. Scenes can be tricky but it may be that this is ON when your lights are OFF.

Blacky :grinning:

does the automation not reset this toggle on its own every morning when an OFF situation occurs? It’s a helper toggle so the only thing that uses it is this automation. I just noticed it’s still on and the lights should all be off (but there are some lights that are still on which is also a battle I face with this automation). As far as I can tell the zwave mesh is healthy but it’s been a battle to deal with zwave so much that I am likely not going to use it again at my next home. Just too invested in it in this house so far.

@networkcrasher

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.

Blacky :grinning:

Hi,

I wonder if I could get some help.

I have an LED strip at the back of the TV, I want to control the brightness of them when the TV is On / Off.

I’ve tried to setup the automation as follows, but it doesn’t seem to be working.

The TV uses the following state ID: [media_player.lounge_oled_tv]
From what I can see, it has 4 states, on, playing, off, unavailable

on - When the TV is initially turned on
playing - Changes to this state is something is being watched
off - when the TV is turned off
unavailable - Changes to this state shortly after being turned off

I created 2 Binary Sensors,

binary_sensor.lounge_tv_on
{{ is_state(ā€˜media_player.lounge_oled_tv’, ā€˜on’) }}

and

binary_sensor.lounge_tv_off
{{ is_state(ā€˜media_player.lounge_oled_tv’, ā€˜unavailable’) }}

NOTE: I dont know how to code OR commands to include the other 2 states.

I then created 2 automations, with the helpers as triggers

TV On - Automation
Set LED Strip brightness to 5%

TV Off - Automation
Set LED Strip brightness to 100%

Hi, isn’t that what I pasted above?

Suggested documentation improvement for the smart-light blueprint
I ran into some confusing behavior with the time settings and wanted to suggest a small clarification that might help other users.
When the option time_on is included in include_time, the blueprint switches into its advanced time mode. In this mode, the value of time_on becomes the only ON-time the blueprint uses. The value of after_time is not used for turning the light on.
If time_on is enabled but not set, the blueprint falls back to a sunrise-based default, which can cause unexpected early turn-ons.
Here is a suggested note that could be added to the documentation:

If you include time_on in include_time, the blueprint uses time_on as the ON time and ignores after_time for turning the light on. To use after_time as the ON time, remove time_on from include_time or explicitly set time_on to the desired time.

This would make the behavior much clearer for new users. Thanks for the great blueprint.

@rustyh

Lets try and just use one automation so there are no conflicts.

Create one binary sensor with this code.

{{ states('media_player.lounge_oled_tv') in ['on', 'playing'] }}

Now when it is ON or playing the binary sensor will be ON. When it is not in these states it will be OFF.

Then in the Use The Entity State Option select ON State and OFF State. Set up your lights to your liking and enjoy.

One automation is all you need.

Blacky :grinning:

@networkcrasher

Sorry my bad.

No the automation only controls the lights not the triggers. In your case the input_boolean.night_lights_toggle. You have a scene that you turn ON. The Scenes & Scripts - Toggle Helper input_boolean.night_lights_toggle_off_at_3am will be turned OFF. In your scene.night_lights_off_at_3am_off in Scenes - Scripts To Turn OFF add your input_boolean.night_lights_toggle to OFF. Then when your scene lights turn OFF it will also turn OFF the toggle helper for you.

Because you going across a day… if you restart your HA in a small time window after 12am your lights may turn back ON… it very hard to get this right in the code because there are so many options. I added HA Restart so if you find this happening your can disable this option.

Blacky :grinning:

@stratrider

I don’t explain the code inputs I try to explain the UI inputs. In the UI inputs if you select ON Time that is the time that will turn the lights ON. If you select OFF Time this is the time the lights will turn OFF. It is the same for all the inputs and you can select to turn the lights ON with the Sun Elevation Falling - ON and then turn them OFF with the OFF Time. You can mix and match to your liking.

What your saying is incorrect. I do find it hard to get all the inputs descriptions right…

Blacky :grinning:

Hi,

How to add a condition to this automation (via UI)?

Reason:
I use the low lux trigger with the idea that the lights turn on in the evening. BUT somehow my lux sensor (shelly blu motion) goes from 135 to 125 in the morning while my limit is at 130. The mean is inclining however.
My idea was to only allow this value starting from 15:00 to 20:00 (dusk).

Thank Blacky,

Only issue I see if i don’t think you can set different brightness levels can you for each binary sensor state?

Hi Blacky,
Thank you very much for this Blueprint.
I am trying to get it working but so far with no luck. I just want by few lights to be turned on and off depends on Lux values available from couple of sensors and then if possible adjust color temperature based on Sun position along with brightness controlled based on Lux value.
Please find below .yaml.
@Blacky Thank you in advance.

alias: Bedroom-Test
description: ""
use_blueprint:
  path: Blackshome/smart-light.yaml
  input:
    include_sun: []
    include_ambient:
      - ambient_low
      - ambient_high
    ambient_light_sensor: sensor.bathroom_illuminance
    include_time:
      - time_off
      - time_on
    after_time: "09:00:00"
    before_time: "19:30:00"
    light_switch:
      entity_id:
        - light.bedroom
        - light.wiz_rgbw_tunable_ead15e
    include_light_control:
      - use_transition
    light_transition_on: 5
    light_transition_off: 5
    include_light_colour_control: use_colour_temperature
    light_colour_temperature: 3900
    light_rgb_colour:
      - 250
      - 246
      - 235
    include_dynamic_lighting: enable_sun_elevation_colour_lux_brightness
    dynamic_lighting_lux_sensor: sensor.bathroom_illuminance
    dynamic_lighting_max_lux: 230
    dynamic_lighting_min_colour_temp: 2500
    dynamic_lighting_state_control_entity: sun.sun
    include_entity_state: []
    boolean_scenes_scripts: input_boolean.bedroom_off
    ambient_light_value: 60

@Corvus71

You would only like this to work between 15:00 to 20:00 and only when the lux is below 130.

Try using my :bulb: Sensor Light blueprint. Then create a time of day helper or a schedule helper. Then use this helper as the trigger. Then set up the ambient and your lights. It will all work.

Blacky :grinning:

@rustyh

You could set 2 different brightness by using the night lights. If you can give me the states you would like to the brightness.

Example

Playing = 5%
ON = 5%
OFF = 100%
Unavailable = 100%

Blacky :grinning: