#difference between a wait and a condition on last_changed

1 messages · Page 1 of 1 (latest)

spice grail
#

consider an actions block with:

    actions:
      - action: light.turn_on
        target: &voordeur
          entity_id:
            - light.voordeur_buiten_lamp
            - light.poort_lamp
      - delay: >
         {{states('input_number.presence_timer')|int}}
      - action: light.turn_off
        target: *voordeur

and a related condition like:

    conditions:
      >
       {{(now() - trigger.from_state.last_changed).total_seconds() >
          states('input_number.presence_timer')|int}}

would these be interchangeable (and ave the identical effect) so I could do:

    actions:
      - action: light.turn_on
        target: &voordeur
          entity_id:
            - light.voordeur_buiten_lamp
            - light.poort_lamp
      - >
       {{(now() - trigger.from_state.last_changed).total_seconds() >
          states('input_number.presence_timer')|int}}
      - action: light.turn_off
        target: *voordeur

something tells me it is not the same, but I can't find the exact issue. what it should boil down to is that the lights are turned on, triggered by a motion detection, and that after the last detection has been off, for the set time, the lights turn off.

the simple delay seems to also work properly, because if during the delay the trigger fires again the automation is restarted...

it also has the advantage of being way more understandable because simple..

#

difference between a wait and a condition on last_changed

hallow frost
#

The condition is evaluated immediately, it isn't a delay. If it returns false your automation stops.

#

Depending on your triggers and automation mode, both setups could work

spice grail
#

right! thats it. condition isnt a wait, its true/false.... suppose the wait fits best then

  - id: poort_beweging_verlicht_voordeur
    mode: restart
    triggers:
      trigger: state
      entity_id: binary_sensor.poort_person_detected
      to: 'on'
    conditions:
      condition: state
      entity_id: binary_sensor.donker_buiten
      state: 'on'
    actions:
      - action: light.turn_on
        target: &voordeur
          entity_id:
            - light.voordeur_buiten_lamp
            - light.poort_lamp
      - delay: >
         {{states('input_number.presence_timer')}}
      - action: light.turn_off
        target: *voordeur