Help with new automation

Hello! Looking for some help with a new automation idea:

We need to open our back door to let our dog out. In the summer, if the back porch light is on, it attracts millions of bugs that come into the house every time the door is opened… Once the weather turns colder, that doesn’t happen. I want to vary the time the back porch light comes on based on temp and sunset.

Sunset +01:00:00 offset (this will typically be between 4pm and 8pm where I live)
Outdoor temp >= 50f
Turn on back porch light at 11pm
Turn on the back port light immediately

The line I highlighted is the part I’m not sure how to automate. I can do all of the rest but I’m not sure how to do the highlighted action other than to create an automation that’s disabled, then use code to enable/run it.


I would use an IF/Else statemen in the action I have a couple of these…

These can be found in the building blocks section now, they are a very powerful tool.

I use if/else already… but how do you “schedule” an activity at a future time from within that construct?

Can you clarify why a Time trigger won’t work?

  - platform: sun
    event: sunset
    offset: "01:00:00"
  - platform: time
    at: "23:00:00"
    id: late 
  - or:
      - alias: "If it's 11pm, we don't care about the temperature"
        condition: trigger
        id: late
      - alias: "If it's sunset, check the temperature"
        condition: numeric_state
        below: 50
        entity_id: sensor.outdoor_temperature_example
  - service: light.turn_on
      entity_id: light.back_porch_example

Let me wrap my head around your example and do some more testing… I guess I was thinking if Sunset + Offset is say 5pm… and the automation triggers, how will it know to turn on the light at 11pm… but it’s because there are TWO triggers (Sunset and the time of 11pm) combined with a ID tag… Makes sense!