Trying to trigger an action based on the sequence of two contact sensors opening or not opening

Hi all, fairly new to HA and loving the challenge. however this automation has me stumped. has anyone tried to do anything similar? I’ve tried to search the forums but not found anything.

So I’ve got a porch door leading to a front door, both have contact sensors on them I’m trying to set up some tracking automation with 4 possible scenarios

  • Someone left the house
  • Someone entered the house
  • Someone opened the porch (probably a package delivery)
  • Someone opened the front door. (probably picking up a package)

I’ve got it half working with the assistance of some helpers I’ve set up.

Hello Dave,

If you want someone to help, please post the YAML. That is ridiculously hard to look at.
Use the </> button or this when you post it:
Here is an example of how to fix it from the site FAQ Page.
How to help us help you - or How to ask a good question.

Sorry, here is the latest code (for one half of the problem, figure if i get this working then i can just copy it to increase occupancy/packages) I have modified it a bit since i posted last night.

So currently if somoene exits the package counter is decreasing but not the occupancy counter

alias: Somebody Exits V2
description: ""
triggers:
  - type: opened
    device_id: e0963fb6dcd3f8390480b2dfb44f0d8f
    entity_id: bb29c0ae6762179a52bb11faa6a217be
    domain: binary_sensor
    trigger: device
conditions: []
actions:
  - action: timer.start
    metadata: {}
    data: {}
    target:
      entity_id: timer.porch_door_timer
  - if:
      - type: is_open
        condition: device
        device_id: df0a813a2f3810aa27dc4ea6d95de0f4
        entity_id: d4370a3bbd8a6dbec44ff18a18d21d08
        domain: binary_sensor
    then:
      - action: timer.pause
        metadata: {}
        data: {}
        target:
          entity_id: timer.porch_door_timer
      - action: counter.decrement
        metadata: {}
        data: {}
        target:
          entity_id: counter.occupancy_estimate
  - delay:
      hours: 0
      minutes: 1
      seconds: 5
      milliseconds: 0
  - choose:
      - conditions:
          - condition: state
            entity_id: timer.porch_door_timer
            state: idle
        sequence:
          - action: counter.decrement
            metadata: {}
            data: {}
            target:
              entity_id: counter.parcel_counter
  - action: timer.cancel
    metadata: {}
    data: {}
    target:
      entity_id: timer.porch_door_timer
mode: single