Problem with sun component

Hi I have several automated lights with pir senses with the condition after and before sunset, which initially works fine until after 12 o’clock midnight it stops working , no longer triggering the light to turn on. Is it an internal problem or a configuration problem need some help please thanks

- alias: BedRoom1 Motion turn on lamp
  initial_state: True
  trigger:
    - platform: state
      entity_id: binary_sensor.BedRoom1_motion
      from: 'off'
      to: 'on'
  condition:
    condition: and
    conditions:
    - condition: sun
      after: sunset
    - condition: state
      entity_id: light.BedRoom1_light
      state: 'off'
  action:
      service: light.turn_on
      entity_id: light.BedRoom1_light

I think what happens is midnight “resets” the clock. Now according to HA its before sunset.

You probably want to use below_horizon instead. I believe that should survive the switch at midnight.

1 Like

cinderella sensors?

Ohhh I did not know this … is this confirmed? That may have affected many of mine automation.

WHich is the command, also after???

condition:
  - condition: sun
    after: below_horizon

Midnight starts a new day so technically sunset for that day hasn’t happened yet. Below is how you would use below_horizon as a condition.

(formatting might need adjusted)

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

Yes, I realize that you are right formally, just wondering if it really works so the component.

Nevertheless I changed to below_horizon some automations

Ahh gotcha. Yeah just theory on my part. Someone with a little more insight to the component will have to answer that.

Thanks guys for your suggestions are tried a couple of them now I suppose you could also use Date and time of the next dawn.

Everybody’s experience is that midnight is a reset, so before sunset covers from midnight to sunset, and after sunset covers from sunset to midnight.

You can of course instead simply check for an elevation of below zero, via a template:

- condition: numeric_state
  entity_id: sun.sun
  value_template: '{{ state.attributes.elevation }}'
  below: 0

That will then always apply between sunset and sunrise.

what is this?

is this different from below_horizon??

Not at zero, but I personally use -5, which is just before civil dusk/dawn. Under “normal” conditions, that’s about right (for me) in terms of lack of light.

1 Like

so you use like this, because below zero would meano 0 and not -5, correct?

- condition: numeric_state
  entity_id: sun.sun
  value_template: '{{ state.attributes.elevation }}'
  below: -5

I still wish I can manage with a light sensor (for those gray days), but still no luck with the right sensor

That’s exactly how I use it.

As for outdoor light sensors, the Aeon labs ones can be used outdoors, if suitably sheltered.

The sunset trigger have stoped working for me to suddently, did it help to use below_horizon instead?

below_horizon works fine.