Using templates in YAML

Hi!

Why does this work?

action: kia_uvo.schedule_charging_and_climate
data:
  device_id: ...
  charging_enabled: true
  first_departure_enabled: true
  first_departure_days:
    - "1"
    - "2"
    - "3"
    - "4"
    - "5"
  first_departure_time: "07:10:00"
  off_peak_charge_only_enabled: true
  climate_enabled: true
  temperature: 18
  temperature_unit: "0"
  defrost: true
  off_peak_start_time: "01:00:00"
  off_peak_end_time: "06:00:00"

But this does not:

action: kia_uvo.schedule_charging_and_climate
data:
  device_id: ...
  charging_enabled: true
  first_departure_enabled: true
  first_departure_days:
    - "1"
    - "2"
    - "3"
    - "4"
    - "5"
  first_departure_time: "07:10:00"
  off_peak_start_time: >-
    {{ states('input_datetime.auto_laadimise_algusaeg') }}
  off_peak_end_time: >-
    {{ states('input_datetime.auto_laadimise_lopp_80') }}
  off_peak_charge_only_enabled: true
  climate_enabled: true
  temperature: 18
  temperature_unit: "0"
  defrost: true

First version of the code sets the charging start and end times, but second version with input_datetime helpers does not.
There is no error, but charging schedule is disabled in Hyundai app.

Thank you!

I believe you are missing the " around your {{ }} statements:

off_peak_start_time: >-
   "{{ states('input_datetime.auto_laadimise_algusaeg') }}" 
off_peak_end_time: >-
    "{{ states('input_datetime.auto_laadimise_lopp_80') }}" 

Wrapping in quotes only applies to templates on a single line with the key. The multiline indicator > should remove the need for them.

To OP: can you provide a bit of context? Is this action part of a script? Or are you running it from the frontend?

And are these datetime helpers time only? What does

{{ states('input_datetime.auto_laadimise_lopp_80') }}

show in Developer Tools > Template?

Possibly because those two options don’t support the use of templates. Not all options support templates.

Contact the integration’s maintainer.

this is the trace of this action in a script.
It appears to send correctly formatted time values.

If the option supports a template and the template produces a valid value yet the action fails to produce the desired result, report the anomaly to the integration’s maintainer.