#Automation Trouble - Conditional Execution based on a template never evaluates to false

1 messages · Page 1 of 1 (latest)

pale kettle
#

The If-Then-Else portion of this automation is not working correctly. Even when I wait more than 10 seconds, the Then is performed, when I trigger the automation. In the visual editor, if I click Run This Action, it evaluates correctly. What could be going on here?

triggers:
  - trigger: state
    entity_id:
      - binary_sensor.aqara_fp2_b_presence_main_zone
    to: "on"
    id: Presence
  - trigger: state
    entity_id:
      - binary_sensor.aqara_fp2_b_presence_main_zone
    to: "off"
    id: Absence
    for:
      hours: 0
      minutes: 0
      seconds: 5

actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Presence
        sequence:
          - if:
              - condition: template
                value_template: >-
                  {{ as_timestamp(now()) -
                  as_timestamp(states.binary_sensor.aqara_fp2_b_presence_main_zone.last_changed)
                  < 10 }}
            then:
              - action: scene.turn_on
                metadata: {}
                data: {}
                target:
                  entity_id: scene.last_basement_lights
            else:
              - action: scene.turn_on
                metadata: {}
                data: {}
                target:
                  entity_id: scene.basement_all_bright_day```
mortal cloak
#

you didn't include your trigger

#

conditions don't wait for anything

pale kettle
#
  - trigger: state
    entity_id:
      - binary_sensor.aqara_fp2_b_presence_main_zone
    to: "on"
    id: Presence
  - trigger: state
    entity_id:
      - binary_sensor.aqara_fp2_b_presence_main_zone
    to: "off"
    id: Absence
    for:
      hours: 0
      minutes: 0
      seconds: 5```
mortal cloak
#

right, so it will always execute the "then"

pale kettle
#

why?

mortal cloak
#

because conditions don't wait for anything

#

if your trigger is based on that entity, the condition is immediately checked and will always be true

pale kettle
#

oh i see

#

thought on how to re-write? is my goal clear?

mortal cloak
#

not really

pale kettle
#

ok let me explain

#

if I leave the room, I want to snapshot the scene (this happens in the Absence trigger and is working correclty, but I couldn't fit all the text)

#

then if I return before some critical amount of time (10 seconds in this case) I want it to restore that created scene

mortal cloak
#

you coiuld use a wait_template with a timeout in the action

#

trigger on absence, save the scene, wait_template for you to return or timeout, restore the scene if it didn't time out

pale kettle
#

ok thanks

#

that's helpful

mortal cloak
#

Or wait_for_trigger with a timeout

pale kettle
#

where is this in the docs? I need to read up a little

#

and this would go in the absence action

mortal cloak
#

Script syntax