Automation using UI for condition "DARK OUTSIDE not time"

Hi All

So I have read up on the sunset and here I got the its DARK…

condition:
 - condition: state
   entity_id: sun.sun
   state: below_horizon
   for:
     hours: 0
     minutes: 0
     seconds: 0

But I would like to only have the light go on when its really DARK!
So I was hoping to delay it for 1-2 hours after sunset
I think below horizon in the morning is okay?

So is this possible using the UI? or id the correct way to include a offset like this?

condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
    offset: '+01:00:00'
    for:
      hours: 0
      minutes: 0
      seconds: 0

I started out thinking this would be easy :slight_smile: but it god a bit more complicated

Currently I have one automation for ON and another for OFF

Ok that didn’t work either…

Why not use the sun elevation?

2 Likes

which, I believe can be done from the automation editor gui.

entity_id: sun.sun
attribute: elevation
below: '-10'

I’ve been using sun elevation for a while and it works flawlessly for me.

So how to translate this into 1 hour or 1,5 hours?
I you using some calculator? - not exactly as easy as defining a offset after sunset
But again I like using the UI so I will try to use the elevation instead (Rock solid is the key word here! LOL)

I dont remember exactly what I did here, it’s been so long, but in short:

  • Set the right timezone and elevation setting in config/core (you’ll have to figure out how to get your exact elevation )
  • Figure out at the trip point. In my case, I use a template {{ state_attr('sun.sun','elevation') < -2.5 }} The -2.5 value here is my trip point. I want my lights on shortly after the sun sets, but not too early.

I do remember running some sensors before I settled on 2.5 to see where the sun was at which time of the day after sunset. Can probably be calculated more elegantly, but this is how it worked for me.

Why? With the elevation you’re going to get consistent light levels across the year after all.

1 Like

Yes but you would get that anyway if using the sun goes down wouldn’t you?

I think I have found a way to just adjust the time before and after the sun goes down…
Not verified will have to test this tonight :slight_smile: should produce the same results as elevation

  condition:
    conditions:
      #Condition beginning 60 min after sunset (and including after sunset): https://home-assistant.io/docs/scripts/conditions/#sun-condition
      - condition: sun
        after: sunset
        after_offset: "+1:00:00"
      #Condition ending 30 min after sunrise (and including before sunrise)
      - condition: sun
        before: sunrise
        before_offset: "-0:30:00"

Found from this Post

And Yes using the UI it would look like this

Tonight, maybe. The problem is that as the months go by it’ll give you different results…

@Tinkerer Sorry I don’t understand your comment I want this to change my condition is that’s it dark outside and that will change from month to month? (Or am I missing something :slight_smile: )

Or maybe just bite the bullet and buy a LUX sensor…(Would still need to define the range, if it was cloudy during the day though)

A practical little thing.

Naturally you can base light automations on the sun. But in practical life, two days where one is a blue sky day and the next is a rainy day with heavy cloud cover will be two very different things when it comes to daylight. It easily makes a difference of more than an hour.

I recommend also using a light sensor. For example an Aeotec multisensor, or an Philips Hue motion sensor which also has a light sensor.

I use the same Philips outdoor motion sensor to turn on the outdoor patio light when it is dark and there is motion and same light sensor is used to turn on the light inside when it gets dark.

I have tried using just the sun but unless you live in a desert where it never rains, there is just too much variation from day to day based on cloud cover.

Lux sensor is the best, but the problem of using a time offset is that half an hour before/after sunset or sunrise is a very different light level on the shortest day than on the longest day.

However, -3 degrees is (ignoring cloud cover) pretty consistent across the year.

1 Like