Xiaomi Human / Body / Motion Sensor - Timeout

Hi Klagio, maybe you can try the way that I have written my automation, with a timer. See my post #99, a few posts up.
It works in such a way that the timer is restarted every time a movement is detected. So as long as there is a movement before the timer ends, the light stays on.

Next to the automations shown in my post, you will also need to define the timer in configuration.yaml:

timer:
  lamp_on:
    duration: '0:03:30'

3:30 minutes is the value I use, change it to any value you like.

I saw your automation, but isn’t a timer the same as the “for:” in the turn_off automation?
?

I mainly used the timer to make sure that the lamp would stay on when there were more movements detected while the lamp was on.
And then it made sense to use the timer for the off-automation too.

I tried your automation and it works for the minutes i set in the timer, but after those minutes the lights go off also if there is movement and i have the sensor just near me.
What’s wrong?

There could be some mistakes in my code. My latest code looks like this:

- id: '1541182668961'
  alias: Lamp on at movement
  trigger:
  - entity_id: binary_sensor.motion_sensor_xyz
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: timer.lamp_on
    service: timer.start
  - after: '16:00:00'
    before: 01:00:00
    condition: time
  - below: '10'
    condition: numeric_state
    entity_id: sensor.illumination_xyz
  - data:
      entity_id: light.something
    service: light.turn_on
- id: '1541264176539'
  alias: Lamp off after some time
  trigger:
  - event_data:
      entity_id: timer.lamp_on
    event_type: timer.finished
    platform: event
  action:
  - data:
      entity_id: light.something
    service: light.turn_off

This is a 1-to-1 copy of the code in my automations.yaml
I see something strange: there are no quotes around the time of 01:00:00, I wonder whether this is a bug, or not?

The timer is always started, no conditions anymore. This helps when someone turns on the light manually. Because the sensor is in the same room as the switch, the light will automatically go off when the timer finishes.

I do see sometimes that the light goes off while it is supposed to stay on, but only when the “next” movement comes at the same time as the timer finishes. When the “next” movement comes well before end of the timer, then the lamp stays on for some more time.

I’m still looking for a solution for this “bug”. I don’t think it can be solved in the automation-code. I think the solution could be found in the way automation-triggers that happen at the same time are handled within HA.

Is this working?

It should never be met (same day event)

Update: I have tested the construct “condition: or” and it seems to be accepted; no error-message in the logs.
Just the message in the Automation-page.

I hope so? I tried to code it as shown in another post on this forum, using the construct “condition: or” but then the automation-page shows the message: unsupported condition “or”.

If I understand that right, the Aqara motion sensor (PIR) had internal (hard-coded) delay of 60 seconds to send the new status. Status could be: Something is moving or nothing is moving. Right?

I saw this great-Xiaomi Zigbee-Temp-Sensor hack here:
hackaday.io - This project is a hack of a Xiaomi Mi smart sensor in aim to develop your proper code with a zigbee protocol
and here another too:

I buy a lot of motion sensors from Aqara (RTCGQ11LM) to use them in my house. The goal of 60 second delay is something that I really dont like. I really really hope that It would be possible to manipulate the firmware. Changing the value from 60 seconds to anything else, would be nice.

Yesterday I made some photos of the PCB of the Aqara RTCGQ11LM



7 aqara PIR pcb photos
There are 6 unamed solder-points and it could be that theese are GND, RST, VCC, DO1, RX & TX. But I do not know the 100% right order.

I hope here is somebody who can help me.

Greetings by JamieMe

If you look at that French site, he says he thinks that the programming pin layout is the same on the motion sensor as on the temp/hum sensor.

I find it quite hard following his site as my French is no good, and google translate is a little bizarre at times.

In the past, see earlier posts, some people (me too) complained about lights not turning on when the xiaomi motion sensor was triggered. Also, it was noticed that there’s a “dead-time”: when triggered, the xiaomi motion sensor does not respond to movement for some time (120 seconds in my HA system).

I have been playing with a lot of options to try to solve the first problem: lights not turning on when the motion sensor was triggered. Nothing worked until I realized this: the light(s) being triggered by the sensor must be turned off before the motion sensor becomes active again. Only then will the light turn on properly when the sensor becomes active again. When the lights are turned off sometime later, the sensor can be triggered before the lights are turned off and will be in “dead-time” state when the sensor is triggered a next time. Result: lights will not turn on.
I thought this could be solved by using a timer; restarting a running timer by a next movement. This worked most of the time but still not always.

