Help with wait for trigger automation

Hello all,

I have an automation I need a little bit of help with. Essentially, I’m trying to trigger it when motion is detected at my front door. However I only want to continue the automation if a person is detected as well. I tried doing a wait for trigger of person detected true, but that doesn’t fire if the last state was already true.

How can I make an automation that checks if something is true, and if not, it waits until it is true?

alias: Deepstack
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.front_door_camera_motion
    id: front_door_person
    to: 'on'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: front_door_person
        sequence:
          - wait_for_trigger:
              - platform: state
                entity_id: binary_sensor.front_door_camera_motion
                attribute: personDetected
                to: 'true'
                from: 'false'
            timeout: '60'
          - service: image_processing.scan
            target:
              entity_id: image_processing.front_door_face
          - service: switch.turn_on
            target:
              entity_id: switch.double_take_front_door

'on' or 'off', not 'true' / 'false'

EDIT: That’s an attribute though, so if that’s the case it will be

            to: True
            from: False

Can you not just trigger the automation on this attribute change?

              - platform: state
                entity_id: binary_sensor.front_door_camera_motion
                attribute: personDetected
                to: 'true'
                from: 'false'

Automation works as is, but the attribute is from the last motion event. So if the last one was a person and motion triggers again the attribute won’t change, that’s why I need it to trigger on motion and persondetected true. I could do a delay, and then check to see if it’s true but that seems a bit messy and slow.

That would be a template trigger

- platform: template
  value_template: > 
    {{ is_state('binary_sensor.front_door_camera_motion', 'on') and is_state_attr('binary_sensor.front_door_camera_motion', 'personDetected', 'true') }}

This of course will only work if personDetected is the string ‘true’. If it’s a boolean…


- platform: template
  value_template: > 
    {{ is_state('binary_sensor.front_door_camera_motion', 'on') and is_state_attr('binary_sensor.front_door_camera_motion', 'personDetected', True) }}

The issue with that is that person detection takes a couple seconds. So when it triggers for motion, it might not have detected a person yet. I could do motion from off to on for 5 seconds or so, but was wondering if there was a better way to do it.

The template will still do that. It will trigger when both conditions in the trigger are met.

if the sensor detects motion, it will be ‘on’ but personDetected will be false. So it does nothing. If sensor stays on and personDetected changes to true, it will then trigger. However if motion turns off and personDetected changes to true, it will not trigger.

Ah nice, that could do what I want then.