Xiaomi Human / Body / Motion Sensor - Timeout

The problem with these sensor’s is the 120 seconds reset time, its hard coded, nothing you can do about it.

So if you have a timer that is anything less than that to turn off lights, it always going to run into problems.

My hallway lights dim to 50% after 30 seconds of no motion, then after 60 seconds, they turn off, but I wouldn’t be able to use the Xiaomi sensor to do this, as it would take 120 seconds before I could set them to dim, which is too long for the hallway lights, so I use a Hue sensor in there, as it has a 10 second reset time.

I just rigged up a £1.50/$2 PIR sensor to a Sonoff S20 plug, and that works over MQTT, so can set a time out of 1 second if needed.

1 Like

I have a Xiaomi motion sensor in my ensuite and it seems to be working fine with the below automation set at only 1 minute. Note that the alias says 2 minutes because the sensor stays on for 1 minute, plus the automation waits a further minute. I have all my lights set for a 2 minute total off-delay.

alias: Ensuite light OFF after 2mins
initial_state: 'on'
trigger:
  - platform: state
    entity_id: binary_sensor.motion_sensor_158d0001ad43db
    to: 'off'
    for:
      minutes: 1
action:
  - service: homeassistant.turn_off
    entity_id: light.ensuite_light

this is my ‘on’ automation… but in writing this I’m starting to wonder if maybe I’m just not in the room long enough to see the issue being discussed… since the one trigger is only going to work once the sensor has turned off first…

alias: Ensuite light auto ON motion
initial_state: 'on'
trigger:
  - platform: state
    entity_id: binary_sensor.motion_sensor_158d0001ad43db
    to: 'on'
condition:
  condition: or
  conditions:
  - condition: sun
    after: sunset
    after_offset: '-00:10:00'
  - condition: sun
    before: sunrise
    before_offset: '-00:30:00'
action:
  service: light.turn_on
  data_template:
    entity_id: light.ensuite_light
    brightness: >
      {%- if now().strftime('%H')| int >= 21 %}
        13
      {%- elif now().strftime('%H')| int < 5 %}
        13
      {%- elif now().strftime('%H')| int >= 5 %}
        255
      {%- endif %}

actually no, I dont have an issue since my total light on-time is greater than the Xiaomi sensor timeout. No wonder it works ok. I’ll shut up now!

@INTEL, @Cee, @ sparkydave, I had noticed the delay of 2 minutes and have worked around it by setting the timer to more than 2 minutes.

But, I think I understand what you mean: if I enter the room at the exact moment the light goes off, the light will stay off for 2 minutes due to the reported 2 minute delay of the xiaomi sensor. I cannot work around the delay in exactly that situation. If I would enter the room just before the light is turned off, or just after the light had been turned off, it would work normally. But this annoys me a bit as I seem to have the tendency to go into that room just when the light turns off :slight_smile:

Also, nice idea to turn the brightness down, something to add to my automation!

I just replied to someone else about the for command in automations, and on my mobile, so just going to post a link to it, but maybe you are having the same problem.

Thank you for the link.

After giving it some thought I realize it is another way to achieve the same, I hope you know what I mean?

I think something like this happens: the light-off automation is active for some (small) time-period. When during this time-period a new automation-trigger comes in, this one is ignored as the automation is working on the active task. In case of the xiaomi motion sensor this means wait for 2 minutes before a new trigger is generated. So, to get the effect that I want, either the xiaomi sensor delay time must go down to a few seconds, or the automation-function would need to have some kind of waiting-queue that can handle such kind of automation-collisions.

Or, maybe I should create the automation in the Xiaomi app. I don’t think the 2-minute delay is present in the app, I seem to remember. Back to re-reading this thread…

So basically with that automation, and your timing, it will be three minutes before your lights turn off, as the motion sensor will always stay active for 2 minutes, and then you are waiting for it to be off for 1 minute from there, so 180 seconds after last motion, your light will switch off.

If you obviously wanted your light to turn off after just two minutes, you just remove the whole for section,

alias: Ensuite light OFF after 2mins
initial_state: 'on'
trigger:
  - platform: state
    entity_id: binary_sensor.motion_sensor_158d0001ad43db
    to: 'off'
action:
  - service: homeassistant.turn_off
    entity_id: light.ensuite_light

Think you probably worked this out anyway, but just in case anyone else is reading this thread.

Can you post your automation here so we can see it. Don’t forget to put it into the code tag’s, the banner at the top tells you how.

You shouldn’t have a situation where the light doesn’t turn on from motion, even if you go in just as it turns it off, as soon as it detects motion again, it should run your automation, even if it is a under a second.

yeah, I haven’t actually timed it to be honest. Its works for me and I haven’t worried about reducing the time period. I suppose I could to reduce the on-time a bit

1 Like

if it works, then don’t touch it :smiley:

1 Like

Is this code serving you well?

Are the below related to two different sensors?

trigger:

  • platform: state
    entity_id: binary_sensor.motion_sensor_xxxxx
    to: ‘off’
    condition:
    condition: state
    entity_id: binary_sensor.motion_sensor_xxxxx
    state: ‘off’

It’s working as it should.
The light stay’s on for 2 minutes (xiaomi sensor timeout), and as soon the sensor closes, light’s turn off.
The sensors in the config I posted are for reference only, they are both the same sensor, i just didn’t add same amount of xxxx to replace original sensor name (xiaomi sensors). I have edit that post to avoid further confusion, sry about that.

Hi! I do have same problem as many others in this thread: how to solve the issue that when people are still in the room the lights do not go OFF.

  • in one room I have only one xiaomi sensor
  • in another room I have two xiaomi sensors (I made no group yet)
  • in another room I have one xiaomi sensor + a zwave motion sensor (I made a group)

apparently for each situation I need a different solution, right?

Now I am a bit confused on which …

but if people are in the room moving during that time, will the light continue to be ON?

Yes it will, sensor is in ‘ON’ state as long as it detect’s motion, and the light is ‘ON’ if the sensor is ‘ON’.

Ok, I will try your code. What do you think of adding some extra minutes just in case somebody is totally still for (example) 4 minutes , how to change the code accordingly?

use my code in post 72 and change the value- for: minutes: 2 (it will add that to the sensor timeout of 2 minutes, giving you 4 in total)

So you are not adding the condition (state off) as INTEL?

Sorry but I have been trying for a solution for like 6 months now … and always failed (now I just turn OFF without automation since family is totally upset at me, need to be sure about next solution :smiley: )

  - id: '1102'
    alias: Motion Kitchen - OFF light New type
    trigger:
      - platform: state
        entity_id: binary_sensor.pir_kitchen
        to: 'off'
    condition:
      condition: state
      entity_id: binary_sensor.pir_kitchen
      state: 'off'
    action:
      service: switch.turn_off
      entity_id: switch.light_kitchen

no, not needed. My automations for lighting have been working well for a year or so now