🔆 Smart Light - Entity - Sun Elevation - Ambient & Time Triggers

I hope this works. Sorry for the extra puzzle.

I’m keeping it simple for now before adding more complex things. Thanks again.

alias: Lighting Control Public Area
description: ""
use_blueprint:
  path: Blackshome/smart-light.yaml
  input:
    include_sun:
      - sun_falling
      - sun_rising
    sun_elevation: 4.5
    sun_elevation_rising: 5
    light_switch:
      entity_id: switch.sonoff_10024347ea
    night_lights_sun_elevation: 2
    night_lights_sun_elevation_rising: 3
    include_night_lights: night_lights_enabled
    night_lights_conditions:
      - sun_enabled
    night_lights:
      entity_id: switch.sonoff_100218af02_1
    include_night_light_control:
      - if_lights_are_on_adjust_when_crossing_over

That’s ultimately the issue. I have a list of lights I want to just switch on (either switches or lights) to 100%, some at 50%, some at 25%. I don’t need them to change brightness, but some lights I just want to come on at a predetermined level, hence the scene. The scene has each light that requires a specific intensity set to that intensity in that scene.

Ah, it wasn’t apparent to me that BOTH had to be true. I just set the 21:00 time because a start time was required. All I really cared about was the 3am time. So I guess I just set the on time to 17:00 or something super early, and then control them coming on with the toggle that gets activated by the normal lights routine?

The point here is that sometimes if it’s really cloudy or overcast it’s “dark” inside the house before it’s actually sunset (or whatever I have the sun elevation set to anyway), so I figured I have an illuminance sensor, might as well incorporate it? 500lux seems reasonably light but I will fine tune it yes.

Is there a way to just use a scene for either or both? I don’t believe I have any 3am off entities that don’t require dimming, and I definitely have some that run all night that require dimming, too. I don’t believe there’s a way to set intensity per device within the automation, right? they all have to be the same level?
Thanks Blacky. Really cool blueprint, just have to figure out how to use it. Is there any way i can test it each time I make a change or do I just have to wait until the conditions are right?

@erwinsidik

Not a problem at all, happy to help.

I have tested this using your settings and I can’t fault it. I will explain what will happen so we are on the same page.

  1. When the sun drops from above 4.5 to below 4.5 but not below 2 (night lights setting) this switch will turn ON switch.sonoff_10024347ea.
  2. We the sun drops below 2 then switch.sonoff_10024347ea will turn OFF and switch.sonoff_100218af02_1 will turn ON.
  3. When the sun rises above 3 but stays below 5 then switch.sonoff_100218af02_1 will turn OFF and switch.sonoff_10024347ea will turn ON.
  4. When the sun rises above 5 then switch.sonoff_10024347ea will turn OFF.

Your sun elevations are very close to one another 4.5 - 2 and 3 - 5.

Is this what your finding?

Blacky :grinning:

Aha. I think my logic might have been faulty. I will play with it according to your guidance when I get home. On vacation right now. It could be I set you on a wild goose chase due to my ignorance of the logic behind the blueprint. If so, I apologize in advance. Anyway I will report to you next week whether I need to put my dunce cap on or not. Many many thanks for your patience.

Sincerely yours,
Erwin

1 Like

Thank you very much for the blueprint! It’s truly the best I’ve seen so far. I do have one question: Why does the light turn off upon restart, even though it should be within the correct time frame? Is there a setting to adjust this? (Last Status)

Hi Blacky
So I took your advice and separated these into 2 automations. What i’m finding now is that in the morning when the sun’s coming up, the lights go off, but then the illuminance sensor turns them on about 40 min later? that’s what I didn’t realize was happening as to why I’d wake up and the lights were on. I don’t get why it would turn them on if the sun was already up? I don’t ambient turn off, just ambient turn on, but if the sun isn’t falling, then how could it evaluate both to true to turn on the lights?

alias: Night Lights
description: ""
use_blueprint:
  path: Blackshome/smart-light.yaml
  input:
    include_sun:
      - sun_rising
      - sun_falling
    light_switch:
      entity_id:
        - switch.kitchen_pantry_door_outlet
        - light.garage_door_carriage_lights
        - switch.front_driveway_flood_light
        - switch.rear_patio_flood_light
        - light.brick_patio_wall
        - light.brick_patio_flood
        - scene.stair_lights
        - switch.basement_front_patio_light
        - switch.laura_beauty_bench_plug_2
        - light.foyer_turkish_lamp
    sun_elevation: -5
    sun_elevation_rising: -5.5
    include_ambient:
      - ambient_low
    boolean_scenes_scripts: input_boolean.standard_night_lights
    include_light_control: []
    include_night_lights: night_lights_disabled
    night_lights_conditions: []
    night_lights_entity_state: []
    include_bypass: []
    ambient_light_sensor: sensor.tempest_weather_illuminance
    ambient_light_value: 1000
    end_scenes:
      - scene.step_lights_off

