Automation with door sensor and PIR sensor

I have a PIR sensor inside, a door sensor, and a PIR sensor outside.

Goal is when I go from inside to outside (inside PIR gets triggered AND door/sensor gets triggered) to turn OFF lamp inside and turn ON lamp outside for 2 minutes

Goal is when I go from outside to inside (outside PIR gets triggered AND door/sensor gets triggered) to turn OFF lamp outside and turn ON lamp inside

How to achieve this?

While this doesn’t have the timer piece, it does address the inside/outside, so should get you started.

1 Like

I have similar automation in my home. But i only use one motion sensor.
Maybe this could work?

- id: '1000'
  alias: 'come back'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.door
    from: 'off'
    to: 'on'
  condition:
    condition: and
    conditions:
      - condition: numeric_state
        entity_id: sun.sun
        value_template: '{{ state.attributes.elevation }}'
        below: 10
      - condition: time
        after: '16:00:00'
        before: '23:00:00'
      - condition: state
        entity_id: binary_sensor.motion_sensor_outside
        state: 'on'
  action:
      - service: light.turn_off
        entity_id: light.outside
      - service: light.turn_on
        entity_id: light.inside
      - delay: 00:03:00
      - service: light.turn_off
        entity_id: light.inside


- id: '1001'
  alias: 'go out'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.door
    from: 'off'
    to: 'on'
  condition:
    condition: and
    conditions:
      - condition: numeric_state
        entity_id: sun.sun
        value_template: '{{ state.attributes.elevation }}'
        below: 10
      - condition: time
        after: '16:00:00'
        before: '23:00:00'
      - condition: state
        entity_id: binary_sensor.motion_sensor_inside
        state: 'on'
  action:
      - service: light.turn_off
        entity_id: light.inside
      - service: light.turn_on
        entity_id: light.outside
      - delay: 00:03:00
      - service: light.turn_off
        entity_id: light.outside

You can delete time and sun condition.

1 Like

I tried this, but is not working. Problem is, I think, the pir sensor (which is in the condition) that has the ON (motion) value for too short period,

before i open the door (which triggers the door sensor) I think the pir sensor is back to OFF.

How to solve?

How about just checking if it was last triggered in the last 3 mins?

Here is the code:

  - condition: template
    value_template: '{{(as_timestamp(now())-as_timestamp(states.<pir entity id goes here>.last_updated)) | int < 300 }}'
2 Likes

I think blinkwise is right about this. :slight_smile: Test it and let us know if it works.

thanks will try. What is 300, 3 minutes? Should not be 360 (seconds)?

I think 300 is 5 minutes.

ops yes so is seconds? 60x3=180 60x5=300 ?

Yup. :):):slight_smile:

no clue on the 300 lol. Its just what I set it as and its around 3 mins.

well then maybe is like 3:00

as_timestamp() will convert datetime object or string to UNIX timestamp. UNIX timestamp is in seconds.

there you have it, 300 is 5 mins then. So adjust your code accordingly. 5mins works in the application I am using it for