Automation depending on input_boolean and PRI-Sensor

Hi

I try to create an automation for following use-case:
Alarm-state should be enabled, if front-door is locked by leaving the house

I have to sensors, to controll this automation:

  • magnetic-sensor which push lock of front-door to an input boolean: housedoor_lockstatus
    (this works fine)
  • pir-sensor inside the house near front-door

My intention is with following logic to controll the automation:
If input boolean.housedoor_lockstatus change from off to on when there is no movement after this trigger for 15 seconds from pir-sensor, then arm the house.

i don’t get a solution for the condition part…

here is my code:

- id: '1604878166027'
  alias: Arm house when locking
  description: Alarm einschalten wenn mit SchlĂĽssel geschlossen wird
  trigger:
  - platform: state
    entity_id: input_boolean.housedoor_lockstatus
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: input_boolean.turn_on
    data: {}
    entity_id: input_boolean.alarm
  mode: single

the pir sensor send a movment by mqtt via sonoff-bridge.
(text from file included binary sensor:)

- platform: mqtt
  unique_id: sonoff_pir_keller_tuere
  name: Sonoff PIR Keller TĂĽre
  state_topic: "tele/tasmota_EF53BF/RESULT"
  value_template: '{{value_json.RfReceived.Data}}'
  payload_on: 'FBFF1E'
  payload_off: 'FBFF1Eoff'
  device_class: motion
  qos: 1

perhaps anyone have a hint :woozy_face:

Skip the condition and do it in the services.

- id: '1604878166027'
  alias: Arm house when locking
  description: Alarm einschalten wenn mit SchlĂĽssel geschlossen wird
  trigger:
  # Every time the door locks
  - platform: state
    entity_id: input_boolean.housedoor_lockstatus
    from: 'off'
    to: 'on'
  condition: []
  action:
  # Wait here until this is true. Or, quit if this times out. 
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.sonoff_pir_keller_tuere
      to: 'off'
      for: "00:00:15"
    timeout:
      # Give it some time to evaluate. Keep in mind, the PIR might currently still
      # be ON from when you initially walked through it to lock the door. 
      # Determine a good timeout here. It will depend on how often your PIR 
      # changes state honestly.
      seconds: 20
    # If this never happens, halt the entire automation here
    continue_on_timeout: false
  - service: input_boolean.turn_on
    data: {}
    entity_id: input_boolean.alarm
  # Every time the door locks, restart this. Just in case we lock the door, turn around unlock, 
  # run inside and grab something, then come back and relock. 
  # Want it to re-evaluate every time it locks. 
  mode: restart
1 Like

@jocnnor thanks a lot for your clear and well explained answer! :smiley:
will try this tomorrow morning!