I suggest you simply copy the example I posted directly into a new automation (or overwrite your existing automation) then replace switch.your_switch with the entity_id of your switch.
For more information, refer to the “How to import an automation from the forum” section of the following post: