Motion sensor timer expand

Hi there, I have several motion sensors at the hallways of my flat. My problem is, if my kids are playing in the hallway for a certain time the motion sensor stops detecting them and the light switches off. I’m using hue motion sensors with a short cool down time but I saw if the sensor detects 3 - 4 times motion in a row, the cool down time seems to be expand and no new signal is generated.
I tried it with a timer which should hold the light on until the sensor is ready again but unfortunately that didn’t work well for me.

Now I have a new idea and want to hear your opinion if it’s possible to do so.

The sensor should detect motion as normal and start a timer, but every time a new motion is detected the timer should be expanded (maybe every time +30 sec) and if there is no more motion the timer should be stopped and reset.

Is that possible to achieve? Thanks for your help.

Thats pretty straightforward using ‘restart’ as the script mode.
However, it won’t totally solve the problem.

The way triggers work in HA is when a state changes. So if the kids are constantly running around in the hall, the motion sensor will never go to a clear state, which means eventually the timer runs out and the light goes off.

Yes and because of that circumstances (kids are playing constantly in the hallway) the timer wasn’t the solution for me.
Hmm any idea to get a solution, I understand the sensor doesn’t clear maybe the problem only could be handled with a presence sensor right (eg Aqara FP1 or something like that)?

I think a presence sensor might be the only way to solve this. There are a number of different models on the market, the FP1 being a reasonable one.

i’m sad to hear this, I thought it would be a way to solve that issue without buying that expensive sensor only to stay lights on an hallway. I mean thats kind of wasting money for me. :frowning:

You shouldn’t need to. I have motion sensors in my utility room and garage that work just fine. An automation switches the light on as soon as motion is detected, and a separate one (because there are some other considerations in my case like physical switches and ping sensors) switches them off if no motion has been detected for a minute.

Here’s an edited version of my off automation showing the key bits:

- alias: Lights - utility room light off

  description: >-
    Turns the utility room light off 60 seconds after last motion detected.

  trigger:
    - platform: state
      entity_id: binary_sensor.utility_room_motion
      from: 'on'
      to: 'off'
      for:
        seconds: 60

  action:
    - service: light.turn_off
      entity_id: light.utility_room_light

What happens if you use something like that?

That seems like an obvious solution, which may solve the OP’s use case, given you’re talking about kids running around and moving alot.

I was thinking more about my own situation where I have the motion sensor in the kitchen. If you are sitting at the table, not moving much, then it does occasionally turn the lights off because no one is moving enough for it to sense you.

I combined the automations into one, so there are 2 triggers once motion is detected and once no motion is detected for 45 seconds. Then once a “light profile” for the day and once for the night. I think that seems to work too, but if I add an additional helper (brightness value of one of the motion detectors involved) as a condition, then the whole thing becomes unreliable. But I don’t know why. Here at least the automation WITHOUT the helper, does it look good so far?

description: if motion is detected, switch lights on/off
trigger:
  - type: motion
    platform: device
    device_id: 05eeedb05b4e2bf8630bbdae235aca54
    entity_id: binary_sensor.motion_hallway_downstairs_occupancy
    domain: binary_sensor
    id: motion detected
  - type: no_motion
    platform: device
    device_id: 05eeedb05b4e2bf8630bbdae235aca54
    entity_id: binary_sensor.motion_hallway_downstairs_occupancy
    domain: binary_sensor
    id: no motion detected
    for:
      hours: 0
      minutes: 0
      seconds: 45
    enabled: true
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: motion detected
          - condition: and
            conditions:
              - condition: state
                entity_id: binary_sensor.nightmode
                state: "off"
        sequence:
          - service: light.turn_on
            data:
              kelvin: 4000
              brightness_pct: 100
            target:
              entity_id: light.hallway_downstairs
      - conditions:
          - condition: trigger
            id: motion detected
          - condition: and
            conditions:
              - condition: state
                entity_id: binary_sensor.nightmode
                state: "on"
        sequence:
          - service: light.turn_on
            data:
              kelvin: 2500
              brightness_pct: 20
            target:
              entity_id:
                - light.hallway_downstairs
      - conditions:
          - condition: trigger
            id: no motion detected
            enabled: true
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.hallway_downstairs
mode: restart
1 Like

This is why I prefer to use multiple, simpler automations — reading yours is hard work. I also avoid using the device notation if I can, which is messier for no good reason.

You could also use the custom component Entity Controller.
Which is very powerful for motion triggered lights and easier to configure that separate automations.

I’m not good in writing code so I prefer to use the automation editor. All seems to be properly there :wink:
Unfortunately in the editor view things look messy, sorry for that.
what do you mean with device notation? I used motion detected and no motion detected, exactly as you did.

Entity controller? How does it work? Is it an addon to setup the entitys?
I saw a blueprint especially for motion detection (YAMA), is that similar to that?

You used the device platform, with device_id, domain, type and so on. I used the state platform with entity_id. Both should work, it’s just that the device way ends up with a lot of cruft in the code.

but if both ways work, that should not be responsible for my issues, is getting the lux value of my motion sensor used for the automation too the problem? should I get the brightness from another device?

I don’t know: you’ve not explained the lux issue in much detail apart from “becomes unreliable”. Show the code with that bit included and explain in words what you’re trying to achieve.

I will try it again first and then I will show you the code. It’s the same code but with the addition of my helpfer for the nightmode which is ON if the lux value of my sensor is below XXX lux, only in that case, the automation should run. If not the lights have to stay off.

  - choose:
      - conditions:
          - condition: trigger
            id: motion detected
          - condition: and
            conditions:
              - condition: state
                entity_id: binary_sensor.nightmode
                state: "off"
              - condition: state
                entity_id: binary_sensor.lights_active
                state: "on"
                enabled: true

No it’s not a blueprint, but an integration. You specify the motion sensor(s), the entities to control and the other options like overrides and night mode.

This is one complex config I use for my corridor, with a night mode, light transition time and backoff mode (to make the light stay on longer if I pass a sensor a couple of times in a short time)

entity_controller: 
  corridor:
    sensor:
      - binary_sensor.motion_corridor
      - binary_sensor.motion_stairs
    entity: light.corridor_lamp
    delay: 120
    backoff: true
    backoff_factor: 1.2
    backoff_max: 600
    service_data:
      brightness: 255
      transition: 3
    service_data_off:
      transition: 3
    night_mode:
      delay: 60
      service_data:
        brightness: 20
        transition: 3
      service_data_off:
        transition: 3
      start_time: "23:30:00"
      end_time: "07:00:00"
    overrides:
      - binary_sensor.light_outside
      - input_boolean.motion_sensor_off

Your first 2 actions have (as their second condition) an “And” that only has one condition. If you meant for both conditions to be required, they both need to be inside the “and” condition.

It doesn’t really matter because multiple conditions are already “and” by default, so it doesn’t change the way the automation works. It’s just something that doesn’t need to be there. But if you were to set up an “Or” condition the same way, it wouldn’t work.

tell me more about the backoff mode, sounds interesting for my case (playing children in from of the sensors) isn’t it?

Yes indeed. The delay option is the normal time the lights stay on after motion detected. The backoff_factor is the factor the delay gets multiplied with and added to the delay after a new motion detected (while the delay is not ended yet). backoff_max is the maximum time the lights may stay on, so the maximum delay.

1 Like