Invalid Time for datetime

Hello, I’m getting an error when running one of my automations that I’m not sure how to fix. I’m trying to set an input_datetime based on a few different sensors.

Here’s the automation:

- alias: Kids Light ready to go for tomorrow
  trigger:
    - platform: time
      at: '11:30:00'
  condition:
    - condition: state
      entity_id: input_boolean.vacation_mode
      state: 'off'
  action:
    - service: input_datetime.set_datetime
      entity_id: input_datetime.kids_light
      data_template:
        time: >-
          {% if is_state('sensor.school_day_tomorrow', 'true') %}
            "06:30:00"
          {% elif is_state('sensor.distance_learning_tomorrow', 'true') %}
            "07:00:00"
          {% else %}
            "07:30:00"
          {% endif %}

And here’s the error:

Invalid time specified: "07:30:00" for dictionary value @ data['time']

Does anyone know what I’m doing wrong? Thanks!

It looks fine to me.

You could try to change “data_template” to just “data” since it’s longer required. But I doubt that’s the issue.

Or you could try a different style of quotes (single vs double) but that shouldn’t be a problem either.

does your input_datetime entity contain the date too by some chance?

No I have has_date set to false

  kids_light:
    name: Turn Kids Light on at
    has_date: false
    has_time: true

I’ll play around with the code, maybe write it a different way.

For some reason this worked instead:

- alias: Kids Light ready to go for tomorrow
  trigger:
    - platform: time
      at: '11:30:00'
  condition:
    - condition: state
      entity_id: input_boolean.vacation_mode
      state: 'off'
  action:
    - service: input_datetime.set_datetime
      data_template:
        entity_id: input_datetime.kids_light
        time: '{% if is_state("sensor.school_day_tomorrow", "true") %}06:30:00{% elif is_state("sensor.distance_learning_tomorrow", "true") %}07:00:00{% else %}07:30:00{% endif %}'

The reason is because your original example specified the time values with unnecessary double-quotes. Remove them and the error message will be eliminated.

Your second example works not because the template is all on one line but because the time values are no longer wrapped in double-quotes.

Just for future reference, should they have no quotes at all? I originally had single quotes but that gave me the same error.

Correct. Precisely what I had suggested (remove them).

To be fair, the docs show all the example as having quotes. Tho there was no example specific to this it seems that it should work to use quotes here too.