Setting up a button to track brew dates

Hi all,

I am hoping to create a button that sets a datetime helper (input_datetime.date_bottledate) to the date that I pressed a button to track the bottle date. Once this is done I hope to expand it to setting up different trackers of performed tasks.

I have managed to create a “timer” that tracks days since xxx however i am stuck when creating the button to set the date.

Currently I have tried to run a script on button press:

script:

setinput_datetime.date_bottledatetonow:
    alias: "12345"
    sequence:
        service: input_datetime.set_datetime
        target:
            entity_id: input_datetime.date_bottledate
        data:
            date: "{{ now().strftime('%Y-%m-%d') }}"
        mode: single

However this script is coming back with errors:
The script “12345” (script.script) is not active because the configuration has errors.

Error:extra keys not allowed @ data['sequence'][0]['mode']. Got None extra keys not allowed @ data['setinput_datetime.date_bottledatetonow']. Got None.

I am hoping someone can help - I am only new to HA and am trying to get my head around the manual aspect. Thanks in advance!

You need to format your script, so we see the spaces correctly.

Mark your entire script and click </> icon to make it preformatted code.
The icon might be hidden in the hamburger menu on some devices.

My apologies - first time posting. I have fixed it now

Mode: is a key for an automation, not a script.

Hey all, after a bit of playing around I got it to work - below is the working code. Main differences seem to be action (not service).

1_test_set_datetime_now:
  alias: 1 Test set datetime now
  sequence:
  - data:
      date: '{{ now().strftime(''%Y-%m-%d'') }}'
    target:
      entity_id: input_datetime.date_bottledate
    action: input_datetime.set_datetime
  mode: restart
setinput_datetime.date_bottledatetonow:
    alias: "12345"
    sequence:
        service: input_datetime.set_datetime
        target:
            entity_id: input_datetime.date_bottledate
        data:
            date: "{{ now().strftime('%Y-%m-%d') }}"
        mode: single  ## incorrect indentation ##

The error is spitting out the ‘mode’

Your 2nd working yaml the mode is correctly indented.