Looking for some help with an automation

Based on some help I received months ago, I have set up the following automation (simplified) and it works as expected – the light turns on at the later of 6:45 pm or sunset:

  trigger:
  - platform: time
    at: '18:45:00'
  - platform: sun
    event: sunset
    offset: 0
  condition:
  - condition: time
    after: '18:45:00'
  - condition: sun
    after: sunset

The only ‘problem’ is that on certain days, like when it is raining, the kitchen is darker than typical and we would like the light to come after 6:45 pm and before sunset if the room is too dark. Based on more help received here, I put together the following automation, which works just fine, which turns on a switch after 6:45 pm if it gets too dark:

  trigger:
  - platform: state
    entity_id:
    - sensor.light_level
  condition:
  - condition: numeric_state
    entity_id: sensor.light_level
    below: '10'
  - condition: time
    after: '18:45:00'

Where I am stuck is trying to combine these. Using the second one as the starting point, I added sunset to both the trigger and condition,

  trigger:
  - platform: state
    entity_id:
    - sensor.light_level
  - platform: sun
    event: sunset
    offset: 0
  condition:
  - condition: numeric_state
    entity_id: sensor.light_level
    below: '10'
  - condition: time
    after: '18:45:00'
  - condition: sun
    after: sunset

but this will not work as intended because the conditions will not all be true until after sunset. If the conditions could be grouped, in other words if the condition: numeric_state and the condition: time could be AND’ed together and the result of the AND then OR’ed with the condition: sun, that should work. Can you please offer some suggestions.

If the light level is what you really care about, then it doesn’t seem like the “sunset” trigger or condition is that helpful. I suggest getting rid of all the sunset-related parts and using this:

  trigger:
  - platform: state
    entity_id: sensor.light_level
  condition:
  - condition: numeric_state
    entity_id: sensor.light_level
    below: '10'
  - condition: time
    after: '18:45:00'

I would also suggest that the time isn’t really that important, and you should just focus on the light level:

  trigger:
  - platform: numeric_state
    entity_id: sensor.light_level
    below: 10

Another option is to use sun elevation instead, which indicates a constant light level year-round (but doesn’t take weather/clouds into account).

  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 2.0

There are other options, but I would start by deciding what you really care about (sunset, light level in the room, time) and not worry about the others.

Is your light sensor indoors or outdoors? The problem with indoor light sensors, is that when you manually switch a light off… you may trigger the automation again so you will have to take that into account when designing your automation. i.e, you only want this automation to run once per day.

Thanks for the reply, but if you read my post, you will see that I care about the time, sunset, and illumination - cannot get rid of any of them.

Thanks for the comment, but that light is almost never turned off manually.

What keeps you from doing so? :slight_smile: You can nest and combine conditions as you like, see here:

Not that I’d recommend that, I’m quite sure there is a better way (which I don’t know), but if that’s the route you’d like to try, nest and combine them. :slight_smile:

Thanks for pointing out conditions - worked just as expected!