Execute function when an entity is stopped

Is there a way to do this or it is highly complicated?

I dont know if this works: execute as @e[tag=speed] if entity @s[nbt={Motion:[0.0d,0.0d,0.0d]}] run function ***:&&&

Continue to help post