Help with sunset automation

The following automation runs when I disable the alarm system and every action occurs except the section after the sunset condtion. Any idea why?

- id: alarm_disarmed
  alias: '[Alarm] Disarmed'
  trigger:
    platform: state
    entity_id: alarm_control_panel.house
    to: disarmed
  action:
  - service: switch.turn_off
    entity_id: group.alarm_outputs
  - service: switch.turn_off
    entity_id: switch.led_red
  - service: switch.turn_on
    entity_id: switch.led_green
  - service: notify.all_ios_devices
    data:
      message: The house alarm has been DISARMED
      data:
        push:
          sound: "Disarmed.wav"
  - service: script.turn_on
    entity_id: script.internal_siren_2bip
# lights on if after sunset
  - condition: template
    value_template: '{{ states.sun.attributes.elevation < 0 }}'
  - service: input_number.set_value
    data_template:
      entity_id: input_number.lounge_rd_lights
      value: 50

I get the following error:

Error during template condition: UndefinedError: ‘None’ has no attribute ‘elevation’

Simple typo, the states object is sun.sun, not just sun

  - condition: template
    value_template: '{{ states.sun.sun.attributes.elevation < 0 }}'

Thank you (again) petro.

1 Like