@cateyes

Welcome to the community.

This is a bit tricky in this blueprint… and I am trying to resolve this.

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.

This way I can better pinpoint what is happening and can you note when you restart it in time.

Blacky :grinning:

@networkcrasher

This is because they are triggers and not conditions.

So

What’s happening is your light is turning ON when the lux level drops below 1000 lux… you recently increased it from 500 lux. A lower threshold might be more appropriate. At 1000 lux, even a small dip to 900 lux can trigger the light, but depending on the conditions, the level may never drop as low as 500 lux.

To fine-tune this:

  • I’ve noticed your sun elevation settings for the “falling” trigger are set quite low. Take a look at this FAQ click here for guidance on how to configure them more effectively.

    Also, try observing your sun elevation and lux sensor together one evening. With your current settings, there’s a significant gap between the two, which may indicate you don’t need both triggers. In fact, if the sun trigger alone gives you the behavior you want, you might consider removing the ambient (lux) condition altogether… that could simplify things and resolve the issue.

  • I noticed you’re using round numbers like 500 or 1000. Instead, observe your lux sensor over a few evenings and take note of the lux level when lighting actually feels needed. That value will help you set a more accurate Low Lux Value - ON. You might find the ideal level is even lower than 500 lux… but only you can decide what feels right in your space.

  • Then, consider enabling the High Lux Value - OFF option and setting it to about 100–200 lux above your ON threshold. This creates a buffer (hysteresis) that helps prevent the light from toggling ON and OFF due to temporary fluctuations like storms or heavy cloud cover.

Let us know if this works for you.

Blacky :grinning:

Hey @Blacky,

First of all, thanks for your great work—your automation setup works really well throughout my entire house!

However, I’m running into some trouble integrating it into my living room setup. The issue revolves around the manual wall switch (Philips Hue Wall Switch), which is also used to control the lights when the automation doesn’t kick in.

The Problem

I want to integrate the wall switch into your automation, but I’m facing a few challenges:

  • Bypass mode: When I use the wall switch as a bypass, it disables the automation entirely until I manually turn the switch off again. I’d prefer not to have to manually reset the switch every time.
    • Example: If I turn on the lights manually during the day and forget to switch them off before bed, the automation won’t resume until I manually deactivate the override.
    • I don’t want to implement the auto turn-off feature since that behaviour is not what I’m looking for.
  • Entity toggle: This could work, but it causes a logic mismatch. If the wall switch turns the lights on and the automation (based on sun elevation) turns them off, the entity stays in the on state. This leads to a situation where the next wall switch press doesn’t do anything—because HA thinks the lights are still on.

My Current Idea

I’m considering writing a turn-off script that resets the wall switch toggle back to off whenever the lights turn off (either by automation or manually). That would keep the logic flowing properly.

However, this would also double-trigger the automation:

  • Once when the light is turned off by automation.
  • Again when the script forces the wall entity back to off .

Do you think the turn-off script is a good solution? Or is there a better way to approach this use case within your automation framework?

Would love to hear your thoughts! :blush:
– Remco

@remcoenden

Is your manual wall switch (Philips Hue Wall Switch) a switch? If so what happens if you add that switch to Lights only?

Blacky :grinning:

Hey Blacky,

The wall swtich isn’t operating like an actual switch in Home Assistant. Whenever I toggle my physical–actual–wall swtich, the Hue Wall Swtich will generate a generic event in Home Assistant. The event doesn’t include any information about the state of the physical switch, but that something has happend. This means that I can’t directly interface this switch with any light entity to simply turn it on or off.
A work around for this behaviour would be to create a template binairy sensor which toggles the state of the sensor any time the Hue Wall Switch reports an event.

I hope this clears things up a tiny bit.

  • Remco

@remcoenden

What entity is this? Can we wright a script that says if this entity is ON then turn OFF? Then use this script in the Scenes - Scripts To Turn OFF

Or

Can we wright a script that toggles your wall switch and fires the event to turn your light ON if “the entity” is OFF (used in Lights - Switches - Scenes - Scripts) and then another script to fire it to turn you light OFF if “the entity” is ON (used in Scenes - Scripts To Turn OFF)?

There is a way just need to find what works for you.

Blacky :grinning:

Thank you for the incredible work. I’m successfully using it across a series of rooms. One use case I’m trying to implement involves using the bypasses when I arm my alarm every night. I want to set the living room lights to red. I successfully set up the bypass with the current state and enabled the lights.

However, I’m encountering an issue: when I disarm the alarm, the blueprint recognizes that the boolean value has changed to false, updates the color, and the lights stay on. I would prefer to have the lights turned off instead.

