Well it’s hard to fault find when you can’t see the correctly formatted code, so make sure there is a blank line above and below the code, then select the code (when in the edit box), and click the </> button at the top of the edit box. This for pasting code in the forum, which is where you are
Why don’t you use the forum internal functions for pre-formatted text? Thats what @keithh666 asked for
Your automation code does look ok (at least to me, but I am not an expert).
So first thing you should try is to trigger the automation manually. If you don’t see the automation on your UI, I think you need to define where the “all_automations” group should be displayed, like: