Rest command in script gives error "Message malformed: template value should be a string for dictionary value @ data['sequence'][0]['data']"

Hi out there.
in my configuration yaml i have a rest command:

  shelly_set_on_with_time:
    url: 'http://{{ ip }}/relay/0?turn=on&timer={{ settime }}'

in a script i want to call now the rest url:

service: rest_command.shelly_set_on_with_time
data:
  ip: xxxxx
  settime: >
    {% (float(states("input_number.irrigation_bewaesserungszeit_ventil_1"))) %}

And here i get the following error:
Message malformed: template value should be a string for dictionary value @ data[‘sequence’][0][‘data’]

But if im am putting the template directly in the configuration yaml it works:

 shelly_set_on_with_time:
    url: 'http://{{ ip }}/relay/0?turn=on&timer={{ (float(states("input_number.irrigation_bewaesserungszeit_ventil_1"))) }}'

So does someone know why this template is not working in a script?

Many Thanks for help

You used the correct print output brackets {{ }} in your direct test but in your automation you used the statement brackets {% %}. Should be:

  settime: >
    {{ states("input_number.irrigation_bewaesserungszeit_ventil_1")|float(0) }}

You also had an over abundance of parentheses and no default for your float filter. They didn’t cause the issue but you should correct them as above.

1 Like

Again what leaned. Thanks a lot for your fast reply. :heartpulse: That works

1 Like