So my question is: Am I configuring this incorrectly, or is there an underlying condition or assumption that the lights should stay on? I’ve included my YAML for the blueprint below.

alias: "Familyroom: Lights"
description: ""
use_blueprint:
  path: Blackshome/smart-light.yaml
  input:
    include_sun:
      - sun_falling
      - sun_rising
    sun_elevation: 5
    sun_elevation_rising: 5
    light_switch:
      entity_id:
        - light.multi_color_bulb_2
        - light.multi_color_bulb_6
    include_light_control:
      - use_brightness
    light_brightness: 70
    include_time:
      - time_off
    include_bypass:
      - bypass_enabled_stop
    bypass_lights_stop:
      - input_boolean.alarm_mode

@cdr67

Hi Robey, and welcome to the community.

Your welcome.

This could be that your sun elevation is within the falling and rising set points when you turn the alarm OFF. I also noticed you have a time turn OFF. Not sure if this is what your after.

Try adding your input_boolean.alarm_mode to the Trigger - Entity State and use the OFF State. Now when you turn alarm OFF the light should go OFF.

PS: You could also use nightlights and change the colour to red when you turn ON your alarm and not use the bypass. Here is an example. Copy paste it in but make a copy of your YAML settings before so you can revert back to your original settings if needed.

alias: "Familyroom: Lights"
description: ""
use_blueprint:
  path: Blackshome/smart-light.yaml
  input:
    include_sun:
      - sun_falling
      - sun_rising
    sun_elevation: 5
    sun_elevation_rising: 5
    light_switch:
      entity_id:
        - light.multi_color_bulb_2
        - light.multi_color_bulb_6
    include_light_control:
      - use_brightness
    light_brightness: 70
    include_time: []
    include_bypass: []
    bypass_lights_stop:
      - input_boolean.alarm_mode
    include_night_lights: night_lights_enabled
    night_lights_conditions:
      - entity_state_enabled
    night_lights_entity_state:
      - input_boolean.alarm_mode
    night_lights:
      entity_id:
        - light.multi_color_bulb_2
        - light.multi_color_bulb_6
    include_night_light_control:
      - if_lights_are_on_adjust_when_crossing_over
      - use_brightness
      - use_transition
    night_light_brightness: 70
    include_night_light_colour_control: use_rgb_colour
    night_light_rgb_colour:
      - 255
      - 0
      - 0
    include_entity_state:
      - entity_off
    entity_input: input_boolean.alarm_mode
    night_light_transition_on: 3
    include_light_colour_control: use_rgb_colour

Blacky :grinning:

Hey @Blacky ,

Thanks for the guidance. I migrated to the night lights, which tightened up the number of automations.

@Blacky

Question for you. Have you used your blueprint with Caseta switches. The api used by for access doesn’t allow setting an initial brightness. Are you aware of any strategies to integrate Caseta into the blueprint?

@cdr67

No problem, I thought that may help you for what you said along with your YAML.

I am a Shelly man so most of my stuff is this. I do have a question though. Is your Caseta switch a “switch” in HA? To check this look at the entity ID. Example; this is one of your lights, light.multi_color_bulb_2 you can see it is a light… If your Caseta is a switch that then turns ON a light (light bulb) when you turn ON a switch in HA you don’t send the same data you would to a light. Hope this makes sense.

Blacky :grinning:

It’s a dimmer and the most reliable device I have found. It uses a low RF frequency (900 MHz) and a controller with an API for management. I’m in a densely populated area, and 2.4 GHz is problematic for IOT. I manage Zwave/Zigbee devices successfully, but I must re-interview occasionally.

When you manually press on without any automation, the lights crank up to 100% (The one poor characteristic, IMHO). A direct light_on call to the switch entity will update brightness and appear like it was set from the beginning. Unfortunately, light groups will NOT set the brightness on the initial press and must be the direct entity.

My developed code is less flexible than your blueprint. I purposely execute a light_on call when an entity trigger occurs. I just tested the SMART light blueprint and it doesn’t. I’m assuming your code is more efficient than mine.

@cdr67

:thinking: Maybe if you go into the entity settings of the switch and then change the Show as from switch to light. I think it will create a new entity and you may also need to change the entity in the blueprint to the new light one. The entity ID will go from switch.XYZ to light.XYZ. You need to select the light one.

Note: I not 100% sure if this will work so maybe do a backup of your HA first and if it doesn’t work you can go back.

Blacky :grinning:

Unfortunately, the device integration automates the switch => light helper for those searching for a tolerable workaround.

The Caseta switches support “trim” function, allowing you to adjust the high and low brightness. I have used @Blacky’s blueprint and mirrored the trim brightness against the min and max in the circadian feature. This prevents the lights from blinding you, but it still must scale down to the setting for the appropriate time.