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
data:
alarm_id: 14
entity_id: media_player.kuche
time: 17:15:00
If I use this, the following erros occurs:
service: sonos.update_alarm
data:
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?
finity
March 24, 2021, 2:03pm
2
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
Same error: Invalid time specified
finity
March 24, 2021, 2:21pm
4
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)?
petro
(Petro)
March 24, 2021, 2:44pm
6
Does the sonos service allow the following? What happens when you use the service caller for this configuration?
service: sonos.update_alarm
data:
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.
petro
(Petro)
March 24, 2021, 3:18pm
8
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.
finity
March 24, 2021, 3:29pm
9
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.
petro
(Petro)
March 24, 2021, 3:42pm
11
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.
petro
(Petro)
March 24, 2021, 3:47pm
13
Templates don’t work in the service caller.
petro
(Petro)
March 24, 2021, 3:48pm
14
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!
finity
March 24, 2021, 11:27pm
16
That would have been useful info from the beginning.
I assumed it was in a script/automation and didn’t work.
petro
(Petro)
March 25, 2021, 8:47am
17
That’s coming in 2021.4, so no more guessing
1 Like