RESTful service with variable

Hi all,
I am new to the community and hope to get some help. I am quiet new to homeassistant but have got many things to work already and I am really pleased with the product.
My problem is using the RESTful command with a variable. What I want to achieve is to change the program on my Sony Bravia TV. So I have a working piece of code in the configuration.yaml:

rest_command:
  tv_playcontent:
    url: http://192.168.132.156/sony/avContent
    method: POST
    headers:
      X-Auth-PSK: 'myKeyHere'
      content_type:  'application/json'
    payload: '{"method": "setPlayContent","id": 101,"params": [{"uri": "tv:dvbs?trip=1.1019.10302&srvName=arte HD"}],"version": "1.0"}'
    verify_ssl: false

When I run the service from the frontend without any parameters it is working well and it changes the program on Bravia TV to Arte. But I would like to amend the code that I only pass the program name to the service I am calling. So I changed the payload parameter to:

payload: '{"method": "setPlayContent","id": 101,"params": [{"uri": {{ uri }}}],"version": "1.0"}'
and when I call the service I enter the service data tp pass with service:

{"uri": "tv:dvbs?trip=1.1019.10302&srvName=arte HD"}

But nothing happens and I donĀ“t even get logs in HA or in the console.

Can someone point me into the right direction please?
Thanks and regards
Alexander

Is it possible that the template simply needs to wrap {{ uri }} in double-quotes?

payload: '{"method": "setPlayContent","id": 101,"params": [{"uri": "{{ uri }}"}],"version": "1.0"}'

Thanks, that indeed resolved the issue.

Glad to hear it works now. Please mark my post with ā€˜Solutionā€™ to make it easier for others to see that this issue has been solved and also to make it easier to find the solution (in case they are experiencing the same problem). Only you, the author of this topic, can mark a post as the ā€˜Solutionā€™. After marking it, it will automatically appear as a link under the first post.

Hope that I marked it correctly.
Thanks again for looking into my issue and fixing it.
BR Alexander

1 Like