Setting the value of an input_datetime from an input_datetime

Hello, I am using the UI to take the action of setting the internet end time “today” from a reference helper, both of which were defined in the UI. Here’s the UI:

and this is the resulting snippet from automations.yaml:

      - service: input_datetime.set_datetime
        data:
          time: '{{ states(''input_datetime.internet_everett_school_day_off_time'')
            }}'
        entity_id: input_datetime.internet_everett_today_off_time

(the UI seems to have changed the quotes from double to single and vice versa - I tried manually editing automations.yaml but either quote setting fails with the same error )

The template string above, when placed in the template editor properly returns the time I’m looking for, but somehow I keep getting the following error:

Choose at step 1: default: Error executing script. Invalid data for call_service at pos 1: must contain at least one of date, time, datetime, timestamp.

Multiple hours on this, had a kind soul on Discord help with the states(input_date…) portion, but stuck again.

TIA!

Are you sure, that input_datetime.internet_everett_school_day_off_time only contains a time, and not a date as well? Otherwise you would have a type mismatch.

Thanks, yes it only contains time. It was created with the UI choosing the time radio button and I have confirmed the “has time true” and “has date false” flags in the config files.

Reply to bump this question. Anyone successfully doing this? Others with the same issue? Thanks!

I can’t duplicate the problem you have encountered.

Using version 2020.12.1, I created two input_datetime entities, both hold time only, then created the following script to assign one entity’s value to the other.

alias: New Script 1
sequence:
  - service: input_datetime.set_datetime
    data:
      time: '{{ states(''input_datetime.start'') }}'
    entity_id: input_datetime.alarm_time
mode: single

It worked. The value of 14:35 contained by input_datetime.start was assigned to input_datetime.alarm_time.

Same here. I just tried this example:

input_datetime:
  test_org:
    has_time: true
  test_copy:
    has_time: true
    
script:
 test_copy_time:
   sequence:
      - service: input_datetime.set_datetime
        data:
          time: "{{ states('input_datetime.test_org') }}"
        entity_id: input_datetime.test_copy

and it worked as expected, copying the time from test_org to test_copy, when I execute the script.

How is your service-call executed? If it is an automation, maybe it isn’t because the trigger isn’t “catching”?

OK, figured this out - my automation actually has multiple choose/option alternatives, and one of the helper fields was defined as a date and not a time. I was thrown off because the error flags “Step 1, position 1” but actually it was the third helper in the list being tested that failed. So, not 0 indexed or 1 indexed (not sure how the errors are counting options). Regardless, once I fixed the third helper to just be time, the whole automation executed and worked as intended. Appreciate the confirmation that the syntax was correct!

seanomat called it first (mismatched input_datetime types). I suggest you mark seanomat’s post with the Solution tag.

1 Like