Rogue switch always turns at startup

I have one automation that seems to trigger and meet its conditions EVERY time I restart HA. But I have an almost identical one that doesn’t. Can anyone offer a suggestion as to why this might be? Interestingly it does not happen when I reload, Groups or Automations.

This one always triggers and always meets the conditions

- alias: Hall light on at dusk
  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.elevation }}'
      below: 5.0
  condition :
    - condition: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.elevation }}'
      below: 5.0
    - condition: time
      before: "23:00:00"
  action:
    # delay a random amount of time between 1 and 2 minutes 
    - delay: '00:01:{{ (range(0, 59)|random|int) }}'
    - service: homeassistant.turn_on
      entity_id: switch.hall_light

This one doesn’t:

- alias: Dining room light on at dusk if someone is home
  trigger:
    - platform: template
      value_template: '{{states.group.family_presence.state == "home"}}'
    - platform: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.elevation }}'
      below: 5.0
  condition: 
    condition: and
    conditions:
    - condition: state
      entity_id: group.family_presence
      state: "home"
    - condition: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.elevation }}'
      below: 5.0
    - condition: time
      before: "23:00:00"
    - condition: time
      after: "12:00:00"
  action:
    service: homeassistant.turn_on
    entity_id: switch.dining_room_light

I also have this:

- alias: check lights at startup
  trigger:
    platform: homeassistant
    event: start
  action:
      entity_id: automation.hall_light_on_at_dusk
    - service: automation.trigger
      entity_id: automation.dining_room_light_on_at_dusk
    - service: automation.trigger

I had the same problem with an automation that opened my garage door triggering on restart.

While not solving the problem, I’ve overcome it by disabling the problem autos for 10 mins after startup.

I set initial_state: false on the offending auto, then another auto that ( intentionally ) triggers on restart turn the auto back on after 10 mins.

Ha! That must have been a lot more annoying than my light turning on!!
Thanks for the idea to get around it. It won’t do my OCD any good though!! :slight_smile: