Assigning a value to a Helper

I have a simple Automation that switches on lights on at the current value of Sunset (Platform: Sun) and switches them off dependent on the value of a Helper (Datetime). Associated with this is a Lovelace Dashboard Card that displays the current value of that Helper (Datetime) allowing me to edit the time and obviously retain the most recent input value from one day to the next.

I have now created a second Helper (Datetime) with which I’d like to assign the current value of Sunset (updated for each day) and again create another Lovelace Dashboard Card initially displaying the current value of Sunset for the current day but allowing me the option to edit that value on the Card, before the lights are automatically switched on. Any edit of Sunset would only be by an hour or so and only apply for the current day. After midnight any previously edited time need to be overridden by the new value for Sunset.

This would be a 5min task to accomplish in most programming languages but being new to HA I have no idea about the best way to achieve it. Writing a script would be the obvious way but how to go about this? And is it the best way? Any advice or schema of a suggested approach (particularly re assigning values to variables in Automations) would be most appreciated.

Thanks.

I just wrote some time based scripts that reset a datetime value, this one sets the value to the current time plus an offset in seconds, which can be positive or negative:

alias: Set Timedate
sequence:
  - service: input_datetime.set_datetime
    data:
      timestamp: '{{ now().timestamp() + timedate }}'
      entity_id: '{{ entity }}'
mode: single

Which can then be called from the UI or an automation like so:

      cards:
        - type: entities
          entities:
            - entity: '[[entity]]'
              hold_action:
                action: call-service
                service: script.script_set_timedate
                service_data:
                  entity: '[[entity]]'
                  timedate: '[[interval]]'
                confirmation:
                  text: Reset Timestamp?

where [[entity]] is the thing you want to change, and interval is the offset. In your case you would not want to use now in the script, but just the timestamp value

You can easily transfer of the old sunset value and set the new one using an automation that occurs at sunrise for that day.

For what purpose are you using a helper for lights-off (curious)

Thanks for this. Very helpful. Haven’t had a chance to apply your code yet using Sunset. Will do this evening.

I’m sure that there are neater and more efficient ways than using a helper. It’s simply that I’ve only just started using HA, converting from a large Vera system, read somewhere what a help could do re input and decided to try it out. I’m still feeling my way around the code. Typically I learn a new language by using GUI assistants (where they exist) to achieve an end objective, then study the underlying code that’s been built. And adapt that code for other similar things. Of course, I end up going back over everything built with a GUI looking to improve it by direct coding!