The automation example you posted looked very familiar to me and then I realized it’s something I had created almost three years ago.
That’s an automation as opposed to a script (two different terms in Home Assistant).
Start Home Assistant’s Automation Editor like this:
- Settings → Automation & scenes → Create Automation → Create new automation
- Click the overflow menu in the upper right corner (three vertical dots) and select Edit in YAML.
- Delete the existing YAML code displayed in the editing window.
- Copy the automation example posted above and paste it into the Automation Editor’s editing window then click Save.