Help: Light automation

Need some help. I have Smartthings with motion sensors and Phillips Hue. I want to have the lights turning on with motion and turning off 5min later if no motion is detected. I get them to turn on with motion but my problem is that they turn off and then after a few seconds detects motion and turn on again. Annoying when you are in the kitchen doing things. Alternatively I wanted it to not turn off automatically if it was already on. Any tips?

You shoul be able to do this with Smart Lighting.
If not CoRE will definately do it.
Here is a screenshot of a simple CoRE piston.
If you search 'CoRE for dummies ’ you should find all you need for CoRE.

Yeah, Smart Lighting works great for turning off things and turning on things but kinda sucks at turning on and off the same thing (mostly works). Seems like the off timer does not get reset sometimes and the light turns off no matter if motion was detected or not.

CoRE was the answer for me.

In “Expert Mode” with “Cancel on Piston State Change” selected, every time motion is detected, the clock resets.

If not in expert mode (Really powerful but can get confusing for noobs) use a Latching Piston.

The first “If” section (argument) can set the “On” condition
The second “But-If” section can set the “Off” condition

Each section cancels the other. Perfect for your scenario.

Easiest solution is
1 in the same automation that turns the lights on, deselect the " also turn off when motion stops" . Drawback to this is lights will never shut off.
2 Better option ( what I have in my kitchen) set it to turn off after x minutes after motion stops. Depending on what motion sensors you have the recycle time is between 1-3 minutes usually. So a 3 minutes delay after motion stops would give you your five minutes. Lights will stay on for 3 minutes after it stops detecting motion, and if there is any motion during that time it resets the clocks.