Automation for presence detector switches on smart plug but immediately switches it off again

Hello Pelle,

You are using a device trigger. I personally do not know how they act but apparently it triggers when present and again when present is not there?
¯\(ツ)
I suggest using an entity trigger for this.