Save next_dusk & next_dawn in Helper with automation

I have to save the next_dusk and next_dawn datetime values from the sun integration in two helpers with an automation running every day at 03:00.

I create two input_datetime helpers:

input_datetime.sun_today_dawn
input_datetime.sun_today_dusk

alias: Sun Heutige Werte festhalten
description: ""
trigger:
  - platform: time
    at: "03:00:00"
condition: []
action:
  - service: input_datetime.set_datetime
    data_template:
      date: "{{ states('sensor.sun_next_dusk') }}"
    target:
      entity_id: input_datetime.sun_today_dusk
mode: single

When I test the action I got: ā€œCould not parse date for dictionary value @ data[ā€˜dateā€™]. Got Noneā€.

What am I doing wrong?

It should be data: not data_template: on the line after input_datetime.set_datetime

When using input_datetime.set_datetime you need to match the data types you are usingā€¦
if sun_today_dusk is configured to hold both date and time you can use the datetime key under `data:

action:
  - service: input_datetime.set_datetime
    data:
      datetime: "{{ states('sensor.sun_next_dusk') }}"
    target:
      entity_id: input_datetime.sun_today_dusk

Just FYI you may want to take a look at the Sun2 custom integration.

1 Like

Thanks to both of you