Need help understanding how to use Automation code examples on my HS Pi

Probably a silly question to those more experienced. Got my HA setup and doing fun stuff. But, I get stuck when trying to use Automation examples I find on the web. I cannot just copy/paste into the automations.yml file because my setup assigns a unique identified id#. So, whatI’ve been doing is to create a basic automation that does nothing and then go back and edit it in the configuration tool and copy/paste the code below the ID line. Then, I saw some examples that have a name where the ID shows on my HA. Hoping there is a better way to just take the code and create the automation. Wondering about two things. First, what about that ID#? Does it have to be a number, or can I just use anything as long as it is unique from other automations?

And, wondering also about where the automations are actually stored in HA. I deleted some that would not work directly from the automations.yml file but they still show (greyed out) in the Automations list and I have to remove them there. Curious to know how others deal with grabbing code snippets and managing them.

You can paste automation examples directly into automations.yaml. The ID needs to be unique and can be alpha-numeric, so long as there’s no spaces (I haven’t tried different symbols). Here’s how most of mine start: -

- id: unique_automation_id
  alias: A more helpful name
  trigger:

One option though is to use the Automation UI editor and paste the YAML into the specific section. The Trigger, Condition and Action all have 3 dots in the top right of that section. Click that and you can Edit as YAML. This will open a window where you can paste the specific parts of the automation you are trying to replicate.

Thanks AJStubbsy: That helps a lot. Must have been bad luck when I tried the past few times where it resulted in the Automations section to dissapear from the HA gui and I had to remove my pasted code. I have not yet masterd the fussyness of the indentations needed to make HA from blowing up. At least I know it can be done as you have suggested.

The good thing about the Automations UI editor is it will give you (at least try to) some indication of what is wrong. One tip and something that recently caught me out, is check the quotation and commas when copying and pasting code. Sometimes, copying and pasting, changes " (symbol on a #2 key on the keyboard) and ’ to `` and ` (the symbol left of #1 on a keyboard). It’s always a good idea to CHECK CONFIGURATION when you make changes to your files, as that can help debug as well (although it will probably just tell you there’s a problem in your automation.yaml when copying and pasting there) :smiley: :+1: