#Trigger automation on occupancy change after time

1 messages · Page 1 of 1 (latest)

outer island
#

Hi all!

I've been fumbling through trying to figure out the trigger condition for an automation I want. I have an occupancy sensor for my bedroom.

I want to trigger an automation if the sensor goes from Detected to Clear , but only if it had been in the Detected state for a certain period of time (e.g. six or more hours). How would I configure a trigger condition for this?

If there's a pre-made Blueprint for this, that'd be great too; if not, I'll probably make and publish one once I have things working. I tried searching this channel and the Blueprints forum, but didn't find what I was looking for.

upbeat hatch
#

Feels a bit hacky, but I would create a template binary_sensor helper that tracks when the motion sensor detects motion and then use that being "on" as a condition:

template:
- binary_sensor:
    - name: test1
      unique_id: test1
      state: "{{ is_state('binary_sensor.motion_sensor', 'off') }}"
      delay_on: 
        seconds: 20
      delay_off:
        seconds: 10
#

basically delay_on: for the amount of time you want to motion to not be detected before turning on, and then give enough time in delay_off: for your automation to trigger and to retain the state for the condition

#

the latter could be 1 second, 5 seconds, 10 seconds, 30 seconds, whatever

rancid elm
# outer island Hi all! I've been fumbling through trying to figure out the trigger condition f...

ooo, we doing hacky? here's a very hacky solution but keeps it all in an automation:

mode: single
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.everything_presence_one_3fdb74_occupancy
    to: "on"
    from: "off"
conditions: []
actions:
  - wait_for_trigger:
      - trigger: state
        entity_id:
          - binary_sensor.everything_presence_one_3fdb74_occupancy
        from: "on"
        to: "off"
    timeout:
      hours: 6
      minutes: 0
      seconds: 0
      milliseconds: 0
    alias: wait for sensor to clear or 6h
  - if:
      - condition: state
        entity_id: binary_sensor.everything_presence_one_3fdb74_occupancy
        state: "off"
    then:
      - stop: ""
    alias: if earliy clear then stop
  - wait_for_trigger:
      - trigger: state
        entity_id:
          - binary_sensor.everything_presence_one_3fdb74_occupancy
        from: "on"
        to: "off"
    alias: wait for clear after timeout
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.mk_room_bulb

you will need to replace the sensor witrh thr right entity.
i added a "turn on light" as an example of doing something at the end

upbeat hatch
#

yeah, I tend to try to avoid long-running automations

#

but you could make a blueprint out of that

rancid elm
rancid elm
#

a better solution i would probably use is creating a switch (toggle) helper to:

trigger that sets it to on after sensor has been detected for 6h

trigger on sensor clear with condition that switch is on to clear which then turns the switch back off plug whatever you want

upbeat hatch
#

or turn it off in the automation that cares about it

alpine storm
#

Have you tried something like this?

upbeat hatch
#

that won't do what the OP wants

#

OP wants to track the duration of the previous state, not the new one

alpine storm
#

So this won't work either?

outer island
#

Hmmm maybe that will, yeah. I’d have to test

upbeat hatch
#

no, that won't work either

outer island
#

Taking some inspiration from some of the earlier suggestions, maybe make one automation that sets a binary sensor to true when the presence sensor is detected for more than X consecutive hours.

Then another automation when that binary sensor is on and when the presence sensor goes from detected to clear, trigger my scene or whatever