Sun events as a condition

Hello good fellow hass users.

I have this issue with sun events, that used to work.

first of all…
im using Hass.io.
doing the automation In the internal Hass io automation editor.

  condition:
  - after: sunset
    condition: sun
  id: '1520308983714'
  trigger:
  - entity_id: switch.plug_158d000171a301
    from: 'on'
    platform: state
    to: 'off' 

If i set this condition “sun” the lights wont even go on… ( when the sun is below the horizon )
When i remove the condition, it does work.
So i am doing something wrong with this condition. and im asking for a nudge in the right direction.

regards

try:

trigger:
   platform: state
   entity_id: switch.plug_158d000171a301
   from: 'on'
   to: 'off'
condition:
    condition: sun
    before: sunset
    before_offset: "00:00:00"

thank you @Sander2506,
i will try that a.s.a.p.

it works

you have to fill in the offset. you cant leave it empty.
thank you for bringing that to my attention.

Not sure I’m reading this correctly, but the trigger is what kicks off the automation.

Trigger > validate Condition > perform Action

Sounds like you got it working. Just for sharing here’s a similar one I use based on the elevation of the sun and using a template formula (I also make sure the other lights haven’t already been turned on, and that it is after 3:30 pm. I should probably make a group out of my target lights):

  trigger:
    platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation }}'
    below: 6.5
  condition:
  - condition: state
    entity_id: light.general_lights
    state: 'off'
  - condition: time
    after: '15:30:00'
  action:
  - service: light.turn_on
    entity_id: light.couch_table_lamp
  - service: light.turn_on
    entity_id: light.chair_table_lamp
  - service: light.turn_on
    entity_id: group.living_room_floor_lamp
  - service: light.turn_on
    entity_id: light.aurora