Trying to give one input_datetime the value of another input_datetime

I’m having some trouble creating an automation. I’m trying to set a bedtime input_datetime that I will use to trigger other automations. The value should be different on a school night or a weekend. This is what I have:

service: input_datetime.set_datetime
target:
  entity_id: input_datetime.bedtime_today
data: |-
  {% if is_state('binary_sensor.workdaytomorrow', 'on') %}
    time: '{{ states("input_datetime.bedtime_weekday") }}'
  {% else %}
    time: '{{ states("input_datetime.bedtime_weekends") }}'
  {% endif %}

This code works in the developer tools template and gives the expected values. But in an automation it gives an “Error: Error rendering data template: Result is not a Dictionary”. I’m fairly new to HA and any help would be appreciated.

You cannot use a Jinja2 template to generate YAML options and values. You use it to generate values that are assigned to a YAML option.

service: input_datetime.set_datetime
target:
  entity_id: input_datetime.bedtime_today
data:
  time: >
    {% if is_state('binary_sensor.workdaytomorrow', 'on') %}
      {{ states("input_datetime.bedtime_weekday") }}
    {% else %}
      {{ states("input_datetime.bedtime_weekends") }}
    {% endif %}
1 Like

Thank you!

1 Like