Another sun related automation not working

Hi all, I have this automation set to run within 3 hours of sunset if the light gets too low due to cloud/rain, but it doesn’t seem to work at all. Why am I having so many issues with the sun condition??

- alias: Cloudy Light On
  initial_state: 'on'
  trigger:
    platform: numeric_state
    entity_id: sensor.illumination_7811dcb06eb9
    below: "350.0"
  condition: 
    condition: and
    conditions:
      - condition: state
        entity_id: input_select.occupancy
        state: 'Home'
      - condition: state
        entity_id: light.living
        state: 'off'
      - condition: sun
        before: sunset
        before_offset: "-03:00:00"
      - condition: or
        conditions:
          - condition: state
            entity_id: sensor.cloud_cover
            state: "Cloudy"
          - condition: state
            entity_id: sensor.cloud_cover
            state: "Mostly Cloudy"
          - condition: state
            entity_id: sensor.cloud_cover
            state: "Partly Cloudy"
  action:
    - service: homeassistant.turn_on
      entity_id: script.cloudy

Anyone see where I’m failing?

My understanding of your configuration is that your sun condition evaluates to true before sunset only, and more specifically until 3 hours before sunset.
Example: Let’s say sunset at your location is at 6pm, then this condition is true during the day until 3pm.
If you want the condition to be true from three hours before sunset until after dark, you need to go with after: sunset and after_offset: “-03:00:00”.

Ahhh… Interesting, I’ll try that.

I am curious to know what your script.cloudy does… could it be possible to share?
I am trying to do the same as you regarding cloudy days and lights…

Nothing too special, just turns on one of the central lights on until my usual sunset automation runs.

cloudy:
  alias: 'Cloudy On'
  sequence:
    - service: light.turn_on
      data: 
        entity_id: light.bar
        brightness_pct: '100'
        transition: '3'
    - service: homeassistant.turn_off
      entity_id: automation.cloudy_light_on
    - service: notify.ios_iphone
      data:
        title: 'Lights - Cloudy'
        message: 'Living ON'

My sunset script is the one that is more important:

sunset:
  alias: 'Sunset On'
  sequence:
    - service: light.turn_on
      data: 
        entity_id: light.living
        kelvin: '3200'
        brightness_pct: '100'
        transition: '3'
    - service: light.lifx_set_state
      data: 
        entity_id: light.bar
        kelvin: '3200'
        transition: '3'
    - service: homeassistant.turn_on
      entity_id: 
        - automation.back_at_night
        - group.medialights
        - automation.night_mode_on
        - automation.away_at_night
    - service: homeassistant.turn_off
      entity_id: 
        - automation.sunset_light_on
        - automation.cloudy_light_on
    - service: notify.ios_iphone
      data:
        title: 'Lights - Sunset'
        message: 'Living ON'
    - delay: '00:00:05'
    - service: light.turn_off
      data:
        entity_id: light.bar
        transition: '60'

Basically the sunset takes over from my cloudy script, and turns off the light over 60 seconds that gets turned on in cloudy script.

1 Like

Thanks, very interesting… i’ll try to make one similar for my purposes…

you need to specify a range, using @exxamalte’s after, will only account for after the sunset -3 hours. From what you are saying, you want it between 3 hours before sunset and sunset. You don’t want this firing after sunset do you? Anyways, you just need to add another condition on top of @exxamalte if you want that functionality. And if I miss understood your intentions, ignore this whole comment.

  - condition: sun
    after: sunset
    after_offset: "-03:00:00"
  - condition: sun
    before: sunset
    before_offset: "+00:30:00"

I added a little padding.

Thanks for that, but the automation is switched off at sunset by another automation so that does the trick.

1 Like