Xiaomi Motion sensor driving me crazy, keeps getting updated to 'off'

Hi there

I installed Hassio on a new system to be able to use Node Red.
Looks great, but having some issues I cannot understand.

I want a simple automation that takes me about 3 minutes to make in HA, took up 4 hours of my time already.
usecase is this
If movement, turn on some light. dead-easy.
2 minutes after movement stopped, turn off the light.

Now, here comes the problem.
The motion sensor keeps getting the ‘off’ state updated every x minutes (haven’t found the cause). This in turn keeps restarting the stoptimer, this never turning off the light.

Clueless as to what is happening.

Any ideas?

Have a look at this

It’s a slightly different take and I use the trigger from OH but you can use the same principle.instead of triggering on the OFF of the motion sensor start the timer after you turned on light (maybe 3 minutes) and before turning OFF check the status of the motion sensor. If it’s still on loop back to the delay, otherwise turn off light.

As explained in the topic the flow will become easier for you as you only have 1 motion sensor in your room.

Thanks, but I don’t like using a workaround without knowing what causes the motion sensor keep getting updated. If my first automation in Node Red starts off with a workaround for something I can set in HA in just a few minutes I am really going in the wrong direction

The event-state will fire when any part of the entity is updated in home-assistant. Which sounds like what is happening. You can use a full msg debug node on the event: state node to confirm this. The solution is to use rbe node after the PIR Small Kitchen node.

Yes, sounds like something like that is happening…
Good tip on the rbe-node, I’ll try that, thanks!

I tend to use the Poll State node and turn the update interval really high and only select “Output On Changed”.
You can also have to the node halt on “Off” so that it isn’t outputting any messages when the sensor is “Off”.

the rbe-node seems to do the trick!

Perfect!