Conditions vs Triggers

Good morning All,

I am having a hard time understanding conditions and triggers. What I am trying to figure out is once a trigger is activated, will it continue to check the condition indefinitely until they are met or only for that instance. Here is an example that hopefully will help me understand. I use input booleans for presence detection and I want a light to go on if everyone is gone. The tricky part for me is I want it to go on if everyone is out of the house before sunset or the last person leaves after sunset. Will this require two automations, or am I missing something:

I could:

  1. use the light as a trigger with sunset and the input booleans as conditions but if the light is off, and never goes to on…no trigger right? Or can I just put the state of the light as off as a trigger?
  2. I could use the input boolean as a trigger, and the light off and after sunset as conditions but if everyone leaves before sunset will it trigger after sunset? Meaning, the trigger happens and keeps checking until all the conditions are met or if the trigger happens and the conditions aren’t met in that instance then it is done?
  3. same scenario for using sunset as a trigger. If someone leaves after sunset, will the light turn on? meaning, one person is home after sunset but decides to leave at say 9 pm. Will them leaving (which is a condition) finally be met and the trigger will activate?

Thanks,
Dan

The condition will be tested once right after the automation is triggered.

Sometime the difference with trigger and condition can be summed like this

  1. if you set Time as a trigger and sunset as the condition - HA will check every second if its sunset and then do its action, good for always available (like after reset) but process heavy

  2. if you set Sunset as the trigger with no condition, it will trigger only when changing to sunset - process light but only will work at state changes

2 Likes

First of all we need to know which possible triggers you have.

Do you only have PIR or also Door sensors?

If you the Sun plugin as a trigger it will only trigger if it goes to below horizon i think.

I would use a door sensor and the PIRs.

Trigger 1: door state changes from open to closed
Condition: sun.below horizon
action:

  1. wait 5 min
  2. condition pir off
  3. turn on lights

for example

Beautiful explanation

Hmm…As I worked it out in my head, I figured out I am going to need two automations:

  1. The light is off, everyone is gone (before sunset) and the sun sets and
    ---------Sunset is the trigger
  2. If it is after sunset, the light is off, and everyone leaves
    ---------Last person leaving is the trigger.

@RobDYI, I agree with your explanation except for when you use time as a trigger (your #1), it only gives you a slot to input one time meaning it will only trigger at that one instance. Using time as a condition allows you to define a range of before and after.

Am I missing something?

Thank you for your responses,
Dan

This will trigger at every state change or every minute.

sensor:
  - platform: time_date
    display_options:
      - 'time'
automation:
    trigger:
      platform: state
      entity_id: sensor.time
    condition: