Trying to get the hang of automations

Never used it before, do you want a screen dump or the file?

  • alias: “Switch_on_at_sunset”
    initial_state: ‘on’
    trigger:
    • platform: sun
      event: sunset
      offset: “-00:45:00”
      action:
    • service: switch.turn_on
      entity_id:
      • switch.bokhyllor_arbetsrum
      • switch.dags_fonsterlampa
      • switch.fonsterlampa_foraldrars_sovrum
      • switch.fonsterlampa_rubens_rum
      • switch.golvlampa_tv
      • switch.lampa_gymmet
      • switch.ph_golv_datarum
      • switch.ph_golv_vardagsrum
      • switch.ph_hall
      • switch.tvbank_lampor
    • service: light.turn_on
      entity_id: light.dimbar_brytare_1

I think your alias should be surrounded by single quotes ‘Switch_on_at_sunset’

same problem

Is the code in a separate automations.yaml file or in the main configuration.yaml?

Until you can provide the raw file, it’s going to be really hard for us to help you. If you’re going to paste it here, use the code format button (</>), or paste it on hastebin or similar.

Screen captures hide things.

Have you actually tried the code in automations.yaml as the lint checker is complaining about the alias line, which it shouldn’t do unless you have a tab or something in there?

It’s really hard to tell with a screenshot and without the actual code. Just based on the screenshot, you appear to be missing automation: before line 1 and from service: light.turn_on to the end, you’re missing a space. Try this…

automation:
  - alias: 'Switch on at sunset'
    initial state: 'on'
    trigger: 
      - platform: sun
        event: sunset
        offset: "-00:45:00"
    action:
      - service: switch.turn_on
        entity_id: 
          - switch.bokhyllor_arbetsrum
          - switch.dags_fonsterlampa
          - switch.fonsterlampa_foraldrars_sovrum
          - switch.fonsterlampa_rubens_rum
          - switch.golvlampa_tv
          - switch.lampa_gymmet
          - switch.ph_golv_datarum
          - switch.ph_golv_vardagsrum
          - switch.ph_hall
          - switch.tvbank_lampor
      - service: light.turn_on
        entity_id: light.dimbar_brytare_1

@NotoriousBDG @insideout

Actually the code still contains the error I made earlier as someone pointed out…initial state: ‘on’ should be initial_state: ‘on’

The spacing is also important. Each indent should ideally be 2 spaces. This should be put under automation:

But if you could share your config file we could help you better see what’s wrong.

I’ll see if that changes. Another thougt - could it be that the version of HA demands me to do the autmations from the web and that the automation needs an id-number?

I don’t think so if you add the following to the configuration.yaml

automation old: !include automation.yaml
Then you don’t need the id’s but you can’t create automations from the built in editor i think.

It got a little confusing a few versions ago. I keep two separate files so I don’t have the editor messing up my manual automations.

Create 2 files in the same directory as your configuration.yaml, (automations.yaml and automation_old.yaml) and then In your configuration.yaml file type this:

automation old: !include automation_old.yaml

automation: !include automations.yaml

This way you can have both the editor and the manual. For the automations.yaml file, each one will need to start with an ID as you mentioned like this:

- id: ‘unique id here’
  Alias: ‘unique alias name’

Maybe just add one so there’s something already populated in each file. Also, remember to indent 2 spaces at the start of each file.

I am currently using a separate folder with individual (manually created) automation’s and using the
automation: !include_dir_automations
setup.
Can this still be used in a similar way so I can keep that directory of automation’s but then have a file created by the editor?

would I just change things to:

automation_old: !include_dir_automations_old
automation: !include automations.yaml

and rename my existing automations folder to automations_old?

@sparkydave I haven’t tried it, but logically that should work

Use this instead:

automation old: !include_dir automations_old/
automation: !include automations.yaml

It’ll error if you use automation_old: because there’s no such component, and there’s no action include_dir_automations or include_dir_automations_old (see here for what is available).