Value cannot be processed error when automating using the numeric state of the sun

I’m trying to turn a light on when the state of the sun is below a certain elevation but it doesn’t seem to like it, here is my automation -

- id: '1546903627380'
  alias: Turn on porch light at sunset
  trigger:
  - below: '5'
    entity_id: sun.sun
    platform: numeric_state
    value_template: "{{ state.attributes.elevation }}"
  condition: []
  action:
  - data:
      entity_id: switch.porch_side_light
    service: switch.turn_on

I have no idea what I am doing wrong! Any help is much appreciated!

try …

- id: '1546903627380'
  alias: Turn on porch light at sunset
  trigger:
    platform: template
    value_template: "{{ states.sun.sun.attributes.elevation  | int < 5 }}"
  action:
    service: switch.turn_on
    entity_id: switch.porch_side_light

Getting no errors now, although it still isn’t triggering the light

Did you replace all of the automation or just the value template? your original automation had a number of errors that were corrected in my example.

If you replaced the entire thing, what does "{{ states.sun.sun.attributes.elevation | int < 5 }}" render in the templates developer tool? It should render true or else the trigger will not fire.

Also, I should have asked this at first but you do have the sun component loaded, correct?

I had replaced everything in the trigger section, just replaced it all now though, checked the template editor and it does return true, I believe I have the sun component loaded, it shows in the overview at the top.

I think it may have triggered at one point as the light did go on. Will it keep on triggering until the template is no longer true? If so how often?

Thanks for the help by the way!

It will trigger each time that attribute is updated. I am not sure how often the sun component updates but I believe its rather frequent.

Here is the automation I use for a similar task.

https://github.com/SilvrrGIT/HomeAssistant/blob/master/automation/outside_Lights.yaml#L27

Well thanks for the help man!

It is triggering, haven’t got it to trigger again once I turn it off, may it just takes a little while to activate again, but shouldn’t really matter as should only really be triggered on once a day!