Motion Detector - pause countown to turn off light when motion is detected still

Good Morning,
I have several motion detectors for turning on the lights in the house automatically for only 2 minutes. Is working fine so far, but there is one challange:. The light has to stay on when I’m in the room. Means the two minute Timer has to pause as long I’m in the room and the Motion detector is registering that.

And in some cases I have two motion sensors andI want to archive is that the countdown starts again, two minutes, when triggering the light e.g. now in the first floor. Assuming there is 30 seconds rest and I’m passing the second motion detector on the first floor, it is supposed to count down the two minutes again

Any Ideas how I may archive that?

Thanks

Simply use the run mode ‘restart’ and have two triggers in your automation with trigger ID’s ‘on’ and ‘off’.
For the ‘off’ trigger have a time for: "00:02:00" such that the trigger only happens once the motion sensor has been ‘off’ for 2 minutes.
Next, in your Action section have the a Choose function and use the two trigger ID’s to turn the light ‘on’ of ‘off’ respectively.

2 Likes

Thanks.
Do have an whole example by accident, with yaml code?
Since until now I used a blueprint what is not working here and I want to write it from scratch or using the standard light automation what is integrated in HA

2 Likes

Hi, this looks good. I’m going to try that out today and will give feedback on the result.
thanks

I figured it out, is working now.
Thanks a lot.

That won’t do what you asked for in your first post.

It will never turn off.

The automation I posted will turn off only after motion has ceased for 2 minutes.

Good Morning,

as mentioned above - it is working as explained by @tom_l @sparkydave
But now I hit another challenge since I have one light entitiy in three automations with each automation a different motion sensor. It is an big open livingroom and the sensors are distributet across the corners of the room.

Challenge:
I pass the first sensor and after couple of seconds the motion sensor detects no movement any longer (change of state) and the light will turn off after two minutes - like stated in the trigger section of the yaml file.
Now, after 90 seconds I pass the second sensor and I would expect that the light is going to tur off after again two minutes. But wrong of course since I passed the first sensor 90 seconds ago and is still counting down the time so the light will turn off in 30 seconds after passing the second or third sensor.
How can I solve that so that the automations overwrite each other and stop their countdown after passing another motion detector.

It looks like this right now, pretty easy but otherwise working like charme - at least with just one motion sensor in place.

As per my first reply.

Also, you don’t need 3 automations. Put all the motion sensors in the same automation as 3 triggers.

Rather than using the example from Tom, set it up how I mentioned above.

Here is an example:

alias: Alfresco LED Strip Auto
description: Alfresco LED Strip Auto
trigger:
  - platform: state
    entity_id:
      - binary_sensor.paradox_z6_alfresco_pir
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.alfresco_presence_sensor_f9a541_pir_sensor
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.paradox_z3_garage_door
    to: "on"
condition:
  - condition: or
    conditions:
      - condition: sun
        before: sunrise
        before_offset: "-01:00:00"
        after: sunset
        after_offset: "-00:15:00"
      - condition: state
        entity_id: light.alfresco_led_strip
        state: "on"
      - condition: template
        value_template: >-
          {{ states('sensor.garage_multisensor_illuminance') | int(0) <
          states('input_number.alfresco_min_lux') | int(1) }}
action:
  - service: light.turn_on
    data:
      brightness_pct: 90
    target:
      entity_id: light.alfresco_led_strip
  - wait_template: >-
      wait_template: "{{
      is_state('binary_sensor.alfresco_presence_sensor_f9a541_occupancy', 'off')
      }}"

      timeout: '01:00:00'
    continue_on_timeout: true
    enabled: false
  - wait_for_trigger:
      - platform: state
        entity_id:
          - binary_sensor.alfresco_presence_sensor_f9a541_occupancy
        to: "off"
        for:
          hours: 0
          minutes: 2
          seconds: 0
    timeout:
      hours: 0
      minutes: 20
      seconds: 0
      milliseconds: 0
  - delay: >-
      00:0{{ states.input_number.alfresco_spotlight_auto_off_time.state | int(1)
      }}:10
    enabled: false
  - choose:
      - conditions:
          - condition: state
            entity_id: schedule.back_yard_lighting_time_extend
            state: "on"
        sequence:
          - delay:
              hours: 0
              minutes: 20
              seconds: 0
              milliseconds: 0
      - conditions:
          - condition: state
            entity_id: schedule.back_yard_lighting_time_extend
            state: "off"
        sequence:
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.alfresco_led_strip
trace:
  stored_traces: 20
