Trigger on movement

I am pretty new here and trying to make some small things work in our home.
I have just a simple movment and light sensor detection and want to do the next thing.
Movment detected, turn light1 on, movement stopped for 3 min turn off the light1.

Tried this in nodeRED and automations, failed in both. Please help

- trigger:
    platform: state
    entity_id: sensor.MOVEMENT
    to: 'on'
  action:
    service: light.turn_on
    entity_id: light.LIGHT
- trigger:
    platform: state
    entity_id: sensor.MOVEMENT
    to: 'off'
    for:
      minutes: 3
  action:
    service: light.turn_off
    entity_id: light.LIGHT

Thank you very much. It works.
The detection is pretty slow tho. There is like 5 seconds between detection and the trigger.
Is this normal?

Very likely its the sensor, what are you using?

I am using the Xiaomi aqara sensors with raspberry pi with raspbee gateway.

I use Xiaomi Aqara sensors and reaction is fast enough. What is your gateway ? Xiaomi as well ?

No. I am using Raspbee with raspberry pi 3b.
I used the automation code sent earlier. I am going to try that with nodered, maybe it is faster .

Iā€™d probably see if you can turn debugging on in the Raspbee so you can see when the motion sensor packets are being received.

You could also then debug HA and see when it is seeing the updates being received from Raspbee.

I doubt NodeRed will be faster than the sensor built into HA.

I use Wemo Motion sensors which are native WiFi to HA, and the delay from Wemo to HA is about 250ms. When logging the motion sensor packets on HA, the delay between it receiving the packet and triggering is not worth measuring; the delay is all down to the Wemo.

1 Like