Light not on for 15 mins condition

This might seem rather trivial, and it does only occur occasionally, however it is annoying. I have a motion sensor automation that among other conditions I want the light to not turn on if it has previously been on in the last 15mins.
I don’t seem to be able to create the automation conditions correctly for that.
This:

entity_id: light.main_bedroom_light
state: "off"
for:
  hours: 0
  minutes: 15
  seconds: 0

Will check if the light has been off, but sometimes it has gone unavailable during that time, so it hasn’t been ‘off’ for a total of 15 mins.

This:

condition: not
conditions:
  - condition: state
    entity_id: light.main_bedroom_light
    state: "on"
    for:
      hours: 0
      minutes: 15
      seconds: 0

Checks that the light hasn’t been constantly switched on for a full 15 mins. The condition I am looking for would I suppose apply the time to the ‘not’ rather than the ‘on’.

I hope I have explained this properly, thanks for any ideas.

You can use a template sensor to capture the time an event happens (light on, light off) and then use that time in automation conditions or other templates.

Here is an example that captures the time at which a door opened / closed and then uses that timestamp in a calculation to make the door work like a motion sensor (e.g. it stays on for x minutes after the door moves)

You want to do something similar. Perhaps capturing two times - one for the light going off to on and one for the light going off to on, then you can use these in an automation condition.

template:
  - trigger:
      - platform: state
        entity_id: binary_sensor.studio_door_open
    sensor:
      - name: "ms_studio_door_trigger_time"
        state: "{{now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]}}"
  - binary_sensor:
      - name: "ms_studio_door"
        state: "{{ ((as_timestamp(now(), 0) | int(0)) - as_timestamp(states('sensor.ms_studio_door_trigger_time'),0) | int(0)) < (states('input_number.ms_studio_door_hold_delay')|int(0) * 60) }}"
        device_class: motion

That seems way more complex than necessary… why not just use a basic template binary sensor that is “on” only when the light is “on”:

template:
  - binary_sensor:
      - name: "Main BR light On exclusive"
        state: "{{ is_state('light.main_bedroom_light', 'on') }}"

then base the condition on that:

condition: state
entity_id: binary_sensor.main_br_light_on_exclusive
state: "off"
for: "00:15:00"
1 Like

This would definitely be a good solution, thank you, I can create this and exclude it from the recorder etc.
I was kinda wondering if there was a way to do it within the syntax of the automation conditions, without creating an extra helper/sensor.