Is it possible to create 1 sensor out of 2 for leaving and entering a door?

Is it possible to create 1 sensor out of 2?

I saw a video about a switchbot door and motion sensor.
When the door sensor is opened and then motion gets sensed someone cam in.
And the other way around someone left.

Curious if this would be possible to create a sensor for those 2 states (come in = true) or (left =true) with a separate motion and contact sensor.

Yes, you could do that with a template sensor, it should be possible with both a trigger and state based sensor, with differing levels of complexity.

Could you explain some more on this? Even if just non-code. Trying to wrap my head around it.

What problem are you trying to solve?

More just curious but let’s say I want to know when someone entered or exited the house from the garage. The garage has a motion sensor by the door and the door has a contact sensor.

‘Door’ being the walk door and not the big garage door.

As the op asked - how would one combine these two into two sensors: enter and exit? I get that the order of triggering is the key but not sure the clean way to go boi it.

I am sure this has been covered numerous times but my search terms are lacking.

The answer is complicated, because this is complicated, and there’s no single right answer here.

Option #1 would be something ugly like:

template:
  - trigger:
      - platform: state
        entity_id:
          - binary_sensor.walk_door
          - binary_sensor.garage_door
        to: 'on'
    sensor:
      - name: "Entry/exit"
        state: >-
          {% if trigger.entity_id == "binary_sensor.walk_door" and (now() - states.binary_sensor.garage_door.last_changed < timedelta(minutes=5)) %}
            entry
          {% elif trigger.entity_id == "binary_sensor.garage_door" and (now() - states.binary_sensor.walk_door.last_changed < timedelta(minutes=5)) %}
            exit
          {% else %}
            unknown
          {% endif %}

This will report entry if when the walk door is opened the garage door changed state in the last 5 minutes, and exit if when the garage door is opened the walk door changed state in the last 5 minutes, otherwise unknown

Obviously this needs adjusted to suit your actual entities, and the timeframes you’re working with, plus it’s not that flexible. A better solution may be an input_text and an automation that uses wait_for_trigger.

1 Like

Thanks @Tinkerer!

The time comparison makes sense but I also like the idea of the wait_for_trigger as I was forgetting that ability.
I will play around with that some.

It would seems logical that when entering through the garage, the garage motion sensor, even though right by the entry door, would pick up the motion well (>1 sec) before the door open/close switch gets activated.
I just wonder when coming the other way if the door switch will get reported before the motion picks up the person or if there could be a chance of it occurring out of order. Sensor placement may have to be adjusted.
Thanks again