Automation Templating Syntax

I am struggling with templating in an automation. In the automation, I have 2 triggers, when either of the triggers are invoked I want to then set a Hue “scene” accordingly:

alias: Auto Hue
description: Test Automation of Hue Lights
trigger:
  - platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation }}'
    below: '+6'
  - platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation }}'
    below: '-6'
action:
  - condition: numeric_state
    entity_id: sun.sun
  - service: script.set_front_porch_light
    data:
      huescene: >
        {% if state.attributes.elevation == '+6' %}
            Hue-Front-Porch-Dim-Scene            
        {% else %}
            Hue-Front-Porch-Norm-Scene            
        {% endif %}
mode: single

I am getting a syntax error when attempting to save this: It is looking fore a “before” or “after”.

A push in the right direction, would be very much appreciated. ‘’’

Change all instances of +6 to just 6.

Not sure if this works bc the trigger is “below”. elevation could be 6.5 and jumping to 5.9. This would trigger the automation but would not match the 1st if. Your if in the “set porch light” should be testing if elevation is >0, shouldnt it?

1 Like