When I was testing this realization, I noticed it still did not work sometimes. I checked in detail and found that the dead-time of the motion sensor is sometime longer than 120 secs, sometimes it is a multiple of this period. I guess this is because the sensor gets triggered again before it has sent the message to the HA that it is off.
image

So, my hopefully final automation-solution turns off the lights when the motion sensor state goes from on to off. Will follow up with results some time later.

Hmm, still not working :frowning:
Also, I noticed a light was turned off, triggered by the automation, but HA shows the sensor as being continuously on. So there was a movement directly after the sensor and consequently the light turned off. Detected by the sensor but no automation-triggered turning-on of the corresponding light in HA. There seems to be a dead-time in HA too?

I’ve got the same issues here, maybe once a week the motion sensor will not power on the light of my kitchen or of my entry.

It’s working maybe 100/1 but when the light doesn’t light up it’s really really annoying (specially when it’s my non-geek impatient girlfriend!)

Haven’t looked in details why it behave like this but I’ve noticed that when the light is switched-on and I restart homeassistant, the light will never switch off again.

Maybe that can help resolve the issue…?

I notice since 0.84.x the motion trigger got delay. like 10 second sometimes. For whatever reason, I am not sure. When I check the sensor it says 15 sec ago but the light come on late.

I managed to reduce the issue after noticing my Raspberry Pi 3B+ under volt(red led did not light up) by rebooting the pi.

Another possibility, xiaomi gateway broadcast signal got lost when your wifi unstable(maybe congested or someone using same channel with you. )

Solution for if you restart you HA and the light never off. I made an automation.
if the light on for x minute,
condition motion sensor is off,
turn off the light.
see example below. there is 2 trigger. Either sensor got off for 3 minute (means 5 mins) or light been on for 5 mins (add 10 second so both dont trigger at same time…just wild guess.)

- alias: 'AutoCMBathRoom Off'
  hide_entity: True
  trigger:
    - platform: state
      entity_id: binary_sensor.motion_cm_bathroom
      from: 'on'
      to: 'off'
      for:
        minutes: 3
    - platform: state
      entity_id: switch.wall_switch_cm_bathrm_light
      to: 'on'
      for:
        minutes: 5
        seconds: 10
  condition:
    - condition: state
      entity_id: binary_sensor.motion_cm_bathroom
      state: 'off'
  action:
    - service: switch.turn_off
      entity_id: switch.wall_switch_cm_bathrm_light
1 Like

If you’ve trouble/issues with the motion sensor please mention the version of the gateway you’re using. The motion sensor of the acpartner.v3 (LAN protocol v2) is handled differently as the lumi.gateway (LAN protocol v1).

I been reading the thru motion sensor. Seems my motion sensor still 120 second.

How to narrow down to 65 second. Should I use custom_component with scan_interval

from datetime import timedelta

SCAN_INTERVAL = timedelta(seconds=5)

Correct. Just copy the components/binary_sensor/xiaomi_aqara.py to custom_components/binary_sensor/xiaomi_aqara.py and add your code.

By accident, while trying to understand why my automations related to the xiaomi motion sensor sometimes do not function, I came across this, breaking change in 0.83.3:

I have updated my automations, let’s see what that does.

Hmm, now nothing works.

These bits make no sense to me:

    - service: automation.turn_on
      data:
        entity_id: automation.MOTION_OFF

and

    - service: automation.turn_off
      data:
        entity_id: automation.Motion_off

What is this automation.motion_off?

This is one of my automations, what shall I change to make it work according to the breaking change?

- id: 'xxxxxxxxxx'
  alias: Lamp aan na beweging op overloop
  trigger:
  - entity_id: binary_sensor.motion_sensor_xxxxxxxxxxxx33
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: template
    value_template: '{{ states.sensor.period_of_day.state != "day" }}'
  action:
  - data_template:
      entity_id: '{% if not( 1 < now().hour < 6) %} light.overloop {% else %} light.hal
        {% endif %}'
    service: light.turn_on
- id: 'xxxxxxxxxx'
  alias: Lamp uit na overloop sensor uit
  trigger:
  - entity_id: binary_sensor.motion_sensor_xxxxxxxxxxxx33
    from: 'on'
    platform: state
    to: 'off'
  action:
  - data_template:
      entity_id: '{% if states.light.hal.state == "on" %} light.hal {% else %} light.overloop {% endif %}'
    service: light.turn_off

Nothing. You don’t use “events” here.