Binary sensor triggered after time in state

I am sure there must be a simple solution to this problem. I would like a binary sensor that turns ON when some other entity has been in a particular state for longer than a predetermined time. For example, when there has been no motion in the house for 5 minutes, the timer_boolean sensor would come ON.

I could use a combination of the timer, a binary sensor and a couple of automations, but this feels like it should have a simple solution (I’d like to stick to native HA rather than head down the app daemon route please).

I’d imagine the solution would be configured like:

timer_boolean:
    entity: sensor.motion_at_home
    state: OFF
    time_delta: 500 # seconds

Cheers

For state checks, you can use the for: option to specify how many minutes it must have been in that state. You could use an input boolean to indicate whether there’s been motion/no motion and a pair of automations.

One turns the boolean off when there’s motion (and the boolean is on). The other waits for the motion sensors to be off for 5 minutes before turning the boolean on. You could probably put all the motion sensors in a group and monitor the group’s state to simplify that. Something like:

input_boolean:
  house_idle:
    name: No motion for at least 5 minutes
    initial: off
    icon: mdi:timer 

automation:
  - alias: house is idle
    initial_state: on
    trigger:
      - platform: state
        entity_id: group.motion_sensors
        to: 'off'
        for:
          minutes: 5
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.house_idle

  - alias: house has motion
    initial_state: on
    trigger:
      - platform: state
        entity_id: group.motion_sensors
        to: 'on'
    condition:
      - condition: state
        entity_id: input_boolean.house_idle
        state: 'off'
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.house_idle
1 Like

@Tinkerer thanks for your suggestion, I believe it will work, but I have hit a slight roadblock. I have my automations setup for use with the Automations editor, but this does not allow me to set the initial_state nor use for. Any suggestions? I have raises this as a feature request.

Feature request is the right way to raise it

OK so although I can’t add the for in the automations editor, if I manually add the automation in automations.yaml the for rule it is displayed in the editor: