Automation Flickers Lights after 3 mins and occupancy does not work

Please copy and share the automation yaml correctly formatted for the forum.