Help with sun offset template

Hi team HASS.

going batty here trying to debug what should be a simple automation improvement.

Basically, as summer moves to winter, I need to tweak my sunset offsets. I.e. in winter I switch on lighting 60 mins prior to sunset. In summer that offset is different.

I want to be able to control these via sliders (input_number) in the GUI. The input_numbers are working, just fine for instance, my input_number looks like this:

input_number:
  sunset_pre_event:
    name: Pre-Sunset Trigger
    icon: mdi:weather-sunset-down
    mode: slider
    # unit_of_measurement: min
    min: 1
    max: 90
    step: 1

which in the GUI looks like this:
20210627_18-57-12_Overview - Home Assistant

which in the templates editor I can confirm is coming up ok:

but when I try to use this in an offset sun automation as the minute value:

#~~~~~~~~~~~~~~~~~~~~~~~SUNSET EVENT
- alias: 'LIGHTING: Sunset Lamps'
  trigger:
    platform: sun
    event: sunset
    # offset: -00:15:00
    offset: '-00:{{states("input_number.sunset_pre_event")|int}}:00'
  action:

I get this error:

2021-06-27 18:52:43 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: offset 00:{{states("input_number.sunset_pre_event")|int|string}}:00 should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['offset']. Got None. (See ?, line ?).

what’s doing my head in is I have a NEAR IDENTICAL setup to tune my irrigation and that is working just fine (note the <<<<<<<<<< template part). Is ‘offset’ more fussy than ‘delay’ ??

#~~~~~~~~~~~~~~~~~~~~~~~WATER GARDEN
- alias: 'IRRIGATION: Water Garden'
  trigger:
    platform: time
    at: "07:30:00"
  condition:
    # If today's forecast shows no rain.... 
    - condition: numeric_state
      entity_id: sensor.bexley_rain_amount_min_0
      below: 0.5
  action:
    - service: notify.k_telegram_bex36debug_push
      data:
        message: '*IRRIGATION:* @tonyTap ->Opening (as no rain forecasted today)'
    ###########TAP OPEN
    - service: switch.turn_on
      data:
        entity_id: switch.aeon_labs_zw132_dual_nano_switch_switch
    ###########SLEEP... 
    - delay: '00:{{ states("input_number.water_tony_before_off") | int }}:00'   #<<<<<<<<<<
    ###########NOTIFY
    - service: notify.k_telegram_bex36debug_push

offset does not accept templates.

However, you probably do not it need at all for your case. See the note regarding “sun elevation trigger” at
Automation Trigger - Home Assistant (home-assistant.io)

1 Like

Omg amazing. I was pulling my hair out. I was pondering flipping to that elevation method in debugging, but not as an end-state (was thinking it’s intuitive to slide the GUI in minutes, not degrees elevation). Might have to rethink that as a fallback

As an aside: is the a way i can find out what parts of an automation do / dont accept templates?

It’s an excellent question.

I don’t know myself, and that becomes very confusing for a lot of people, including me.
I hope that issue will be addressed by HA at some point, or by allowing templates everywhere, or making it clearer in the doc.

1 Like

One fairly reliable way is:

  • If the documentation doesn’t explicitly mention, or provide an example of, the option supporting a template then it doesn’t.

For example, the documentation for the Sunrise/Sunset Trigger doesn’t mention that offset can accept a template and its example doesn’t include a template.

Compare that to the documentation for the State Trigger which explicitly indicates the for option accepts a template.