Sun Componet

I’m trying to set an automation that will trigger two lights ONLY between Sunset and Sunrise.
I’m attempting to use a condition setting the parameters to Before Sunrise and After Sunset… (Automation below is HA generated not by my hand)

My motion sensor is firing ( I can see the light flash) but my two lights do not turn on.
Now… If I set the condition to a time condition 18:00 to 06:00 it works… and if I just set the condition to just “After Sunset” it works as well…

I’m at a loss… again!

 id: '1564252116802'
  alias: 'Auto  East Patio Lights On '
  trigger:
  - entity_id: binary_sensor.ecolink_motion_detector_sensor_2
    platform: state
    to: 'on'
  condition:
 - after: sunset
    before: sunrise
    condition: sun
  action:
  - data:
      entity_id: switch.honeywell1
    service: switch.turn_on
  - data:
      entity_id: switch.honeywell3
    service: switch.turn_on
- id: '1564254684625'
  alias: Auto East Patio Lights Off
  trigger:
  - entity_id: binary_sensor.ecolink_motion_detector_sensor_2
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      entity_id: switch.honeywell3
    service: switch.turn_off
  - data:
      entity_id: switch.honeywell1
    service: switch.turn_off

again…this condition works…

condition:
  - after: sunset
  condition: sun

What am I missing

Name me a time of the day (ie a 24 hour period between midnight and the following midnight) when it is both before sunrise AND after sunset.

Use below_horizon :slight_smile:

I’m not given that option on the page…
Capture

I was using it like a Between…
If(sun >= sunset && sun <= sunrise)
{
// then do something
}
It works fine when I use just After: Sunset… which is the same as below_horizion I guess…

Only until midnight.

scroll down to the green bar graphs for a pictorial representation.

After sunset OR before sunrise would be equivalent to below horizon. However I don’t think you can do OR conditions with the GUI editor either.

Take the leap. Edit the yaml.

But… “I’m a-scared of the ymal” LOL

Like I said Ive got it working wit a single condition “After Sunset”

I’ll play around anyway… thanks

Ok as long as you are not relying on the condition between midnight and sunrise it will work.

And I will be… Hmmmm

So I’m trying this…

condition:
    condition: or  # 'when dark' condition: either after sunset or before sunrise - equivalent to a state condition on `sun.sun` of `below_horizon`
    conditions:
      - condition: sun
        after: sunset
      - condition: sun
        before: sunrise

***** EDIT ****
This seems to work

Found it here https://www.home-assistant.io/docs/scripts/conditions/

Yep. There now, that wasn’t so scary :slight_smile:

Though taking nick’s advice you could simplify it to:

condition: state
  entity_id: sun.sun
  state: 'below_horizon'

No it wasnt lol… I’m a coder by profession… but ymal and its dependency on spaces is maddening… the statement below is a VERY klutzy or statement… logical when you look at it but just doesn’t roll off the fingers…

I’ll try the other method just for completeness in the experiment that is HA!

Thanks for the support and advice folks… the struggle is real … lol

condition:
    condition: or  # 'when dark' condition: either after sunset or before sunrise - equivalent to a state condition on `sun.sun` of `below_horizon`
    conditions:
      - condition: sun
        after: sunset
      - condition: sun
        before: sunrise