Confusion over triggers and conditions

I’m getting confused between triggers and conditions. I’m turning my lights on and off based upon times offset from sunrise and sunset times, using them as triggers. What I’d like to do is have a couple of enhancements but I’m not sure whether I need more triggers or a combination of triggers and conditions, or whether I can add the necessaries in “graphical” mode, or I need to edit the YAML. The trigger thing concerns me because I gather it’s a one-off trigger, I’m not sure how often the inputs which I want to act upon, are “sampled”, for want of a better term.

Firstly I’d like to adjust the turn-on times based upon weather, i.e. sooner if the weather is cloudy and another time if it’s snowing for example.

Secondly, I turn off a set of lights at night at a fixed time but I’d like to leave them on if either my wife or I (or both of course) are out until we are both in and have been home for (say) 15 minutes. We use life_360 on our mobile phones. I’d also like to have a holiday mode that means this functionality is not used (i.e. the standard “off” times are used), but short of just having a global flag that I manually set, I’m struggling to see how to automate it. Could the Google calendar be read and we make sure we use a set heading for holiday periods, or is there something else we could use. I don’t mind if we have to manually set holiday periods since we don’t have that many during any 12 month period.

Many thanks - you wouldn’t think I used to be a software engineer, would you? I could write it in C as a cyclically sampled state machine but I’m struggling to get my head around the YAML model and sampling and trigger vs condition thing.

Many thanks, Mark Bradbury

Firstly I’d like to adjust the turn-on times based upon weather, i.e. sooner if the weather is cloudy and another time if it’s snowing for example.

I use illuminance to accomplish what you are asking for. My weather app is weatherbit so you are not limited to Weather Underground. This post describes it well:

How much “sooner”?

For example, if sunset is at 17:00 and you normally would offset by 30 minutes earlier (so 16:30), would you offset by yet another 30 minutes if it was snowing 1 hour prior to sunset?

If that’s the case then the automation would trigger at 30 and 60 minutes prior to sunset. At 60 minutes it would check weather conditions and only proceed if the weather was cloudy/rainy/snowing/whatever. At 30 minutes it wouldn’t check the weather.

BTW, if this is part of a strategy to guesstimate interior light levels, it’s far more accurate to employ a well positioned, interior light sensor (or two). It’s what I have used for many years; it’s filtered in order to smooth out short-term variations.

Usually it’s recommended to start by showing what you have already so that we can help you build from there.

Post your properly formatted automation code in yaml.

also there are other ways to give you an estimated “it’s dark out” sensor to trigger your lights based on current weather conditions.

here is one I use (borrowed from someone lse but can’t remember who):

sensor:
  platform: template
  sensors:
    dark_outside:
        friendly_name: It Is Dark Outside
        value_template: >
          {% if (state_attr('sun.sun', 'elevation') | int < -2) %}
            true
          {% elif (state_attr('sun.sun', 'elevation') | int < 1) and (states('sensor.dark_sky_cloud_coverage') | int > 80) %}
            true
          {% elif (state_attr('sun.sun', 'elevation') | int < 2) and (states('sensor.dark_sky_cloud_coverage') | int > 85) %}
            true
          {% elif (state_attr('sun.sun', 'elevation') | int < 3) and (states('sensor.dark_sky_cloud_coverage') | int > 95) %}
            true
          {% else %}
            false
          {% endif %}

Triggers for events (entity state change, time of day, sun position, every 5 minutes, etc. Fires whenever HA notices the change.)

Conditions to qualify whether trigger is worth processing (early sun position triggered AND weather is overcast, you/spouse are home, etc)