Automations seem to not work when conditions are set. Thoughts?

Hi everyone, I’ve been trying to work out some of my automations don’t trigger. I’m not sure whether it’s to do with the types of condition. Hopefully you can help me find out.

For starters, I re-did all my automations using the Automation Editor. Triggering the automations manually works like a charm. But it’s just the automatic triggering that seems to be the problem.

An example of an automation that won’t trigger is this:

- action:
  - data:
      entity_id: group.all_lights
    service: light.turn_off
  - data:
      entity_id: scene.gone_out_nighttime
    service: scene.turn_on
  alias: "Departure \u2014 after dark"
  condition:
  - after: sunset
    before: sunrise
    condition: sun
  id: '1506415798774'
  trigger:
  - entity_id: group.all_devices
    from: home
    platform: state
    to: not_home

But if I change the trigger to a time, it seems to work! Thoughts?

Your condition is wrong. Try this;

  condition:
    condition: state
    entity_id: sun.sun
    state: 'below_horizon'

Thanks very much! That seems to have been the problem.

Also, if I have an offset time with the sunset as trigger:

  trigger:
  - event: sunset
    offset: -00:10:00
    platform: sun

There are no quotes around the offset. Are the quotes still necessary for the trigger to work?

Yes.

trigger:
  platform: sun
  event: sunrise
  offset: "-00:15:00"

You could also try and use the sun elevation instead of the sunset/sunrise with offset. I used to do it that way myself, but found it more reliable to use the sun elevation.

trigger:
  platform: numeric_state
  entity_id: sun.sun
  value_template: "{{ state.attributes.elevation }}"
  below: 8.0