Lights turning home by themselves and stay on for hours (node red)

It’s seems like when my Zigbee Motion sensor become unavailable, lights turn on and stay on until I manually turn them off (usually a few hours…)

Although my flow is only suppose to turn on when the payload is “on” and then turn off when it’s off

Update:
my flow was turning off when the motion was “off” but perhaps I can just change to != “on”

update 2:
I also tried event:stats > is not available but same issue, whatever I use this or =!, if the devices in unavailable node red return Entity could not be found in cache for entity_id

I think I’m having the same issue, but with my Shelly devices. I think I’ve narrowed it down to Node Red, as if I turn off Node Red and restart my network the issue doesn’t occur.

Did you end up working out what it was?