Identified automation bug and trimmed code

- Code has been trimmed since many attributes are not used.

- Code does not protect against immediate automation stop and restart.
This results in 2 separate automation cycles. For now, a warning is
displayed to let the user know how long they should wait.