Invalid time specified in Service

Hello experts,

I try to use a service but I have problems with the time-format:

If I use this, everything works fine:

service: sonos.update_alarm
  alarm_id: 14
  entity_id: media_player.kuche
  time: 17:15:00

If I use this, the following erros occurs:

service: sonos.update_alarm
  alarm_id: 14
  entity_id: media_player.kuche
  time: '{{ states['input_datetime.wecker_individuell'].state }}'

Invalid time specified: {{ states[‘input_datetime.wecker_individuell’].state }} for dictionary value @ data[‘time’]

Can anyone help?

try fixing your quotes.

the outer quotes need to be the opposite type as the inner ones so change them to a double quote.

And you don’t need to reference the entity in that way.

so you can do it like this:

time: "{{ states.input_datetime.wecker_individuell.state }}"

or like this (recommended):

time: "{{ states('input_datetime.wecker_individuell') }}"

If neither of those work then I would assume that means that the time can’t be templated.

Unfortunately it doesnt work :slightly_frowning_face:

Same error: Invalid time specified

Then it is probably the case that the time isn’t able to be templated.

ok, but how can I use the time from input_datetime (or any other input-objetc) in a service?
Or is it just a problem in this service (sonos.update_alarm)?

Does the sonos service allow the following? What happens when you use the service caller for this configuration?

service: sonos.update_alarm
  alarm_id: 14
  entity_id: media_player.kuche
  time: '00:10:00'

Yes, this works when I call the service. But I need to insert the time from the input_datetime.

Then what @finity wrote should work. I verified that the template returns a string, are you sure you tried his template and received the same error?

time: "{{ states('input_datetime.wecker_individuell') }}"

Also what version of HA are you running?

Lastly, please reply to me properly, use the reply button on my post, not the blue reply button.

If the templates I (and others) said should work but they don’t then it is likely that this service doesn’t accept a template for the time.

There are other services that accept templates for the time so it isn’t just all services in general.

That´s why I´m really confused. It seems to be pretty easy, but it doesnt work.
I tried again and copied the code. But the service only works when I insert the time directly.
If I use your code e.g. in custom-buttom card, it works. But not in this service.

How are you calling this service when testing the template?

Im using the service UI in the development tools

And I´m using the latest version of HA.

Templates don’t work in the service caller.

Make a script and put the script into your custom button card. It’ll work.

Really? I did not know that. I will try it. Many Thanks!

That would have been useful info from the beginning.

I assumed it was in a script/automation and didn’t work. :roll_eyes:

That’s coming in 2021.4, so no more guessing

1 Like