mode: restart

The above is little more complicated than you need because I have two different ‘off timers’ depending on a schedule and it also has illuminance based conditions plus wait templates relating to presence sensing. You can trim out those functions to just do basic on/off using your triggers and a fixed time delay.

Example:

alias: Alfresco LED Strip Auto
description: Alfresco LED Strip Auto
trigger:
  - platform: state
    entity_id:
      - binary_sensor.paradox_z6_alfresco_pir
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.alfresco_presence_sensor_f9a541_pir_sensor
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.paradox_z3_garage_door
    to: "on"
action:
  - service: light.turn_on
    data:
      brightness_pct: 90
    target:
      entity_id: light.alfresco_led_strip
  - delay: "00:02:00"
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.alfresco_led_strip
trace:
  stored_traces: 20
mode: restart

Is working like charme. Forgot the restart option, yes.

Thanks!

@sparkydave @tom_l
Hi,

one further question to this automation you solved for me (Thabnks again). How can I set an option in this automation to reach the follow goal:

a) Brightness 30% of the max illumination of this lamp between 9pm and 6am
b) Brightness 60% of the max illumination of this lamp between 6am and 9pm

Thanks
Tux1980

action:
  - service: light.turn_on
    data:
      brightness_pct: >
        {{ if 6 <= now().hour < 21 }}
          153
        {{ else }}
          76
        {{ endif }}
    target:
      entity_id: light.alfresco_led_strip

Hi,
Get the Syntax but why the value 153 especially?

Woops. Sorry I missed that you were using brightness_pct

It I’am changing that I getting the message:
Message malformed: template value should be a string for dictionary value @ data[‘action’][0][‘data’]

action:
  - service: light.turn_{{ trigger.to_state.state }}
    data:
      brightness_pct: >
        {{ if 6 <= now().hour < 21 }}
          153
        {{ else }}
          76
        {{ endif }}
    target:
      entity_id: light.flur_oben_light
mode: restart

Yeah I messed up quite a bit try this:

action:
  - service: light.turn_on
    data:
      brightness_pct: >
        {% if 6 <= now().hour < 21 %}
          60
        {% else %}
          30
        {% endif %}
    target:
      entity_id: light.alfresco_led_strip

This is working now:).
In some autmation I do have several light target which I want to behave differntly. When I want to illuminate them differnt I just can put the data straight below the corresponding “entitiy_id”, right?

No I#m creating for each bulb a corresponding service, so I can put it below each service, ok

Yeah you need a separate service call for each different set of data.

I think something has been happened.
Now the light aren’t turning off again after a minute as it was before I putt the data section with the time and brightness optiones.

alias: Motion Detection - TRADFRI Leon Tür
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.tradfri_leon_tuer_bewegung
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.tradfri_leon_tuer_bewegung
    to: "off"
    for:
      minutes: 1
condition: []
action:
  - service: light.turn_{{ trigger.to_state.state }}
    data:
      brightness_pct: |
        {% if 6 <= now().hour < 21 %}
          60
        {% else %}
          20
        {% endif %}
    target:
      entity_id: light.flur_oben_light
mode: restart

Any hint what that might cause? I guess (maybe) that even when the state is going back to “normal” it sets again the brightness below the service means the light will never switch off?

You are missing this bit below the light turn on action:

I only showed you how to modify the light turn on service call. It was not meant to replace all your actions. Sorry I should have made that clear.