New to this - can someone confirm if this will fire correctly 10 minutes before Sunset on 4th of July (yearly)?

Title says it all - this is my first time using templates, have I done this correctly? Kinda hard to test it other than waiting and finding out the hard way.

alias: 'Nighttime Lighting: Fourth of July'
description: ''
trigger:
  - platform: sun
    event: sunset
    offset: '-10'
condition:
  - condition: template
    value_template: |-
      {% if now().month == 7 and now().day == 4 %}
      true
      {% else %} 
      false
      {% endif %}
action:
  - service: scene.turn_on
    target:
      entity_id: scene.outside_front_america
    metadata: {}
mode: single

You can simplify the template. This will return true or false, there’s no need for an if/else:

condition:
  - condition: template
    value_template: "{{ now().month == 7 and now().day == 4 }}"

Or it you want to be really brief you can use the template condition shorthand notation:

condition:
  - "{{ now().month == 7 and now().day == 4 }}"

And your trigger offset needs to be defined like this (hh:mm:ss):

trigger:
  - platform: sun
    event: sunset
    offset: '-00:10:00'
4 Likes