Can't set an Input Datetime to the value of another in an automation

I’d like to use an automation to set one Input Datetime to the value of another each day. Basically I want to be able to be able to set a bedtime for my kids via the UI, but each day have that reset to a usual bedtime, which I can also change via the UI.

My code is below, which returns the following errors when I try to run the actions

Error while executing automation automation.reset_kids_lights_out_time: Invalid time specified: {’[object Object]’: None} for dictionary value @ data[‘time’]
Reset kids lights out time: Error executing script. Invalid data for call_service at pos 1: Invalid time specified: {’[object Object]’: None} for dictionary value @ data[‘time’]

When I replace {{ states(‘input_datetime.lights_out_for_kids_usual’) }} with a time (e.g. ‘19:30:00’) it works fine, and when I try putting {{ states(‘input_datetime.lights_out_for_kids_usual’) }} into the template tool on Developer Tools it displays a time

I’ve also tried {{ state_attr(‘input_datetime.lights_out_for_kids_usual’,‘timestamp’) }}, which seems to return the same error

Still trying to get the hang of how templates work so am sure I am doing something stupid, any help hugely appreciated

Thanks!

alias: Reset kids lights out time
description: ''
trigger:
  - platform: time
    at: '23:59'
condition: []
action:
  - service: input_datetime.set_datetime
    data_template:
      time: {{ states('input_datetime.lights_out_for_kids_usual') }}
      entity_id: input_datetime.lights_out_for_kids_today
mode: single

Did you have a look at the yaml after saving? I do see this when you make an automation in the UI and it thinks it’s wrong. Here it’s probaby falling over the lack of quotes around the template.

alias: Reset kids lights out time
description: ''
trigger:
  - platform: time
    at: '23:59'
condition: []
action:
  - service: input_datetime.set_datetime
    data_template:
      time: "{{ states('input_datetime.lights_out_for_kids_usual') }}"
      entity_id: input_datetime.lights_out_for_kids_today
mode: single

PS Afraid of 0:00? :smiley:

1 Like

brilliant, thank you! I’d be fiddling with every combination of the template I could think of but didn’t realise I needed to include quotes.

and yes, not sure why I irrationally went for 23:59 :smiley: