Make Input_boolean stay on for a certain time

Hi.

I’m trying to make an input boolean for “house occupied”.
The triggers include motion sensors, door/window sensors and device trackers.

The goal is to keep the input boolean “on” as long as any states have been triggered the last 20 minutes.

However the input boolean switches off after short time.

Any suggestions? Maybe there is even a better way than input_boolean.

  action:
  - data: {}
    entity_id: input_boolean.house_occupied
    service: input_boolean.turn_on
  - delay: 00:20:00
  - data: {}
    entity_id: input_boolean.house_occupied
    service: input_boolean.turn_off

Try giving us some more code. How do you turn it on and how do you turn it off?

I would just use a Template Binary Sensor for this instead. Example:

binary_sensor:
  - platform: template
    sensors:
      house_occupied:
        delay_off:
          minutes: 20
        value_template: >-
          {{ is_state('device_tracker.stoles_phone', 'home')
             or is_state('binary_sensor.office_motion', 'on')
             or is_state('binary_sensor.front_door', 'on')
             or is_state('binary_sensor.bedroom_window', 'on') }}

This will give you binary_sensor.house_occupied and it will turn on when any of those states are true, but will wait 20 minutes before turning off after those states are false.

2 Likes