Template in

Hello, is it possible to pass somehow mathematical equation in offset parameter in automation based on sun platform? I’ve got such code:


- id: '1605022981055'
  alias: Lid - Close at the evening
  description: ''
  trigger:
  - platform: sun
    event: sunset
    offset: +00:30:00
  condition: []
  action:
  - service: script.lid_close
  mode: single

I’d like to update offset to something like this:

offset: "+00:{{ now().month | string }}:00"

It’s my understanding that you cannot do that because the offset option does not support the use of a template.

Why do you want to offset the time by minutes equal to the month’s ordinal value (Jan=1, Feb=2, etc)?

If that’s meant to adapt to seasonal differences in twilight time, I suggest you consider using a Sun Elevation Trigger.

For example, close the lid when the sun’s elevation decreases below 1.1 degrees above the horizon.


- id: 'close_lid_just_before_sunset'
  alias: Lid - Close just before sunset
  description: ''
  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 1.1
  condition: []
  action:
    - service: script.lid_close
  mode: single