Automations having issue with 'sun' dependency

Hi all,

Getting an invalid configuration notice when I added a new automation. Not entirely sure what’s going on here so any assistance would be great. It seems to have caused one of my automations to not trigger (“Evening”). The new automation I’ve tried adding to my existing lighting.yaml config:

- alias: "Berto Leaving"
  trigger:
    - platform: sun
      event: sunrise
      offset: '+00:10:00'
    - platform: zone
      entity_id: device_tracker.berto_iphone
      zone: zone.home
      event: leave
  action:
    service: homeassistant.turn_off
    entity_id: switch.living_room_lamp

The existing config which was working fine before adding this new entry was:

- alias: "Berto Wakeup"
  trigger:
    platform: time
    after: '05:45:00'
  action:
    service: homeassistant.turn_on
    entity_id: switch.living_room_lamp

- alias: "Berto Leaving"
  trigger:
    - platform: sun
      event: sunrise
      offset: '+00:10:00'
    - platform: zone
      entity_id: device_tracker.berto_iphone
      zone: zone.home
      event: leave
  action:
    service: homeassistant.turn_off
    entity_id: switch.living_room_lamp

- alias: "Evening"
  trigger:
    platform: sun
    event: sunset
    offset: '-00:15:00'
  action:
    service: homeassistant.turn_on
    entity_id: switch.living_room_lamp

- alias: "Sleeping"
  trigger:
    platform: time
    after: '01:30:00'
  action:
    service: homeassistant.turn_off
    entity_id: group.all_switches

And the error I’m seeing is:

Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.loader] Loaded automation.time from homeassistant.components.automation.time
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.loader] Loaded automation.sun from homeassistant.components.automation.sun
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.loader] Loaded automation.zone from homeassistant.components.automation.zone
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.bootstrap] Setting up automation
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.loader] Loaded sun from homeassistant.components.sun
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 ERROR (MainThread) [homeassistant.bootstrap] Attempt made to setup sun during setup of sun
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 ERROR (MainThread) [homeassistant.bootstrap] Component sun failed to setup
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 ERROR (MainThread) [homeassistant.bootstrap] Unable to prepare setup for platform automation.sun because dependency sun could not be initialized
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=persistent_notification, service_data=notification_id=invalid_config, title=Invalid config, message=The following components and platforms could not be set up:
Jan 04 22:09:18 ha-ubuntu hass[7408]: * [sun](https://home-assistant.io/components/sun/)
Jan 04 22:09:18 ha-ubuntu hass[7408]: Please check your config, service=create, service_call_id=139838079863384-1>
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=persistent_notification, service_data=notification_id=invalid_config, title=Invalid config, message=The following components and platforms could not be set up:
Jan 04 22:09:18 ha-ubuntu hass[7408]: * [sun](https://home-assistant.io/components/sun/)
Jan 04 22:09:18 ha-ubuntu hass[7408]: Please check your config, service=create, service_call_id=139838079863384-2>
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=persistent_notification, service_data=notification_id=invalid_config, title=Invalid config, message=The following components and platforms could not be set up:
Jan 04 22:09:18 ha-ubuntu hass[7408]: * [sun](https://home-assistant.io/components/sun/)
Jan 04 22:09:18 ha-ubuntu hass[7408]: * [automation.sun](https://home-assistant.io/components/automation.sun/)
Jan 04 22:09:18 ha-ubuntu hass[7408]: Please check your config, service=create, service_call_id=139838079863384-3>
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.components.automation] Initialized trigger Berto Left Work
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.components.automation] Initialized trigger Sleeping
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.components.automation] Initialized trigger Berto Wakeup

...

Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=139838079863384-3>
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.bootstrap] Setting up sun
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sun.sun=below_horizon; friendly_name=Sun, next_setting=2017-01-05T23:09:10+00:00, elevation=0, azimuth=0, next_rising=2017-01-05T13:36:25+00:00 @ 2017-01-04T22:09:18.568775-06:00>, old_state=None, entity_id=sun.sun>
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=sun>
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.components.automation] Initialized trigger Berto Leaving
Jan 04 22:09:18 ha-ubuntu hass[7408]: 17-01-04 22:09:18 INFO (MainThread) [homeassistant.components.automation] Initialized trigger Berto Leaving

Any ideas here?

Hi mstberto,

did you find a solution to this issue?
I’m running into the same dependency problem after adding a second (more or less a cloned section) automation rule to a working one.

Even check config via

hass --script check_config

doesn’t show an error.

Very annoying. I only can overcome this by not using the sun trigger, but a time trigger.

Regards,
Bastian

Try this:

trigger:
  platform: sun
  after: sunset
  after_offset: "00:10:00"

Have not tried this myself but I use this in an automation which works well:

- alias: 'Lights on when home after sunset'
  trigger:
    - platform: state
      entity_id: group.all_devices
      state: 'home'
    - platform: sun
      event: sunset
      offset: "-0:20:00"
  condition:  
    condition: and
    conditions:
      - condition: sun
        after: sunset
        after_offset: "-0:20:00"
      - condition: state
        entity_id: group.all_devices
        state: 'home'
  action:
    - service: scene.turn_on
      entity_id: scene.evening
    - service: switch.turn_on
      entity_id: switch.wake_on_lan    
    - service: tts.google_say
      data_template:
        entity_id: media_player.home_group
        message: 'Evening lights turned on'
        cache: false

Edit: I see I use the same trigger :blush:
Try ditching the “+”