Problem adding a simple automation rule

I am stepping from Domoticz to Home Assistent, but am facing an annoying problem, probably due to my lack of HA knowledge.
I have a RFXtrx connected to my raspberry, and have setup light switches.

I edited the automations.yaml file to switch on the light 45 minutes prior to sunset. Looks very easy, but I am having difficulties.

Automations.yaml:

  • id: ‘1551452493721’
    alias: Licht Woonkamer VOOR AAN 45 min voor zonsondergang
    trigger:
    • event: sunset
      offset: -00:45:00
      platform: sun
      condition: []
      action:
      entity_id: switch.licht_woonkamer_voor
      service: switch.turn_on

First off all: the ‘id’ was inserted when I tried to modify this automation using the frontend. The online docs do not mention this…at least I havent found it.

When I use the frontend the action field keeps having a red rectangle. Seems something is wrong, but I dont know what. Rectangle doesnt disappear. When I open a automation, the action field is always empty, while the automations file has data…

Hope you can help me, or point me to where the solution is hidden :wink:

Your indenting makes it impossible to tell but indenting for your action looks off. It should be same indenting as your trigger. (Same for the condition)

Indenting with YAML is very important.

The frontend editor adds the ID. It won’t ‘see’ an automation without an ID.

The forum misformatted my yaml code. Let me try it again:
Edit: Strangly the preview looks OK, but when posted is is malformatted

- id: '1551452493721'
  alias: Licht Woonkamer VOOR AAN 45 min voor zonsondergang
  trigger:
  - event: sunset
    offset: -00:45:00
    platform: sun
  condition: []
  action:
    entity_id: switch.licht_woonkamer_voor 
    service: switch.turn_on

Try putting the offset in quotes.

Thanks for your quick replies

If I add the quotes and use the frondend to check if all OK, I see no action:

HA-Automation

So it seems to me that there’s something wrong

  action:
  - service: switch.turn_on
    data:
      entity_id: switch.sonoff12914

One of mine…

I have put in your sample, and the output from the frondend looks promissing :slight_smile:

Thanks in advance !