Getting sunset (with offset) as a time value

I’m trying to get an automation that for a given sunset time, it tell me what time that will be (so I can give it to node-red).

So the automation I’ve tried is:

alias: update sunset minus one
trigger:
  platform: sun
  event: sunset
  offset: "-00:60:00"
action:
  service: input_datetime.set_value
  data_template:
    entity_id: input_number.sunset_minus_one_hour
    value: "{{ trigger.to_state.state | int }}"

So sunset -60 minus (I hope) and I want the time value in to an input_datetime field.

But I can’t figure out what value: '{{ trigger.to_state.state | int }} should be to post the value from the sun platform to the input_datetime field

Try this:

alias: update sunset minus one
trigger:
  platform: sun
  event: sunset
  offset: "-01:00:00"
action:
  service: input_datetime.set_value
  data_template:
    entity_id: input_number.sunset_minus_one_hour
    value: "{{ now().strftime('%H:%M:00') }}"

ahh because this will trigger at the time of sunset, which is the current time. Ahh right.

So is there a way that I could get what time sunset will be tonight? and trigger it say at 8 in the morning.

Create this sensor:

    nextsunset:
      friendly_name: 'Next Sunset'
      entity_id: sun.sun
      value_template: "{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_local }}"

Or just use the template if you’re not going to use it elsewhere.

Note it will only work up until sunset. At that point it becomes tomorrows sunset.

There’s a custom component here that will keep the value:

Not a problem if you are triggering at 8am though.

Time trigger: Automation Trigger - Home Assistant

No the sensor template gets me a time, thanks for that.

I’ll feed that into node-red for use in a time of day calculation.

Still trying to get my head around HA compared to openhab (doing a very slow migration)

Ok but keep in mind what I said:

Yep thanks. As soon as it updates it’s fed into node red so I can set a state of evening which triggers some lights.

It does have to be bang on, and I’ll remove the date porting and leave just the time.